src/Pure/Admin/build_vscodium.scala
author wenzelm
Sat, 05 Mar 2022 20:01:23 +0100
changeset 75225 05f677e64178
parent 75224 419781ac89bf
child 75226 5e87e4fb68d2
permissions -rw-r--r--
tuned imports;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/build_vscodium.scala
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
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     4
Build component for VSCodium (cross-compiled from sources for all platforms).
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     5
*/
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
package isabelle
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
     8
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
import java.security.MessageDigest
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    11
import java.util.Base64
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    12
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    13
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    14
object Build_VSCodium
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    15
{
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    16
  /* global parameters */
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    17
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    18
  lazy val version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION")
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    19
  val vscodium_repository = "https://github.com/VSCodium/vscodium.git"
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    20
  val vscodium_download = "https://github.com/VSCodium/vscodium/releases/download"
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    21
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    22
  def vscodium_exe(dir: Path): Path = dir + Path.explode("bin/codium")
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    23
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
    24
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    25
  /* platform info */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    26
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    27
  sealed case class Platform_Info(
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    28
    platform: Platform.Family.Value,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    29
    download_template: String,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    30
    build_name: String,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    31
    env: List[String])
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    32
  {
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    33
    def download_name: String = "VSCodium-" + download_template.replace("{VERSION}", version)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    34
    def download_zip: Boolean = download_name.endsWith(".zip")
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    35
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    36
    def download(dir: Path, progress: Progress = new Progress): Unit =
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    37
    {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    38
      if (download_zip) Isabelle_System.require_command("unzip", test = "-h")
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    39
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    40
      Isabelle_System.with_tmp_file("download")(download_file =>
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    41
      {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    42
        Isabelle_System.download_file(vscodium_download + "/" + version + "/" + download_name,
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    43
          download_file, progress = progress)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    44
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    45
        progress.echo("Unpacking " + dir.expand)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    46
        if (download_zip) {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    47
          Isabelle_System.bash("unzip -x " + File.bash_path(download_file), cwd = dir.file).check
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    48
        }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    49
        else {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    50
          Isabelle_System.gnutar("-xzf " + File.bash_path(download_file), dir = dir).check
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    51
        }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    52
      })
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    53
    }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    54
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    55
    def platform_dir(dir: Path): Path =
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    56
    {
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    57
      val platform_name =
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    58
        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
    59
        else Platform.Family.standard(platform)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    60
      dir + Path.explode(platform_name)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    61
    }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    62
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    63
    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
    64
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    65
    def build_environment: String =
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
    66
      (("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
    67
        .map(s => "export " + s + "\n").mkString
75222
wenzelm
parents: 75217
diff changeset
    68
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    69
    def resources_dir(dir: Path): Path =
75222
wenzelm
parents: 75217
diff changeset
    70
    {
wenzelm
parents: 75217
diff changeset
    71
      val resources =
wenzelm
parents: 75217
diff changeset
    72
        if (platform == Platform.Family.macos) "VSCodium.app/Contents/Resources"
wenzelm
parents: 75217
diff changeset
    73
        else "resources"
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    74
      dir + Path.explode(resources)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    75
    }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    76
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    77
    def patch_resources(dir0: Path): Unit =
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    78
    {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    79
      val dir = resources_dir(dir0)
75222
wenzelm
parents: 75217
diff changeset
    80
wenzelm
parents: 75217
diff changeset
    81
      HTML.init_fonts(dir + Path.explode("app/out/vs/base/browser/ui"))
wenzelm
parents: 75217
diff changeset
    82
wenzelm
parents: 75217
diff changeset
    83
      val workbench_css = dir + Path.explode("app/out/vs/workbench/workbench.desktop.main.css")
wenzelm
parents: 75217
diff changeset
    84
      val checksum1 = file_checksum(workbench_css)
wenzelm
parents: 75217
diff changeset
    85
      File.append(workbench_css, "\n\n" + HTML.fonts_css_dir(prefix = "../base/browser/ui"))
wenzelm
parents: 75217
diff changeset
    86
      val checksum2 = file_checksum(workbench_css)
wenzelm
parents: 75217
diff changeset
    87
wenzelm
parents: 75217
diff changeset
    88
      val file_name = workbench_css.file_name
wenzelm
parents: 75217
diff changeset
    89
      File.change_lines(dir + Path.explode("app/product.json")) { _.map(line =>
wenzelm
parents: 75217
diff changeset
    90
        if (line.containsSlice(file_name) && line.contains(checksum1)) {
wenzelm
parents: 75217
diff changeset
    91
          line.replace(checksum1, checksum2)
wenzelm
parents: 75217
diff changeset
    92
        }
wenzelm
parents: 75217
diff changeset
    93
        else line)
wenzelm
parents: 75217
diff changeset
    94
      }
wenzelm
parents: 75217
diff changeset
    95
    }
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    96
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    97
    def setup_executables(dir: Path): Unit =
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    98
    {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
    99
      val exe = vscodium_exe(dir)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   100
      Isabelle_System.make_directory(exe.dir)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   101
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   102
      platform match {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   103
        case Platform.Family.macos =>
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   104
          File.write(exe, macos_exe)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   105
          File.set_executable(exe, true)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   106
        case Platform.Family.windows =>
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   107
          val files1 = File.find_files(exe.dir.file)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   108
          val files2 = File.find_files(dir.file, pred = file =>
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   109
            {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   110
              val name = file.getName
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   111
              name.endsWith(".dll") || name.endsWith(".exe") || name.endsWith(".node")
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   112
            })
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   113
          for (file <- files1 ::: files2) File.set_executable(File.path(file), true)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   114
          Isabelle_System.bash("chmod -R o-w " + File.bash_path(dir))
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   115
        case _ =>
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   116
      }
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   117
    }
75222
wenzelm
parents: 75217
diff changeset
   118
  }
wenzelm
parents: 75217
diff changeset
   119
wenzelm
parents: 75217
diff changeset
   120
  // see https://github.com/microsoft/vscode/blob/main/build/gulpfile.vscode.js
wenzelm
parents: 75217
diff changeset
   121
  // function computeChecksum(filename)
wenzelm
parents: 75217
diff changeset
   122
  private def file_checksum(path: Path): String =
wenzelm
parents: 75217
diff changeset
   123
  {
wenzelm
parents: 75217
diff changeset
   124
    val digest = MessageDigest.getInstance("MD5")
wenzelm
parents: 75217
diff changeset
   125
    digest.update(Bytes.read(path).array)
wenzelm
parents: 75217
diff changeset
   126
    Bytes(Base64.getEncoder.encode(digest.digest()))
wenzelm
parents: 75217
diff changeset
   127
      .text.replaceAll("=", "")
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   128
  }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   129
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   130
  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
   131
    Iterator(
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   132
      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
   133
        List("OS_NAME=linux", "SKIP_LINUX_PACKAGES=True")),
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   134
      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
   135
        List("OS_NAME=linux", "SKIP_LINUX_PACKAGES=True", "VSCODE_ARCH=arm64")),
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   136
      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
   137
        List("OS_NAME=osx")),
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   138
      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
   139
        List("OS_NAME=windows",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   140
          "SHOULD_BUILD_ZIP=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   141
          "SHOULD_BUILD_EXE_SYS=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   142
          "SHOULD_BUILD_EXE_USR=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   143
          "SHOULD_BUILD_MSI=no",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   144
          "SHOULD_BUILD_MSI_NOUP=no")))
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   145
      .map(info => info.platform -> info).toMap
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   146
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   147
  def the_platform_info(platform: Platform.Family.Value): Platform_Info =
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   148
    platform_infos.getOrElse(platform, error("No platform info for " + quote(platform.toString)))
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   149
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   150
75222
wenzelm
parents: 75217
diff changeset
   151
  /* check system */
