src/Tools/VSCode/src/build_vscodium.scala
changeset 75273 f1c6e778e412
parent 75272 3ee89eaa0b55
child 75277 f64725832d63
equal deleted inserted replaced
75272:3ee89eaa0b55 75273:f1c6e778e412
    19   /* global parameters */
    19   /* global parameters */
    20 
    20 
    21   lazy val version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION")
    21   lazy val version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION")
    22   val vscodium_repository = "https://github.com/VSCodium/vscodium.git"
    22   val vscodium_repository = "https://github.com/VSCodium/vscodium.git"
    23   val vscodium_download = "https://github.com/VSCodium/vscodium/releases/download"
    23   val vscodium_download = "https://github.com/VSCodium/vscodium/releases/download"
    24 
       
    25   def vscodium_exe(dir: Path): Path = dir + Path.explode("bin/codium")
       
    26 
    24 
    27 
    25 
    28   /* Isabelle symbols (static subset only) */
    26   /* Isabelle symbols (static subset only) */
    29 
    27 
    30   def make_symbols(): File.Content =
    28   def make_symbols(): File.Content =
   184         Isabelle_System.symlink(Path.explode("VSCodium.app/Contents/Resources"), resources_dir)
   182         Isabelle_System.symlink(Path.explode("VSCodium.app/Contents/Resources"), resources_dir)
   185       }
   183       }
   186       resources_dir
   184       resources_dir
   187     }
   185     }
   188 
   186 
   189     def node_binaries(target_dir: Path, progress: Progress): Unit =
   187     def setup_node(target_dir: Path, progress: Progress): Unit =
   190     {
   188     {
   191       Isabelle_System.with_tmp_dir("download")(download_dir =>
   189       Isabelle_System.with_tmp_dir("download")(download_dir =>
   192       {
   190       {
   193         download(download_dir, progress = progress)
   191         download(download_dir, progress = progress)
   194         val dir1 = init_resources(download_dir)
   192         val dir1 = init_resources(download_dir)
   199           Isabelle_System.copy_dir(dir1 + path, dir2 + path)
   197           Isabelle_System.copy_dir(dir1 + path, dir2 + path)
   200         }
   198         }
   201       })
   199       })
   202     }
   200     }
   203 
   201 
       
   202     def setup_electron(dir: Path): Unit =
       
   203     {
       
   204       val electron = Path.explode("electron")
       
   205       platform match {
       
   206         case Platform.Family.linux | Platform.Family.linux_arm =>
       
   207           Isabelle_System.move_file(dir + Path.explode("codium"), dir + electron)
       
   208         case Platform.Family.macos =>
       
   209           Isabelle_System.symlink(Path.explode("VSCodium.app/Contents/MacOS/Electron"), dir + electron)
       
   210         case Platform.Family.windows =>
       
   211           Isabelle_System.move_file(dir + Path.explode("VSCodium.exe"), dir + electron.exe)
       
   212           Isabelle_System.move_file(
       
   213             dir + Path.explode("VSCodium.VisualElementsManifest.xml"),
       
   214             dir + Path.explode("electron.VisualElementsManifest.xml"))
       
   215       }
       
   216     }
       
   217 
   204     def setup_executables(dir: Path): Unit =
   218     def setup_executables(dir: Path): Unit =
   205     {
   219     {
   206       val exe = vscodium_exe(dir)
   220       Isabelle_System.rm_tree(dir + Path.explode("bin"))
   207       Isabelle_System.make_directory(exe.dir)
   221 
   208 
   222       val exe = dir + Path.explode("vscodium")
   209       platform match {
   223       File.write(exe, """#!/usr/bin/env bash
   210         case Platform.Family.macos =>
   224 
   211           File.write(exe, macos_exe)
   225 unset CDPATH
   212           File.set_executable(exe, true)
   226 THIS="$(cd "$(dirname "$0")"; pwd -P)"
   213         case Platform.Family.windows =>
   227 
   214           val files1 = File.find_files(exe.dir.file)
   228 ELECTRON_RUN_AS_NODE=1 "$THIS/electron" "$THIS/resources/app/out/cli.js" --ms-enable-electron-run-as-node "$@"
   215           val files2 = File.find_files(dir.file, pred = file =>
   229 """)
       
   230       File.set_executable(exe, true)
       
   231 
       
   232       if (platform == Platform.Family.windows) {
       
   233         val files =
       
   234           File.find_files(dir.file, pred = file =>
   216             {
   235             {
   217               val name = file.getName
   236               val name = file.getName
   218               name.endsWith(".dll") || name.endsWith(".exe") || name.endsWith(".node")
   237               name.endsWith(".dll") || name.endsWith(".exe") || name.endsWith(".node")
   219             })
   238             })
   220           for (file <- files1 ::: files2) File.set_executable(File.path(file), true)
   239         files.foreach(file => File.set_executable(File.path(file), true))
   221           Isabelle_System.bash("chmod -R o-w " + File.bash_path(dir)).check
   240         Isabelle_System.bash("chmod -R o-w " + File.bash_path(dir)).check
   222         case _ =>
       
   223       }
   241       }
   224     }
   242     }
   225   }
   243   }
   226 
   244 
   227 
   245 
   310 
   328 
   311   /* build vscodium */
   329   /* build vscodium */
   312 
   330 
   313   def default_platforms: List[Platform.Family.Value] = Platform.Family.list
   331   def default_platforms: List[Platform.Family.Value] = Platform.Family.list
   314 
   332 
   315   def macos_exe: String =
       
   316 """#!/usr/bin/env bash
       
   317 
       
   318 unset CDPATH
       
   319 VSCODE_PATH="$(cd "$(dirname "$0")"/../VSCodium.app/Contents; pwd)"
       
   320 
       
   321 ELECTRON="$VSCODE_PATH/MacOS/Electron"
       
   322 CLI="$VSCODE_PATH/Resources/app/out/cli.js"
       
   323 ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --ms-enable-electron-run-as-node "$@"
       
   324 exit $?
       
   325 """
       
   326 
       
   327   def build_vscodium(
   333   def build_vscodium(
   328     target_dir: Path = Path.current,
   334     target_dir: Path = Path.current,
   329     platforms: List[Platform.Family.Value] = default_platforms,
   335     platforms: List[Platform.Family.Value] = default_platforms,
   330     verbose: Boolean = false,
   336     verbose: Boolean = false,
   331     progress: Progress = new Progress): Unit =
   337     progress: Progress = new Progress): Unit =
   355     /* build */
   361     /* build */
   356 
   362 
   357     for (platform <- platforms) yield {
   363     for (platform <- platforms) yield {
   358       val platform_info = the_platform_info(platform)
   364       val platform_info = the_platform_info(platform)
   359 
   365 
   360       Isabelle_System.with_tmp_dir("vscodium")(build_dir =>
   366       Isabelle_System.with_tmp_dir("build")(build_dir =>
   361       {
   367       {
   362         progress.echo("\n* Building " + platform + ":")
   368         progress.echo("\n* Building " + platform + ":")
   363 
   369 
   364         platform_info.get_vscodium_repository(build_dir, progress = progress)
   370         platform_info.get_vscodium_repository(build_dir, progress = progress)
   365 
   371 
   374           Isabelle_System.copy_file(build_dir + Path.explode("LICENSE"), component_dir)
   380           Isabelle_System.copy_file(build_dir + Path.explode("LICENSE"), component_dir)
   375         }
   381         }
   376 
   382 
   377         val platform_dir = platform_info.platform_dir(component_dir)
   383         val platform_dir = platform_info.platform_dir(component_dir)
   378         Isabelle_System.copy_dir(platform_info.build_dir(build_dir), platform_dir)
   384         Isabelle_System.copy_dir(platform_info.build_dir(build_dir), platform_dir)
   379         platform_info.node_binaries(platform_dir, progress)
   385         platform_info.setup_node(platform_dir, progress)
       
   386         platform_info.setup_electron(platform_dir)
   380 
   387 
   381         val resources_patch = platform_info.patch_resources(platform_dir)
   388         val resources_patch = platform_info.patch_resources(platform_dir)
   382         if (platform_info.is_linux) write_patch("03-isabelle_resources", resources_patch)
   389         if (platform_info.is_linux) write_patch("03-isabelle_resources", resources_patch)
   383 
   390 
   384         platform_info.setup_executables(platform_dir)
   391         platform_info.setup_executables(platform_dir)
   393     val etc_dir = Isabelle_System.make_directory(component_dir + Path.explode("etc"))
   400     val etc_dir = Isabelle_System.make_directory(component_dir + Path.explode("etc"))
   394     File.write(etc_dir + Path.explode("settings"),
   401     File.write(etc_dir + Path.explode("settings"),
   395       """# -*- shell-script -*- :mode=shellscript:
   402       """# -*- shell-script -*- :mode=shellscript:
   396 
   403 
   397 ISABELLE_VSCODIUM_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}"
   404 ISABELLE_VSCODIUM_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}"
   398 
       
   399 case "$ISABELLE_PLATFORM_FAMILY" in
       
   400   linux)
       
   401     ISABELLE_ELECTRON="$ISABELLE_VSCODIUM_HOME/codium"
       
   402     ;;
       
   403   macos)
       
   404     ISABELLE_ELECTRON="$ISABELLE_VSCODIUM_HOME/VSCodium.app/Contents/MacOS/Electron"
       
   405     ;;
       
   406   windows)
       
   407     ISABELLE_ELECTRON="$ISABELLE_VSCODIUM_HOME/VSCodium.exe"
       
   408     ;;
       
   409 esac
       
   410 """)
   405 """)
   411 
   406 
   412 
   407 
   413     /* README */
   408     /* README */
   414 
   409