src/Tools/VSCode/src/vscode_setup.scala
author wenzelm
Sat, 05 Mar 2022 14:31:29 +0100
changeset 75223 8c09e1f82f81
parent 75215 1129e82dc1ec
child 75224 419781ac89bf
permissions -rw-r--r--
more executable files; clarified modules;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/VSCode/src/vscode_setup.scala
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     3
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     4
Setup VSCode from VSCodium distribution.
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     5
*/
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     6
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     7
package isabelle.vscode
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     8
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
     9
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    10
import isabelle._
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    11
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    12
import java.security.MessageDigest
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    13
import java.util.Base64
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    14
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    15
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    16
object VSCode_Setup
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    17
{
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    18
  /* global resources */
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    19
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    20
  def vscode_home: Path = Path.variable("ISABELLE_VSCODE_HOME")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    21
  def vscode_settings: Path = Path.variable("ISABELLE_VSCODE_SETTINGS")
75157
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    22
  def vscode_settings_user: Path = vscode_settings + Path.explode("user-data/User/settings.json")
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    23
  def vscode_version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION")
75209
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    24
  def vscode_workspace: Path = Path.variable("ISABELLE_VSCODE_WORKSPACE")
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    25
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents: 75209
diff changeset
    26
  def vscodium_home: Path = Path.variable("ISABELLE_VSCODIUM_HOME")
75215
1129e82dc1ec more robust;
wenzelm
parents: 75214
diff changeset
    27
  def vscodium_home_ok(): Boolean =
1129e82dc1ec more robust;
wenzelm
parents: 75214
diff changeset
    28
    try { vscodium_home.is_dir }
1129e82dc1ec more robust;
wenzelm
parents: 75214
diff changeset
    29
    catch { case ERROR(_) => false }
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents: 75209
diff changeset
    30
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    31
  def exe_path(dir: Path): Path = dir + Path.explode("bin/codium")
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    32
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    33
  def vscode_installation(version: String, platform: Platform.Family.Value): (Boolean, Path) =
75156
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    34
  {
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    35
    val platform_name =
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    36
      if (platform == Platform.Family.windows) Platform.Family.native(platform)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    37
      else Platform.Family.standard(platform)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    38
    val install_dir =
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    39
      vscode_settings + Path.basic("installation") +
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    40
        Path.basic(version) + Path.basic(platform_name)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    41
    val install_ok = exe_path(install_dir).is_file
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    42
    (install_ok, install_dir)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    43
  }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    44
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    45
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    46
  /* patch resources */
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    47
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    48
  // see https://github.com/microsoft/vscode/blob/main/build/gulpfile.vscode.js
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    49
  // function computeChecksum(filename)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    50
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    51
  def file_checksum(path: Path): String =
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    52
  {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    53
    val digest = MessageDigest.getInstance("MD5")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    54
    digest.update(Bytes.read(path).array)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    55
    Bytes(Base64.getEncoder.encode(digest.digest()))
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    56
      .text.replaceAll("=", "")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    57
  }
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    58
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    59
  def patch_resources(dir: Path): Unit =
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    60
  {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    61
    HTML.init_fonts(dir + Path.explode("app/out/vs/base/browser/ui"))
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    62
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    63
    val workbench_css = dir + Path.explode("app/out/vs/workbench/workbench.desktop.main.css")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    64
    val checksum1 = file_checksum(workbench_css)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    65
    File.append(workbench_css, "\n\n" + HTML.fonts_css_dir(prefix = "../base/browser/ui"))
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    66
    val checksum2 = file_checksum(workbench_css)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    67
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    68
    val file_name = workbench_css.file_name
75205
wenzelm
parents: 75202
diff changeset
    69
    File.change_lines(dir + Path.explode("app/product.json")) { _.map(line =>
wenzelm
parents: 75202
diff changeset
    70
      if (line.containsSlice(file_name) && line.contains(checksum1)) {
wenzelm
parents: 75202
diff changeset
    71
        line.replace(checksum1, checksum2)
wenzelm
parents: 75202
diff changeset
    72
      }
wenzelm
parents: 75202
diff changeset
    73
      else line)
75202
4fdde010086f clarified signature;
wenzelm
parents: 75178
diff changeset
    74
    }
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    75
  }
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    76
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    77
75209
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    78
  /* workspace */
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    79
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    80
  def init_workspace(dir: Path): Unit =
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    81
  {
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    82
    Isabelle_System.make_directory(dir)
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    83
    Isabelle_System.chmod("700", dir)
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    84
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    85
    File.change(dir + Path.explode("symbols.json"), init = true) { _ =>
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    86
      JSON.Format(
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    87
        for (entry <- Symbol.symbols.entries; code <- entry.code)
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    88
          yield JSON.Object(
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    89
            "symbol" -> entry.symbol,
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    90
            "name" -> entry.name,
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    91
            "code" -> code,
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    92
            "abbrevs" -> entry.abbrevs
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    93
          )
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    94
      )
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    95
    }
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    96
  }
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    97
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
    98
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    99
  /* vscode setup */
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   100
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   101
  val default_download_url: String = "https://github.com/VSCodium/vscodium/releases/download"
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   102
  def default_platform: Platform.Family.Value = Platform.family
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   103
75166
wenzelm
parents: 75165
diff changeset
   104
  private val init_settings = """  {
wenzelm
parents: 75165
diff changeset
   105
    "editor.fontFamily": "'Isabelle DejaVu Sans Mono'",
wenzelm
parents: 75165
diff changeset
   106
    "editor.fontSize": 18,
wenzelm
parents: 75165
diff changeset
   107
    "editor.lineNumbers": "off",
wenzelm
parents: 75165
diff changeset
   108
    "editor.renderIndentGuides": false,
wenzelm
parents: 75165
diff changeset
   109
    "editor.rulers": [80, 100],
75171
96b26b0d2cc5 clarified rendering;
wenzelm
parents: 75167
diff changeset
   110
    "editor.unicodeHighlight.ambiguousCharacters": false,
75166
wenzelm
parents: 75165
diff changeset
   111
    "extensions.autoCheckUpdates": false,
75167
wenzelm
parents: 75166
diff changeset
   112
    "extensions.autoUpdate": false,
75178
01017b938135 proper monospace font for terminal;
wenzelm
parents: 75171
diff changeset
   113
    "terminal.integrated.fontFamily": "monospace",
75167
wenzelm
parents: 75166
diff changeset
   114
    "update.mode": "none"
75166
wenzelm
parents: 75165
diff changeset
   115
  }
wenzelm
parents: 75165
diff changeset
   116
"""
wenzelm
parents: 75165
diff changeset
   117
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   118
  def vscode_setup(
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   119
    check: Boolean = false,
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   120
    download_url: String = default_download_url,
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   121
    version: String = vscode_version,
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   122
    platform: Platform.Family.Value = default_platform,
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   123
    quiet: Boolean = false,
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   124
    fresh: Boolean = false,
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   125
    progress: Progress = new Progress): Unit =
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   126
  {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   127
    val (install_ok, install_dir) = vscode_installation(version, platform)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   128
75163
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   129
    if (!vscode_settings_user.is_file) {
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   130
      Isabelle_System.make_directory(vscode_settings_user.dir)
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   131
      File.write(vscode_settings_user, init_settings)
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   132
    }
75157
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
   133
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   134
    if (check) {
75215
1129e82dc1ec more robust;
wenzelm
parents: 75214
diff changeset
   135
      if (vscodium_home_ok()) {
75214
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents: 75209
diff changeset
   136
        init_workspace(vscode_workspace)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents: 75209
diff changeset
   137
        progress.echo(vscodium_home.expand.implode)
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents: 75209
diff changeset
   138
      }
a51a0a704854 build component for VSCodium (cross-compiled from sources for all platforms);
wenzelm
parents: 75209
diff changeset
   139
      else if (install_ok) {
75209
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
   140
        init_workspace(vscode_workspace)
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
   141
        progress.echo(install_dir.expand.implode)
4187f6f18232 provide symbols statically via ISABELLE_VSCODE_WORKSPACE, instead of LSP/PIDE protocol;
wenzelm
parents: 75205
diff changeset
   142
      }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   143
      else {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   144
        error("Bad Isabelle/VSCode installation: " + install_dir.expand +
75092
cdc2838f7536 tuned message;
wenzelm
parents: 75089
diff changeset
   145
          "\n(use \"isabelle vscode_setup\" for download and installation)")
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   146
      }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   147
    }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   148
    else {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   149
      if (install_ok) {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   150
        progress.echo_warning("Isabelle/VSCode installation already present: " + install_dir.expand)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   151
      }
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   152
      if (!install_ok || fresh) {
75166
wenzelm
parents: 75165
diff changeset
   153
        val download_name =
wenzelm
parents: 75165
diff changeset
   154
        {
wenzelm
parents: 75165
diff changeset
   155
          val a = "VSCodium"
wenzelm
parents: 75165
diff changeset
   156
          val (b, c) =
wenzelm
parents: 75165
diff changeset
   157
            platform match {
wenzelm
parents: 75165
diff changeset
   158
              case Platform.Family.linux_arm => ("linux-arm64", "tar.gz")
wenzelm
parents: 75165
diff changeset
   159
              case Platform.Family.linux => ("linux-x64", "tar.gz")
wenzelm
parents: 75165
diff changeset
   160
              case Platform.Family.macos => ("darwin-x64", "zip")
wenzelm
parents: 75165
diff changeset
   161
              case Platform.Family.windows => ("win32-x64", "zip")
wenzelm
parents: 75165
diff changeset
   162
            }
wenzelm
parents: 75165
diff changeset
   163
          a + "-" + b + "-" + version + "." + c
wenzelm
parents: 75165
diff changeset
   164
        }
wenzelm
parents: 75165
diff changeset
   165
        val is_zip = download_name.endsWith(".zip")
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   166
        if (is_zip) Isabelle_System.require_command("unzip", test = "-h")
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   167
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   168
        Isabelle_System.make_directory(install_dir)
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   169
        val exe = exe_path(install_dir)
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   170
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   171
        Isabelle_System.with_tmp_file("download")(download =>
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   172
        {
75166
wenzelm
parents: 75165
diff changeset
   173
          Isabelle_System.download_file(download_url + "/" + version + "/" + download_name,
wenzelm
parents: 75165
diff changeset
   174
            download, progress = if (quiet) new Progress else progress)
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   175
          if (!quiet) progress.echo("Installing " + install_dir.expand)
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   176
          if (is_zip) {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   177
            Isabelle_System.bash("unzip -x " + File.bash_path(download),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   178
              cwd = install_dir.file).check
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   179
          }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   180
          else {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   181
            Isabelle_System.gnutar("-xzf " + File.bash_path(download),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   182
              dir = install_dir).check
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   183
          }
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   184
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   185
          platform match {
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   186
            case Platform.Family.macos =>
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   187
              Isabelle_System.make_directory(exe.dir)
75223
8c09e1f82f81 more executable files;
wenzelm
parents: 75215
diff changeset
   188
              File.write(exe, Build_VSCodium.macos_exe)
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   189
              File.set_executable(exe, true)
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   190
            case Platform.Family.windows =>
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   191
              val files1 = File.find_files(exe.dir.file)
75223
8c09e1f82f81 more executable files;
wenzelm
parents: 75215
diff changeset
   192
              val files2 = File.find_files(install_dir.file, pred = Build_VSCodium.is_windows_exe)
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   193
              for (file <- files1 ::: files2) File.set_executable(File.path(file), true)
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   194
            case _ =>
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   195
          }
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   196
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   197
          patch_resources(
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   198
            if (platform == Platform.Family.macos) {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   199
              install_dir + Path.explode("VSCodium.app/Contents/Resources")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   200
            }
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   201
            else install_dir + Path.explode("resources"))
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   202
        })
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   203
      }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   204
    }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   205
  }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   206
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   207
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   208
  /* Isabelle tool wrapper */
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   209
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   210
  val isabelle_tool =
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   211
    Isabelle_Tool("vscode_setup", "setup VSCode from VSCodium distribution",
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   212
      Scala_Project.here, args =>
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   213
    {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   214
      var check = false
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   215
      var download_url = default_download_url
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   216
      var version = vscode_version
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   217
      var fresh = false
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   218
      var platforms = List(default_platform)
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   219
      var quiet = false
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   220
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   221
      val getopts = Getopts("""
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   222
Usage: vscode_setup [OPTIONS]
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   223
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   224
  Options are:
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   225
    -C           check and print installation directory
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   226
    -U URL       download URL
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   227
                 (default: """" + default_download_url + """")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   228
    -V VERSION   version (default: """" + vscode_version + """")
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   229
    -f           force fresh installation
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   230
    -p NAMES     platform families: comma-separated names
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   231
                 (""" + commas_quote(Platform.Family.list.map(_.toString)) + """, default: """ +
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   232
        quote(default_platform.toString) + """)
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   233
    -q           quiet mode
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   234
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   235
  Maintain local installation of VSCode, see also https://vscodium.com
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   236
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   237
  Option -C checks the existing installation (without download), and
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   238
  prints its directory location.
75163
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   239
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   240
  The following initial settings are provided for a fresh installation:
75165
19454aac373c tuned message;
wenzelm
parents: 75164
diff changeset
   241
""" + init_settings,
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   242
        "C" -> (_ => check = true),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   243
        "U:" -> (arg => download_url = arg),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   244
        "V:" -> (arg => version = arg),
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   245
        "f" -> (_ => fresh = true),
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   246
        "p:" -> (arg => platforms = Library.space_explode(',', arg).map(Platform.Family.parse)),
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   247
        "q" -> (_ => quiet = true))
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   248
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   249
      val more_args = getopts(args)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   250
      if (more_args.nonEmpty) getopts.usage()
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   251
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   252
      val progress = new Console_Progress()
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   253
      for (platform <- platforms) {
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   254
        vscode_setup(check = check, download_url = download_url, version = version,
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   255
          platform = platform, quiet = quiet, fresh = fresh, progress = progress)
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   256
      }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   257
    })
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   258
}