wenzelm
parents: 75217
diff changeset
   152
wenzelm
parents: 75217
diff changeset
   153
  def check_system(platforms: List[Platform.Family.Value]): Unit =
wenzelm
parents: 75217
diff changeset
   154
  {
wenzelm
parents: 75217
diff changeset
   155
    Linux.check_system()
wenzelm
parents: 75217
diff changeset
   156
wenzelm
parents: 75217
diff changeset
   157
    Isabelle_System.require_command("git")
wenzelm
parents: 75217
diff changeset
   158
    if (platforms.nonEmpty) {
wenzelm
parents: 75217
diff changeset
   159
      Isabelle_System.require_command("node")
wenzelm
parents: 75217
diff changeset
   160
      Isabelle_System.require_command("yarn")
wenzelm
parents: 75217
diff changeset
   161
      Isabelle_System.require_command("jq")
wenzelm
parents: 75217
diff changeset
   162
    }
wenzelm
parents: 75217
diff changeset
   163
    if (platforms.contains(Platform.Family.windows)) {
wenzelm
parents: 75217
diff changeset
   164
      Isabelle_System.require_command("wine")
wenzelm
parents: 75217
diff changeset
   165
    }
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   166
    if (platforms.exists(platform => the_platform_info(platform).download_zip)) {
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   167
      Isabelle_System.require_command("unzip", test = "-h")
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   168
    }
75222
wenzelm
parents: 75217
diff changeset
   169
  }
wenzelm
parents: 75217
diff changeset
   170
wenzelm
parents: 75217
diff changeset
   171
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   172
  /* build vscodium */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   173
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   174
  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
   175
