src/Tools/VSCode/src/vscode_setup.scala
author wenzelm
Mon, 28 Feb 2022 12:51:27 +0100
changeset 75163 c440b77c79c0
parent 75162 4fc51c9cf8fd
child 75164 837bcbe60837
permissions -rw-r--r--
tuned message;
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")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    24
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    25
  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
    26
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    27
  def vscode_installation(version: String, platform: Platform.Family.Value): (Boolean, Path) =
75156
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    28
  {
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    29
    val platform_name =
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    30
      if (platform == Platform.Family.windows) Platform.Family.native(platform)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    31
      else Platform.Family.standard(platform)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    32
    val install_dir =
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    33
      vscode_settings + Path.basic("installation") +
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    34
        Path.basic(version) + Path.basic(platform_name)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    35
    val install_ok = exe_path(install_dir).is_file
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    36
    (install_ok, install_dir)
09da7b15162b tuned whitespace;
wenzelm
parents: 75155
diff changeset
    37
  }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    38
75163
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
    39
  val init_settings = """{
75157
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    40
  "editor.fontFamily": "'Isabelle DejaVu Sans Mono'",
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    41
  "editor.fontSize": 18,
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    42
  "editor.lineNumbers": "off",
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    43
  "editor.renderIndentGuides": false,
75162
4fc51c9cf8fd disable check for updates: support just one static version;
wenzelm
parents: 75159
diff changeset
    44
  "editor.rulers": [80, 100],
4fc51c9cf8fd disable check for updates: support just one static version;
wenzelm
parents: 75159
diff changeset
    45
  "update.mode": "none"
75157
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    46
}
75163
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
    47
"""
75157
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
    48
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    49
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    50
  /* patch resources */
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    51
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    52
  // 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
    53
  // function computeChecksum(filename)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    54
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    55
  def file_checksum(path: Path): String =
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    56
  {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    57
    val digest = MessageDigest.getInstance("MD5")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    58
    digest.update(Bytes.read(path).array)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    59
    Bytes(Base64.getEncoder.encode(digest.digest()))
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    60
      .text.replaceAll("=", "")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    61
  }
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
  def patch_resources(dir: Path): Unit =
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    64
  {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    65
    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
    66
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    67
    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
    68
    val checksum1 = file_checksum(workbench_css)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    69
    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
    70
    val checksum2 = file_checksum(workbench_css)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    71
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    72
    val file_name = workbench_css.file_name
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    73
    File.change(dir + Path.explode("app/product.json"), text =>
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    74
      cat_lines(split_lines(text).map(line =>
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    75
        if (line.containsSlice(file_name) && line.contains(checksum1)) {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    76
          line.replace(checksum1, checksum2)
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    77
        }
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    78
        else line
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    79
      )))
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    80
  }
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    81
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
    82
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    83
  /* vscode setup */
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    84
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    85
  val default_download_url: String = "https://github.com/VSCodium/vscodium/releases/download"
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
    86
  def default_platform: Platform.Family.Value = Platform.family
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
    87
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    88
  private def macos_exe: String =
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    89
"""#!/usr/bin/env bash
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    90
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    91
unset CDPATH
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    92
VSCODE_PATH="$(cd "$(dirname "$0")"/../VSCodium.app/Contents; pwd)"
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    93
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    94
ELECTRON="$VSCODE_PATH/MacOS/Electron"
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    95
CLI="$VSCODE_PATH/Resources/app/out/cli.js"
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    96
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --ms-enable-electron-run-as-node "$@"
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    97
exit $?
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    98
"""
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
    99
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   100
  def download_name(version: String, platform: Platform.Family.Value): String =
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   101
  {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   102
    val a = "VSCodium"
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   103
    val (b, c) =
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   104
      platform match {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   105
        case Platform.Family.linux_arm => ("linux-arm64", "tar.gz")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   106
        case Platform.Family.linux => ("linux-x64", "tar.gz")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   107
        case Platform.Family.macos => ("darwin-x64", "zip")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   108
        case Platform.Family.windows => ("win32-x64", "zip")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   109
      }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   110
    a + "-" + b + "-" + version + "." + c
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   111
  }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   112
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   113
  def vscode_setup(
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   114
    check: Boolean = false,
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   115
    download_url: String = default_download_url,
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   116
    version: String = vscode_version,
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   117
    platform: Platform.Family.Value = default_platform,
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   118
    quiet: Boolean = false,
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   119
    fresh: Boolean = false,
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   120
    progress: Progress = new Progress): Unit =
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   121
  {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   122
    val (install_ok, install_dir) = vscode_installation(version, platform)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   123
75163
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   124
    if (!vscode_settings_user.is_file) {
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   125
      Isabelle_System.make_directory(vscode_settings_user.dir)
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   126
      File.write(vscode_settings_user, init_settings)
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   127
    }
75157
d67ec542b5b5 clarified default settings;
wenzelm
parents: 75156
diff changeset
   128
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   129
    if (check) {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   130
      if (install_ok) progress.echo(install_dir.expand.implode)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   131
      else {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   132
        error("Bad Isabelle/VSCode installation: " + install_dir.expand +
75092
cdc2838f7536 tuned message;
wenzelm
parents: 75089
diff changeset
   133
          "\n(use \"isabelle vscode_setup\" for download and installation)")
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   134
      }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   135
    }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   136
    else {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   137
      if (install_ok) {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   138
        progress.echo_warning("Isabelle/VSCode installation already present: " + install_dir.expand)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   139
      }
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   140
      if (!install_ok || fresh) {
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   141
        val name = download_name(version, platform)
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   142
        val is_zip = name.endsWith(".zip")
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   143
        if (is_zip) Isabelle_System.require_command("unzip", test = "-h")
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   144
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   145
        Isabelle_System.make_directory(install_dir)
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   146
        val exe = exe_path(install_dir)
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   147
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   148
        Isabelle_System.with_tmp_file("download")(download =>
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   149
        {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   150
          Isabelle_System.download_file(download_url + "/" + version + "/" + name, download,
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   151
            progress = if (quiet) new Progress else progress)
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   152
          if (!quiet) progress.echo("Installing " + install_dir.expand)
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   153
          if (is_zip) {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   154
            Isabelle_System.bash("unzip -x " + File.bash_path(download),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   155
              cwd = install_dir.file).check
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   156
          }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   157
          else {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   158
            Isabelle_System.gnutar("-xzf " + File.bash_path(download),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   159
              dir = install_dir).check
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   160
          }
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   161
75089
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   162
          platform match {
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   163
            case Platform.Family.macos =>
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   164
              Isabelle_System.make_directory(exe.dir)
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   165
              File.write(exe, macos_exe)
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   166
              File.set_executable(exe, true)
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   167
            case Platform.Family.windows =>
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   168
              val files1 = File.find_files(exe.dir.file)
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   169
              val files2 =
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   170
                File.find_files(install_dir.file,
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   171
                  pred = file => file.getName.endsWith(".exe") || file.getName.endsWith(".dll"))
1e230ff31fb0 provide macos_exe, based on bin/codium from linux;
wenzelm
parents: 75088
diff changeset
   172
              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
   173
            case _ =>
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   174
          }
75155
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   175
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   176
          patch_resources(
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   177
            if (platform == Platform.Family.macos) {
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   178
              install_dir + Path.explode("VSCodium.app/Contents/Resources")
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   179
            }
0b6c43a87fa6 support Isabelle fonts via patch of vscode resources;
wenzelm
parents: 75100
diff changeset
   180
            else install_dir + Path.explode("resources"))
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   181
        })
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   182
      }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   183
    }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   184
  }
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   185
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   186
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   187
  /* Isabelle tool wrapper */
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   188
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   189
  val isabelle_tool =
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   190
    Isabelle_Tool("vscode_setup", "setup VSCode from VSCodium distribution",
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   191
      Scala_Project.here, args =>
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   192
    {
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   193
      var check = false
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   194
      var download_url = default_download_url
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   195
      var version = vscode_version
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   196
      var fresh = false
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   197
      var platforms = List(default_platform)
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   198
      var quiet = false
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   199
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   200
      val getopts = Getopts("""
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   201
Usage: vscode_setup [OPTIONS]
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   202
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   203
  Options are:
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   204
    -C           check and print installation directory
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   205
    -U URL       download URL
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   206
                 (default: """" + default_download_url + """")
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   207
    -V VERSION   version (default: """" + vscode_version + """")
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   208
    -f           force fresh installation
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   209
    -p NAMES     platform families: comma-separated names
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   210
                 (""" + commas_quote(Platform.Family.list.map(_.toString)) + """, default: """ +
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   211
        quote(default_platform.toString) + """)
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   212
    -q           quiet mode
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   213
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   214
  Maintain local installation of VSCode, see also https://vscodium.com
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   215
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   216
  Option -C checks the existing installation (without download), and
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   217
  prints its directory location.
75163
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   218
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   219
  The following initial settings are provided for a fresh installation:
c440b77c79c0 tuned message;
wenzelm
parents: 75162
diff changeset
   220
""" + cat_lines(split_lines(init_settings).map(s => "  " + s)) + "\n",
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   221
        "C" -> (_ => check = true),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   222
        "U:" -> (arg => download_url = arg),
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   223
        "V:" -> (arg => version = arg),
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   224
        "f" -> (_ => fresh = true),
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   225
        "p:" -> (arg => platforms = Library.space_explode(',', arg).map(Platform.Family.parse)),
75099
b5a9315578f8 clarified options;
wenzelm
parents: 75092
diff changeset
   226
        "q" -> (_ => quiet = true))
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   227
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   228
      val more_args = getopts(args)
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   229
      if (more_args.nonEmpty) getopts.usage()
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   230
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   231
      val progress = new Console_Progress()
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   232
      for (platform <- platforms) {
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   233
        vscode_setup(check = check, download_url = download_url, version = version,
75100
6eff5c260381 clarified options;
wenzelm
parents: 75099
diff changeset
   234
          platform = platform, quiet = quiet, fresh = fresh, progress = progress)
75088
32ebb38154e7 clarified options;
wenzelm
parents: 75083
diff changeset
   235
      }
75083
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   236
    })
35a5c4b16024 setup VSCode from VSCodium distribution;
wenzelm
parents:
diff changeset
   237
}