src/Pure/Admin/build_jcef.scala
changeset 73476 6b480efe1bc3
child 73566 4e6b31ed7197
equal deleted inserted replaced
73475:4840ce456b4f 73476:6b480efe1bc3
       
     1 /*  Title:      Pure/Admin/build_jcef.scala
       
     2     Author:     Makarius
       
     3 
       
     4 Build Isabelle component for Java Chromium Embedded Framework (JCEF).
       
     5 See also:
       
     6 
       
     7   - https://github.com/jcefbuild/jcefbuild
       
     8   - https://github.com/chromiumembedded/java-cef
       
     9 */
       
    10 
       
    11 package isabelle
       
    12 
       
    13 
       
    14 object Build_JCEF
       
    15 {
       
    16   /* platform information */
       
    17 
       
    18   sealed case class JCEF_Platform(platform_name: String, archive: String)
       
    19   {
       
    20     def archive_path: Path = Path.explode(archive)
       
    21     def dir(component_dir: Path): Path = component_dir + Path.basic(platform_name)
       
    22   }
       
    23 
       
    24   val platforms: List[JCEF_Platform] =
       
    25     List(
       
    26       JCEF_Platform("x86_64-linux", "linux64.zip"),
       
    27       JCEF_Platform("x86_64-windows", "win64.zip"),
       
    28       JCEF_Platform("x86_64-darwin", "macosx64.zip"))
       
    29 
       
    30 
       
    31   /* build JCEF */
       
    32 
       
    33   val default_url = "https://github.com/jcefbuild/jcefbuild/releases/download"
       
    34   val default_version = "v1.0.10-83.4.0+gfd6631b+chromium-83.0.4103.106"
       
    35 
       
    36   def build_jcef(
       
    37     base_url: String = default_url,
       
    38     version: String = default_version,
       
    39     target_dir: Path = Path.current,
       
    40     progress: Progress = new Progress): Unit =
       
    41   {
       
    42     /* component name */
       
    43 
       
    44     val Version = """^([^+]+).*$""".r
       
    45     val component =
       
    46       version match {
       
    47         case Version(name) => "jcef-" + name
       
    48         case _ => error("Bad component version " + quote(version))
       
    49       }
       
    50     val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component))
       
    51     progress.echo("Component " + component_dir)
       
    52 
       
    53 
       
    54     /* download and assemble platforms */
       
    55 
       
    56     for (platform <- platforms) {
       
    57       Isabelle_System.with_tmp_file("archive", ext = "zip")(archive_file =>
       
    58       {
       
    59         val url = base_url + "/" + Url.encode(version) + "/" + platform.archive
       
    60         Isabelle_System.download(url, archive_file, progress = progress)
       
    61         Isabelle_System.bash("unzip -x " + File.bash_path(archive_file),
       
    62             cwd = component_dir.file).check
       
    63 
       
    64         val unzip_dir = component_dir + Path.explode("java-cef-build-bin")
       
    65         for {
       
    66           file <- File.find_files(unzip_dir.file).iterator
       
    67           name = file.getName if name.containsSlice("LICENSE")
       
    68           target_file = component_dir + Path.explode(name) if !target_file.is_file
       
    69         } Isabelle_System.move_file(File.path(file), target_file)
       
    70 
       
    71         val platform_dir = component_dir + Path.explode(platform.platform_name)
       
    72         Isabelle_System.move_file(unzip_dir + Path.explode("bin"), platform_dir)
       
    73         for {
       
    74           file <- File.find_files(platform_dir.file).iterator
       
    75           name = file.getName
       
    76           if name.endsWith(".dll") || name.endsWith(".exe")
       
    77         } File.set_executable(File.path(file), true)
       
    78 
       
    79         Isabelle_System.rm_tree(unzip_dir)
       
    80       })
       
    81     }
       
    82 
       
    83 
       
    84     /* settings */
       
    85 
       
    86     val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc"))
       
    87     File.write(etc_dir + Path.basic("settings"),
       
    88       """# -*- shell-script -*- :mode=shellscript:
       
    89 
       
    90 if [ -d "$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}" ]
       
    91 then
       
    92   ISABELLE_JCEF_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}"
       
    93   ISABELLE_JCEF_LIBRARY=""
       
    94   case "$ISABELLE_PLATFORM_FAMILY" in
       
    95     linux)
       
    96       classpath "$ISABELLE_JCEF_HOME/"*.jar
       
    97       ISABELLE_JCEF_LIB="$ISABELLE_JCEF_HOME/lib/linux64"
       
    98       ISABELLE_JCEF_LIBRARY="$ISABELLE_JCEF_LIB/libcef.so"
       
    99       export LD_LIBRARY_PATH="$ISABELLE_JCEF_LIB:$LD_LIBRARY_PATH"
       
   100       ;;
       
   101     windows)
       
   102       classpath "$ISABELLE_JCEF_HOME/"*.jar
       
   103       ISABELLE_JCEF_LIB="$ISABELLE_JCEF_HOME/lib/win64"
       
   104       export PATH="$ISABELLE_JCEF_LIB:$PATH"
       
   105       ;;
       
   106     macos)
       
   107       classpath "$ISABELLE_JCEF_HOME/jcef_app.app/Contents/Java/"*.jar
       
   108       ISABELLE_JCEF_LIB="$ISABELLE_JCEF_HOME/jcef_app.app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries"
       
   109       export JAVA_LIBRARY_PATH="$ISABELLE_JCEF_HOME/jcef_app.app/Contents/Java:$ISABELLE_JCEF_LIB:$JAVA_LIBRARY_PATH"
       
   110       ;;
       
   111   esac
       
   112 fi
       
   113 """)
       
   114 
       
   115 
       
   116     /* README */
       
   117 
       
   118     File.write(component_dir + Path.basic("README"),
       
   119       """This distribution of Java Chromium Embedded Framework (JCEF)
       
   120 has been assembled from the binary builds from
       
   121 """ + base_url + """
       
   122 
       
   123 Examples invocations:
       
   124 
       
   125 * command-line
       
   126 
       
   127   isabelle env bash -c 'isabelle java -Djava.library.path="$(platform_path "$ISABELLE_JCEF_LIB")" tests.detailed.MainFrame'
       
   128 
       
   129 * Scala REPL (e.g. Isabelle/jEdit Console)
       
   130 
       
   131   import isabelle._
       
   132   System.setProperty("java.library.path", File.platform_path(Path.explode("$ISABELLE_JCEF_LIB")))
       
   133   org.cef.CefApp.startup(Array())
       
   134   GUI_Thread.later { val frame = new tests.detailed.MainFrame(false, false, false, Array()); frame.setSize(1200,900); frame.setVisible(true) }
       
   135 
       
   136 
       
   137         Makarius
       
   138         """ + Date.Format.date(Date.now()) + "\n")
       
   139   }
       
   140 
       
   141 
       
   142   /* Isabelle tool wrapper */
       
   143 
       
   144   val isabelle_tool =
       
   145     Isabelle_Tool("build_jcef", "build component for Java Chromium Embedded Framework",
       
   146       Scala_Project.here, args =>
       
   147     {
       
   148       var target_dir = Path.current
       
   149       var base_url = default_url
       
   150       var version = default_version
       
   151 
       
   152       val getopts = Getopts("""
       
   153 Usage: isabelle build_jcef [OPTIONS]
       
   154 
       
   155   Options are:
       
   156     -D DIR       target directory (default ".")
       
   157     -U URL       download URL (default: """" + default_url + """")
       
   158     -V VERSION   version (default: """" + default_version + """")
       
   159 
       
   160   Build component for Java Chromium Embedded Framework.
       
   161 """,
       
   162         "D:" -> (arg => target_dir = Path.explode(arg)),
       
   163         "U:" -> (arg => base_url = arg),
       
   164         "V:" -> (arg => version = arg))
       
   165 
       
   166       val more_args = getopts(args)
       
   167       if (more_args.nonEmpty) getopts.usage()
       
   168 
       
   169       val progress = new Console_Progress()
       
   170 
       
   171       build_jcef(base_url = base_url, version = version, target_dir = target_dir,
       
   172         progress = progress)
       
   173     })
       
   174 }