75223
8c09e1f82f81 more executable files;
wenzelm
parents: 75222
diff changeset
   176
  def macos_exe: String =
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   177
"""#!/usr/bin/env bash
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   178
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   179
unset CDPATH
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   180
VSCODE_PATH="$(cd "$(dirname "$0")"/../VSCodium.app/Contents; pwd)"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   181
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   182
ELECTRON="$VSCODE_PATH/MacOS/Electron"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   183
CLI="$VSCODE_PATH/Resources/app/out/cli.js"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   184
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --ms-enable-electron-run-as-node "$@"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   185
exit $?
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   186
"""
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   187
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   188
  def build_vscodium(
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   189
    target_dir: Path = Path.current,
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   190
    platforms: List[Platform.Family.Value] = default_platforms,
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   191
    verbose: Boolean = false,
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   192
    progress: Progress = new Progress): Unit =
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   193
  {
75222
wenzelm
parents: 75217
diff changeset
   194
    check_system(platforms)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   195
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   196
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   197
    /* component */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   198
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   199
    val component_name = "vscodium-" + version
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   200
    val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component_name))
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   201
    progress.echo("Component " + component_dir)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   202
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   203
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   204
    /* build */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   205
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   206
    for (platform <- platforms) {
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   207
      val platform_info = the_platform_info(platform)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   208
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   209
      progress.echo("Building " + platform + " ...")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   210
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   211
      Isabelle_System.with_tmp_dir("vscodium")(vscodium_dir =>
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   212
      {
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   213
        def execute(lines: String*): Unit =
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   214
          progress.bash(("set -e" :: platform_info.build_environment :: lines.toList).mkString("\n"),
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   215
            cwd = vscodium_dir.file, echo = verbose).check
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   216
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   217
        execute(
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   218
          "git clone -n " + Bash.string(vscodium_repository) + " .",
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   219
          "git checkout -q " + Bash.string(version),
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   220
          "./get_repo.sh")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   221
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   222
        for (name <- Seq("vscode/build/lib/electron.js", "vscode/build/lib/electron.ts")) {
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   223
          File.change(vscodium_dir + Path.explode(name), strict = true) {
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   224
            _.replace("""'resources/darwin/' + icon + '.icns'""",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   225
              """'resources/darwin/' + icon.toLowerCase() + '.icns'""")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   226
          }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   227
        }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   228
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   229
        execute("./build.sh")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   230
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   231
        Isabelle_System.copy_file(vscodium_dir + Path.explode("LICENSE"), component_dir)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   232
75224
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   233
        val platform_dir = platform_info.platform_dir(component_dir)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   234
        Isabelle_System.copy_dir(platform_info.build_dir(vscodium_dir), platform_dir)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   235
        platform_info.patch_resources(platform_dir)
419781ac89bf misc tuning and clarification;
wenzelm
parents: 75223
diff changeset
   236
        platform_info.setup_executables(platform_dir)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   237
      })
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   238
    }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   239
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   240
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   241
    /* settings */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   242
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   243
    val etc_dir = Isabelle_System.make_directory(component_dir + Path.explode("etc"))
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   244
    File.write(etc_dir + Path.basic("settings"),
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   245
      """# -*- shell-script -*- :mode=shellscript:
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   246
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   247
ISABELLE_VSCODIUM_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   248
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   249
case "$ISABELLE_PLATFORM_FAMILY" in
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   250
  linux)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   251
    ISABELLE_ELECTRON="$ISABELLE_VSCODIUM_HOME/codium"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   252
    ;;
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   253
  macos)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   254
    ISABELLE_ELECTRON="$ISABELLE_VSCODIUM_HOME/VSCodium.app/Contents/MacOS/Electron"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   255
    ;;
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   256
  windows)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   257
    ISABELLE_ELECTRON="$ISABELLE_VSCODIUM_HOME/VSCodium.exe"
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   258
    ;;
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   259
esac
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   260
""")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   261
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   262
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   263
    /* README */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   264
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   265
    File.write(component_dir + Path.basic("README"),
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   266
      "This is VSCodium " + version + " from " + vscodium_repository +
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   267
"""
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   268
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   269
It has been built from sources using "isabelle build_vscodium": this applies
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   270
a few changes required for Isabelle/VSCode.
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   271
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   272
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   273
        Makarius
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   274
        """ + Date.Format.date(Date.now()) + "\n")
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   275
  }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   276
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   277
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   278
  /* Isabelle tool wrapper */
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   279
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   280
  val isabelle_tool =
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   281
    Isabelle_Tool("build_vscodium", "build component for VSCodium",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   282
      Scala_Project.here, args =>
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   283
    {
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   284
      var target_dir = Path.current
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   285
      var platforms = default_platforms
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   286
      var verbose = false
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   287
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   288
      val getopts = Getopts("""
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   289
Usage: vscode_setup [OPTIONS]
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   290
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   291
  Options are:
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   292
    -D DIR       target directory (default ".")
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   293
    -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
   294
    -v           verbose
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   295
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   296
  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
   297
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   298
  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
   299
  for targeting Windows.
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   300
""",
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   301
        "D:" -> (arg => target_dir = Path.explode(arg)),
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   302
        "p:" -> (arg => platforms = Library.space_explode(',', arg).map(Platform.Family.parse)),
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   303
        "v" -> (_ => verbose = true))
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   304
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   305
      val more_args = getopts(args)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   306
      if (more_args.nonEmpty) getopts.usage()
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   307
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   308
      val progress = new Console_Progress()
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   309
75217
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   310
      build_vscodium(target_dir = target_dir, platforms = platforms,
6e7b3492d7df clarified command-line options;
wenzelm
parents: 75214
diff changeset
   311
        verbose = verbose, progress = progress)
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   312
    })
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents:
diff changeset
   313
}