src/Tools/VSCode/src/build_vscodium.scala
author wenzelm
Sun, 20 Nov 2022 23:37:54 +0100
changeset 76518 b30b8e23383c
parent 75959 4fe213c214f9
child 76530 2bf13b30b98e
permissions -rw-r--r--
clarified signature: more explicit types;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75247
4a9809ee1a85 clarified directories;
wenzelm
parents: 75232
diff changeset
     1
/*  Title:      Tools/VSCode/src/build_vscodium.scala
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     3
75250
e1dd62dd5540 tuned comments;
wenzelm
parents: 75249
diff changeset
     4
Build the Isabelle system component for VSCodium: cross-compilation for all
e1dd62dd5540 tuned comments;
wenzelm
parents: 75249
diff changeset
     5
platforms.
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     6
*/
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     7
75247
4a9809ee1a85 clarified directories;
wenzelm
parents: 75232
diff changeset
     8
package isabelle.vscode
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     9
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    10
75247
4a9809ee1a85 clarified directories;
wenzelm
parents: 75232
diff changeset
    11
import isabelle._
4a9809ee1a85 clarified directories;
wenzelm
parents: 75232
diff changeset
    12
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    13
import java.security.MessageDigest
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    14
import java.util.Base64
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    15
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    16
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    17
object Build_VSCodium {
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    18
  /* global parameters */
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    19
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    20
  lazy val version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION")
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    21
  val vscodium_repository = "https://github.com/VSCodium/vscodium.git"
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    22
  val vscodium_download = "https://github.com/VSCodium/vscodium/releases/download"
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    23
75278
wenzelm
parents: 75277
diff changeset
    24
  private val resources = Path.explode("resources")
wenzelm
parents: 75277
diff changeset
    25
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    26
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    27
  /* Isabelle symbols (static subset only) */
75252
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
    28
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    29
  def make_symbols(): File.Content = {
75252
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
    30
    val symbols = Symbol.Symbols.load(static = true)
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    31
    val symbols_js =
75959
4fe213c214f9 support for pretty-printing of JSON trees;
wenzelm
parents: 75906
diff changeset
    32
      JSON.Format.pretty_print(
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    33
        for (entry <- symbols.entries) yield
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    34
          JSON.Object(
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    35
            "symbol" -> entry.symbol,
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    36
            "name" -> entry.name,
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    37
            "abbrevs" -> entry.abbrevs) ++
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    38
          JSON.optional("code", entry.code))
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    39
75824
a2b2e8964e1a tuned signature;
wenzelm
parents: 75394
diff changeset
    40
    File.content(Path.explode("symbols.json"), symbols_js)
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    41
  }
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    42
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    43
  def make_isabelle_encoding(header: String): File.Content = {
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    44
    val symbols = Symbol.Symbols.load(static = true)
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    45
    val symbols_js =
75959
4fe213c214f9 support for pretty-printing of JSON trees;
wenzelm
parents: 75906
diff changeset
    46
      JSON.Format.pretty_print(
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    47
        for (entry <- symbols.entries; code <- entry.code)
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    48
          yield JSON.Object("symbol" -> entry.symbol, "code" -> code))
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    49
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    50
    val path = Path.explode("isabelle_encoding.ts")
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    51
    val body =
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    52
      File.read(Path.explode("$ISABELLE_VSCODE_HOME/patches") + path)
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
    53
        .replace("[/*symbols*/]", symbols_js)
75824
a2b2e8964e1a tuned signature;
wenzelm
parents: 75394
diff changeset
    54
    File.content(path, header + "\n" + body)
75252
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
    55
  }
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
    56
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
    57
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    58
  /* platform info */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    59
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    60
  sealed case class Platform_Info(
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    61
    platform: Platform.Family.Value,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    62
    download_template: String,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    63
    build_name: String,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    64
    env: List[String]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    65
  ) {
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    66
    def is_linux: Boolean = platform == Platform.Family.linux
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    67
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    68
    def download_name: String = "VSCodium-" + download_template.replace("{VERSION}", version)
75906
2167b9e3157a clarified signature: support for adhoc file types;
wenzelm
parents: 75824
diff changeset
    69
    def download_zip: Boolean = File.is_zip(download_name)
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    70
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    71
    def download(dir: Path, progress: Progress = new Progress): Unit = {
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    72
      if (download_zip) Isabelle_System.require_command("unzip", test = "-h")
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    73
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    74
      Isabelle_System.with_tmp_file("download") { download_file =>
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    75
        Isabelle_System.download_file(vscodium_download + "/" + version + "/" + download_name,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    76
          download_file, progress = progress)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    77
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    78
        progress.echo("Extract ...")
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    79
        if (download_zip) {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    80
          Isabelle_System.bash("unzip -x " + File.bash_path(download_file), cwd = dir.file).check
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    81
        }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    82
        else {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    83
          Isabelle_System.gnutar("-xzf " + File.bash_path(download_file), dir = dir).check
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    84
        }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    85
      }
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    86
    }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    87
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
    88
    def get_vscodium_repository(build_dir: Path, progress: Progress = new Progress): Unit = {
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    89
      progress.echo("Getting VSCodium repository ...")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    90
      Isabelle_System.bash(
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    91
        List(
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    92
          "set -e",
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    93
          "git clone -n " + Bash.string(vscodium_repository) + " .",
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    94
          "git checkout -q " + Bash.string(version)
75272
wenzelm
parents: 75271
diff changeset
    95
        ).mkString("\n"), cwd = build_dir.file).check
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    96
75232
6c4ec2a27ad6 tuned message;
wenzelm
parents: 75231
diff changeset
    97
      progress.echo("Getting VSCode repository ...")
75272
wenzelm
parents: 75271
diff changeset
    98
      Isabelle_System.bash(environment + "\n" + "./get_repo.sh", cwd = build_dir.file).check
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
    99
    }
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   100
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   101
    def platform_dir(dir: Path): Path = {
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   102
      val platform_name =
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   103
        if (platform == Platform.Family.windows) Platform.Family.native(platform)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   104
        else Platform.Family.standard(platform)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   105
      dir + Path.explode(platform_name)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   106
    }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   107
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   108
    def build_dir(dir: Path): Path = dir + Path.explode(build_name)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   109
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   110
    def environment: String =
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   111
      (("MS_TAG=" + Bash.string(version)) :: "SHOULD_BUILD=yes" :: "VSCODE_ARCH=x64" :: env)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   112
        .map(s => "export " + s + "\n").mkString
75222
wenzelm
parents: 75217
diff changeset
   113
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   114
    def patch_sources(base_dir: Path): String = {
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   115
      val dir = base_dir + Path.explode("vscode")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   116
      Isabelle_System.with_copy_dir(dir, dir.orig) {
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   117
        // macos icns
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   118
        for (name <- Seq("build/lib/electron.js", "build/lib/electron.ts")) {
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   119
          File.change(dir + Path.explode(name), strict = true) {
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   120
            _.replace("""'resources/darwin/' + icon + '.icns'""",
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   121
              """'resources/darwin/' + icon.toLowerCase() + '.icns'""")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   122
          }
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   123
        }
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   124
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   125
        // isabelle_encoding.ts
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   126
        {
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   127
          val common_dir = dir + Path.explode("src/vs/workbench/services/textfile/common")
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   128
          val header =
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   129
            split_lines(File.read(common_dir + Path.explode("encoding.ts")))
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   130
              .takeWhile(_.trim.nonEmpty)
75253
1b1b60db9dda clarified modules: vscode vs. extension;
wenzelm
parents: 75252
diff changeset
   131
          make_isabelle_encoding(cat_lines(header)).write(common_dir)
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   132
        }
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   133
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   134
        // explicit patches
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   135
        {
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   136
          val patches_dir = Path.explode("$ISABELLE_VSCODE_HOME/patches")
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   137
          for (name <- Seq("cli", "isabelle_encoding", "no_ocaml_icons")) {
75271
wenzelm
parents: 75269
diff changeset
   138
            val path = patches_dir + Path.explode(name).patch
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   139
            Isabelle_System.bash("patch -p1 < " + File.bash_path(path), cwd = dir.file).check
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   140
          }
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   141
        }
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   142
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   143
        Isabelle_System.make_patch(base_dir, dir.base.orig, dir.base)
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   144
      }
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   145
    }
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   146
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   147
    def patch_resources(base_dir: Path): String = {
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   148
      val dir = base_dir + resources
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   149
      val patch =
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   150
        Isabelle_System.with_copy_dir(dir, dir.orig) {
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   151
          val fonts_dir = dir + Path.explode("app/out/vs/base/browser/ui/fonts")
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   152
          HTML.init_fonts(fonts_dir.dir)
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   153
          make_symbols().write(fonts_dir)
75222
wenzelm
parents: 75217
diff changeset
   154
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   155
          val workbench_css = dir + Path.explode("app/out/vs/workbench/workbench.desktop.main.css")
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   156
          val checksum1 = file_checksum(workbench_css)
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   157
          File.append(workbench_css, "\n\n" + HTML.fonts_css_dir(prefix = "../base/browser/ui"))
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   158
          val checksum2 = file_checksum(workbench_css)
75222
wenzelm
parents: 75217
diff changeset
   159
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   160
          val file_name = workbench_css.file_name
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   161
          File.change_lines(dir + Path.explode("app/product.json")) { _.map(line =>
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   162
            if (line.containsSlice(file_name) && line.contains(checksum1)) {
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   163
              line.replace(checksum1, checksum2)
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   164
            }
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   165
            else line)
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   166
          }
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   167
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   168
          Isabelle_System.make_patch(dir.dir, dir.orig.base, dir.base)
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   169
        }
75222
wenzelm
parents: 75217
diff changeset
   170
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   171
      val app_dir = dir + Path.explode("app")
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   172
      val vscodium_app_dir = dir + Path.explode("vscodium")
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   173
      Isabelle_System.move_file(app_dir, vscodium_app_dir)
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   174
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   175
      Isabelle_System.make_directory(app_dir)
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   176
      if ((vscodium_app_dir + resources).is_dir) {
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   177
        Isabelle_System.copy_dir(vscodium_app_dir + resources, app_dir)
75222
wenzelm
parents: 75217
diff changeset
   178
      }
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   179
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   180
      patch
75222
wenzelm
parents: 75217
diff changeset
   181
    }
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   182
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   183
    def init_resources(base_dir: Path): Path = {
75278
wenzelm
parents: 75277
diff changeset
   184
      val dir = base_dir + resources
75255
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   185
      if (platform == Platform.Family.macos) {
75278
wenzelm
parents: 75277
diff changeset
   186
        Isabelle_System.symlink(Path.explode("VSCodium.app/Contents/Resources"), dir)
75255
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   187
      }
75278
wenzelm
parents: 75277
diff changeset
   188
      dir
75255
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   189
    }
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   190
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   191
    def setup_node(target_dir: Path, progress: Progress): Unit = {
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   192
      Isabelle_System.with_tmp_dir("download") { download_dir =>
75228
33fb3014876f recover platform-specific node binaries from original download, notably for node-pty for Terminal;
wenzelm
parents: 75227
diff changeset
   193
        download(download_dir, progress = progress)
75255
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   194
        val dir1 = init_resources(download_dir)
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   195
        val dir2 = init_resources(target_dir)
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   196
        for (name <- Seq("app/node_modules.asar", "app/node_modules.asar.unpacked")) {
75252
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
   197
          val path = Path.explode(name)
75255
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   198
          Isabelle_System.rm_tree(dir2 + path)
d192b0a8b620 proper init_resources for macos;
wenzelm
parents: 75253
diff changeset
   199
          Isabelle_System.copy_dir(dir1 + path, dir2 + path)
75228
33fb3014876f recover platform-specific node binaries from original download, notably for node-pty for Terminal;
wenzelm
parents: 75227
diff changeset
   200
        }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   201
      }
75228
33fb3014876f recover platform-specific node binaries from original download, notably for node-pty for Terminal;
wenzelm
parents: 75227
diff changeset
   202
    }
33fb3014876f recover platform-specific node binaries from original download, notably for node-pty for Terminal;
wenzelm
parents: 75227
diff changeset
   203
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   204
    def setup_electron(dir: Path): Unit = {
75273
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   205
      val electron = Path.explode("electron")
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   206
      platform match {
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   207
        case Platform.Family.linux | Platform.Family.linux_arm =>
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   208
          Isabelle_System.move_file(dir + Path.explode("codium"), dir + electron)
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   209
        case Platform.Family.windows =>
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   210
          Isabelle_System.move_file(dir + Path.explode("VSCodium.exe"), dir + electron.exe)
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   211
          Isabelle_System.move_file(
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   212
            dir + Path.explode("VSCodium.VisualElementsManifest.xml"),
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   213
            dir + Path.explode("electron.VisualElementsManifest.xml"))
75279
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   214
        case Platform.Family.macos =>
75273
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   215
      }
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   216
    }
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   217
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   218
    def setup_executables(dir: Path): Unit = {
75273
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   219
      Isabelle_System.rm_tree(dir + Path.explode("bin"))
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   220
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   221
      if (platform == Platform.Family.windows) {
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   222
        val files =
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   223
          File.find_files(dir.file, pred = { file =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   224
            val name = file.getName
75906
2167b9e3157a clarified signature: support for adhoc file types;
wenzelm
parents: 75824
diff changeset
   225
            File.is_dll(name) || File.is_exe(name) || File.is_node(name)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   226
          })
75273
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   227
        files.foreach(file => File.set_executable(File.path(file), true))
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   228
        Isabelle_System.bash("chmod -R o-w " + File.bash_path(dir)).check
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   229
      }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   230
    }
75222
wenzelm
parents: 75217
diff changeset
   231
  }
wenzelm
parents: 75217
diff changeset
   232
75252
41dfe941c3da inline Isabelle symbols into source text, so that "isabelle vscode" can start up properly without access to process.env or fs;
wenzelm
parents: 75250
diff changeset
   233
75222
wenzelm
parents: 75217
diff changeset
   234
  // see https://github.com/microsoft/vscode/blob/main/build/gulpfile.vscode.js
wenzelm
parents: 75217
diff changeset
   235
  // function computeChecksum(filename)
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   236
  private def file_checksum(path: Path): String = {
75222
wenzelm
parents: 75217
diff changeset
   237
    val digest = MessageDigest.getInstance("MD5")
wenzelm
parents: 75217
diff changeset
   238
    digest.update(Bytes.read(path).array)
wenzelm
parents: 75217
diff changeset
   239
    Bytes(Base64.getEncoder.encode(digest.digest()))
wenzelm
parents: 75217
diff changeset
   240
      .text.replaceAll("=", "")
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   241
  }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   242
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   243
  private val platform_infos: Map[Platform.Family.Value, Platform_Info] =
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   244
    Iterator(
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   245
      Platform_Info(Platform.Family.linux, "linux-x64-{VERSION}.tar.gz", "VSCode-linux-x64",
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   246
        List("OS_NAME=linux", "SKIP_LINUX_PACKAGES=True")),
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   247
      Platform_Info(Platform.Family.linux_arm, "linux-arm64-{VERSION}.tar.gz", "VSCode-linux-arm64",
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   248
        List("OS_NAME=linux", "SKIP_LINUX_PACKAGES=True", "VSCODE_ARCH=arm64")),
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   249
      Platform_Info(Platform.Family.macos, "darwin-x64-{VERSION}.zip", "VSCode-darwin-x64",
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   250
        List("OS_NAME=osx")),
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   251
      Platform_Info(Platform.Family.windows, "win32-x64-{VERSION}.zip", "VSCode-win32-x64",
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   252
        List("OS_NAME=windows",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   253
          "SHOULD_BUILD_ZIP=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   254
          "SHOULD_BUILD_EXE_SYS=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   255
          "SHOULD_BUILD_EXE_USR=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   256
          "SHOULD_BUILD_MSI=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   257
          "SHOULD_BUILD_MSI_NOUP=no")))
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   258
      .map(info => info.platform -> info).toMap
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   259
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   260
  def the_platform_info(platform: Platform.Family.Value): Platform_Info =
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   261
    platform_infos.getOrElse(platform, error("No platform info for " + quote(platform.toString)))
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   262
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   263
  def linux_platform_info: Platform_Info =
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   264
    the_platform_info(Platform.Family.linux)
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   265
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   266
75222
wenzelm
parents: 75217
diff changeset
   267
  /* check system */
wenzelm
parents: 75217
diff changeset
   268
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   269
  def check_system(platforms: List[Platform.Family.Value]): Unit = {
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   270
    if (Platform.family != Platform.Family.linux) error("Not a Linux/x86_64 system")
75222
wenzelm
parents: 75217
diff changeset
   271
wenzelm
parents: 75217
diff changeset
   272
    Isabelle_System.require_command("git")
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   273
    Isabelle_System.require_command("node")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   274
    Isabelle_System.require_command("yarn")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   275
    Isabelle_System.require_command("jq")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   276
75222
wenzelm
parents: 75217
diff changeset
   277
    if (platforms.contains(Platform.Family.windows)) {
wenzelm
parents: 75217
diff changeset
   278
      Isabelle_System.require_command("wine")
wenzelm
parents: 75217
diff changeset
   279
    }
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   280
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   281
    if (platforms.exists(platform => the_platform_info(platform).download_zip)) {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   282
      Isabelle_System.require_command("unzip", test = "-h")
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   283
    }
75222
wenzelm
parents: 75217
diff changeset
   284
  }
wenzelm
parents: 75217
diff changeset
   285
wenzelm
parents: 75217
diff changeset
   286
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   287
  /* original repository clones and patches */
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   288
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   289
  def vscodium_patch(verbose: Boolean = false, progress: Progress = new Progress): String = {
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   290
    val platform_info = linux_platform_info
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   291
    check_system(List(platform_info.platform))
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   292
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   293
    Isabelle_System.with_tmp_dir("build") { build_dir =>
75272
wenzelm
parents: 75271
diff changeset
   294
      platform_info.get_vscodium_repository(build_dir, progress = progress)
wenzelm
parents: 75271
diff changeset
   295
      val vscode_dir = build_dir + Path.explode("vscode")
75250
e1dd62dd5540 tuned comments;
wenzelm
parents: 75249
diff changeset
   296
      progress.echo("Prepare ...")
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   297
      Isabelle_System.with_copy_dir(vscode_dir, vscode_dir.orig) {
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   298
        progress.bash(
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   299
          List(
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   300
            "set -e",
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   301
            platform_info.environment,
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   302
            "./prepare_vscode.sh",
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   303
            // enforce binary diff of code.xpm
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   304
            "cp vscode/resources/linux/code.png vscode/resources/linux/rpm/code.xpm"
75272
wenzelm
parents: 75271
diff changeset
   305
          ).mkString("\n"), cwd = build_dir.file, echo = verbose).check
wenzelm
parents: 75271
diff changeset
   306
        Isabelle_System.make_patch(build_dir, vscode_dir.orig.base, vscode_dir.base,
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   307
          diff_options = "--exclude=.git --exclude=node_modules")
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   308
      }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   309
    }
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   310
  }
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   311
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   312
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   313
  /* build vscodium */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   314
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   315
  def default_platforms: List[Platform.Family.Value] = Platform.Family.list
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   316
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   317
  def build_vscodium(
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   318
    target_dir: Path = Path.current,
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   319
    platforms: List[Platform.Family.Value] = default_platforms,
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   320
    verbose: Boolean = false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   321
    progress: Progress = new Progress
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   322
  ): Unit = {
75222
wenzelm
parents: 75217
diff changeset
   323
    check_system(platforms)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   324
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   325
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   326
    /* component */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   327
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   328
    val component_name = "vscodium-" + version
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   329
    val component_dir =
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   330
      Components.Directory.create(target_dir + Path.explode(component_name), progress = progress)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   331
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   332
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   333
    /* patches */
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   334
75256
5055c0cdabc9 tuned messages;
wenzelm
parents: 75255
diff changeset
   335
    progress.echo("\n* Building patches:")
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   336
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   337
    val patches_dir = Isabelle_System.new_directory(component_dir.path + Path.explode("patches"))
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   338
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   339
    def write_patch(name: String, patch: String): Unit =
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   340
      File.write(patches_dir + Path.explode(name).patch, patch)
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   341
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   342
    write_patch("01-vscodium", vscodium_patch(verbose = verbose, progress = progress))
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   343
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   344
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   345
    /* build */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   346
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   347
    for (platform <- platforms) yield {
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   348
      val platform_info = the_platform_info(platform)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   349
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   350
      Isabelle_System.with_tmp_dir("build") { build_dir =>
75256
5055c0cdabc9 tuned messages;
wenzelm
parents: 75255
diff changeset
   351
        progress.echo("\n* Building " + platform + ":")
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   352
75272
wenzelm
parents: 75271
diff changeset
   353
        platform_info.get_vscodium_repository(build_dir, progress = progress)
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   354
75272
wenzelm
parents: 75271
diff changeset
   355
        val sources_patch = platform_info.patch_sources(build_dir)
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   356
        if (platform_info.is_linux) write_patch("02-isabelle_sources", sources_patch)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   357
75250
e1dd62dd5540 tuned comments;
wenzelm
parents: 75249
diff changeset
   358
        progress.echo("Build ...")
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   359
        progress.bash(platform_info.environment + "\n" + "./build.sh",
75272
wenzelm
parents: 75271
diff changeset
   360
          cwd = build_dir.file, echo = verbose).check
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   361
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   362
        if (platform_info.is_linux) {
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   363
          Isabelle_System.copy_file(build_dir + Path.explode("LICENSE"), component_dir.path)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   364
        }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   365
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   366
        val platform_dir = platform_info.platform_dir(component_dir.path)
75272
wenzelm
parents: 75271
diff changeset
   367
        Isabelle_System.copy_dir(platform_info.build_dir(build_dir), platform_dir)
75273
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   368
        platform_info.setup_node(platform_dir, progress)
f1c6e778e412 clarified and unified executable names;
wenzelm
parents: 75272
diff changeset
   369
        platform_info.setup_electron(platform_dir)
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   370
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   371
        val resources_patch = platform_info.patch_resources(platform_dir)
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   372
        if (platform_info.is_linux) write_patch("03-isabelle_resources", resources_patch)
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   373
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   374
        Isabelle_System.copy_file(
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   375
          build_dir + Path.explode("vscode/node_modules/electron/dist/resources/default_app.asar"),
75278
wenzelm
parents: 75277
diff changeset
   376
          platform_dir + resources)
75277
f64725832d63 support Electron application framework;
wenzelm
parents: 75273
diff changeset
   377
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   378
        platform_info.setup_executables(platform_dir)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   379
      }
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   380
    }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   381
75231
8945d691ecf2 more compact result;
wenzelm
parents: 75230
diff changeset
   382
    Isabelle_System.bash("gzip *.patch", cwd = patches_dir.file).check
8945d691ecf2 more compact result;
wenzelm
parents: 75230
diff changeset
   383
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   384
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   385
    /* settings */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   386
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   387
    File.write(component_dir.settings,
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   388
      """# -*- shell-script -*- :mode=shellscript:
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   389
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   390
ISABELLE_VSCODIUM_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}"
75279
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   391
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   392
if [ "$ISABELLE_PLATFORM_FAMILY" = "macos" ]; then
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   393
  ISABELLE_VSCODIUM_ELECTRON="$ISABELLE_VSCODIUM_HOME/VSCodium.app/Contents/MacOS/Electron"
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   394
  ISABELLE_VSCODIUM_RESOURCES="$ISABELLE_VSCODIUM_HOME/VSCodium.app/Contents/Resources"
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   395
else
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   396
  ISABELLE_VSCODIUM_ELECTRON="$ISABELLE_VSCODIUM_HOME/electron"
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   397
  ISABELLE_VSCODIUM_RESOURCES="$ISABELLE_VSCODIUM_HOME/resources"
9229f2681db7 clarified directory layout and settings: more robust on all platforms;
wenzelm
parents: 75278
diff changeset
   398
fi
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   399
""")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   400
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   401
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   402
    /* README */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   403
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75959
diff changeset
   404
    File.write(component_dir.README,
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   405
      "This is VSCodium " + version + " from " + vscodium_repository +
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   406
"""
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   407
75230
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   408
It has been built from sources using "isabelle build_vscodium". This applies
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   409
a few changes required for Isabelle/VSCode, see "patches" directory for a
bbbee54b1198 prepare patched version more thoroughly, with explicit patches;
wenzelm
parents: 75228
diff changeset
   410
formal record.
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   411
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   412
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   413
        Makarius
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   414
        """ + Date.Format.date(Date.now()) + "\n")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   415
  }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   416
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   417
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   418
  /* Isabelle tool wrappers */
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   419
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   420
  val isabelle_tool1 =
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   421
    Isabelle_Tool("build_vscodium", "build component for VSCodium",
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   422
      Scala_Project.here,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   423
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   424
        var target_dir = Path.current
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   425
        var platforms = default_platforms
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   426
        var verbose = false
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   427
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   428
        val getopts = Getopts("""
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   429
Usage: build_vscodium [OPTIONS]
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   430
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   431
  Options are:
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   432
    -D DIR       target directory (default ".")
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   433
    -p NAMES     platform families (default: """ + quote(platforms.mkString(",")) + """)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   434
    -v           verbose
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   435
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   436
  Build VSCodium from sources and turn it into an Isabelle component.
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   437
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   438
  The build platform needs to be Linux with nodejs/yarn, jq, and wine
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   439
  for targeting Windows.
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   440
""",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   441
          "D:" -> (arg => target_dir = Path.explode(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   442
          "p:" -> (arg => platforms = Library.space_explode(',', arg).map(Platform.Family.parse)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   443
          "v" -> (_ => verbose = true))
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   444
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   445
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   446
        if (more_args.nonEmpty) getopts.usage()
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   447
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   448
        val progress = new Console_Progress()
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   449
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   450
        build_vscodium(target_dir = target_dir, platforms = platforms,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   451
          verbose = verbose, progress = progress)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   452
      })
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   453
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   454
  val isabelle_tool2 =
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   455
    Isabelle_Tool("vscode_patch", "patch VSCode source tree",
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75279
diff changeset
   456
      Scala_Project.here,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   457
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   458
        var base_dir = Path.current
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   459
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   460
        val getopts = Getopts("""
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   461
Usage: vscode_patch [OPTIONS]
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   462
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   463
  Options are:
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   464
    -D DIR       base directory (default ".")
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   465
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   466
  Patch original VSCode source tree for use with Isabelle/VSCode.
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   467
""",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   468
          "D:" -> (arg => base_dir = Path.explode(arg)))
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   469
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   470
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   471
        if (more_args.nonEmpty) getopts.usage()
75249
8142e75320f6 patch VSCode source tree to support isabelle_encoding.ts;
wenzelm
parents: 75247
diff changeset
   472
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   473
        val platform_info = the_platform_info(Platform.family)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   474
        platform_info.patch_sources(base_dir)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   475
      })
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   476
}