author | wenzelm |
Fri, 18 Feb 2022 18:52:46 +0100 | |
changeset 75099 | b5a9315578f8 |
parent 75092 | cdc2838f7536 |
child 75100 | 6eff5c260381 |
permissions | -rw-r--r-- |
75083 | 1 |
/* Title: Tools/VSCode/src/vscode_setup.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Setup VSCode from VSCodium distribution. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.vscode |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
||
13 |
object VSCode_Setup |
|
14 |
{ |
|
15 |
/* global resources */ |
|
16 |
||
17 |
def vscode_home: Path = Path.variable("ISABELLE_VSCODE_HOME") |
|
18 |
def vscode_settings: Path = Path.variable("ISABELLE_VSCODE_SETTINGS") |
|
19 |
def vscode_version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION") |
|
20 |
||
75089
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
21 |
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
|
22 |
|
75083 | 23 |
def vscode_installation(version: String, platform: Platform.Family.Value): (Boolean, Path) = |
24 |
{ |
|
25 |
val platform_name = |
|
26 |
if (platform == Platform.Family.windows) Platform.Family.native(platform) |
|
27 |
else Platform.Family.standard(platform) |
|
28 |
val install_dir = |
|
29 |
vscode_settings + Path.basic("installation") + |
|
30 |
Path.basic(version) + Path.basic(platform_name) |
|
75089
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
31 |
val install_ok = exe_path(install_dir).is_file |
75083 | 32 |
(install_ok, install_dir) |
33 |
} |
|
34 |
||
35 |
||
36 |
/* vscode setup */ |
|
37 |
||
38 |
val default_download_url: String = "https://github.com/VSCodium/vscodium/releases/download" |
|
75088 | 39 |
def default_platform: Platform.Family.Value = Platform.family |
75083 | 40 |
|
75089
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
41 |
private def macos_exe: String = |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
42 |
"""#!/usr/bin/env bash |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
43 |
|
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
44 |
unset CDPATH |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
45 |
VSCODE_PATH="$(cd "$(dirname "$0")"/../VSCodium.app/Contents; pwd)" |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
46 |
|
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
47 |
ELECTRON="$VSCODE_PATH/MacOS/Electron" |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
48 |
CLI="$VSCODE_PATH/Resources/app/out/cli.js" |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
49 |
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
|
50 |
exit $? |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
51 |
""" |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
52 |
|
75083 | 53 |
def download_name(version: String, platform: Platform.Family.Value): String = |
54 |
{ |
|
55 |
val a = "VSCodium" |
|
56 |
val (b, c) = |
|
57 |
platform match { |
|
58 |
case Platform.Family.linux_arm => ("linux-arm64", "tar.gz") |
|
59 |
case Platform.Family.linux => ("linux-x64", "tar.gz") |
|
60 |
case Platform.Family.macos => ("darwin-x64", "zip") |
|
61 |
case Platform.Family.windows => ("win32-x64", "zip") |
|
62 |
} |
|
63 |
a + "-" + b + "-" + version + "." + c |
|
64 |
} |
|
65 |
||
66 |
def vscode_setup( |
|
67 |
check: Boolean = false, |
|
68 |
download_url: String = default_download_url, |
|
69 |
version: String = vscode_version, |
|
75088 | 70 |
platform: Platform.Family.Value = default_platform, |
75099 | 71 |
quiet: Boolean = false, |
75083 | 72 |
progress: Progress = new Progress): Unit = |
73 |
{ |
|
74 |
val (install_ok, install_dir) = vscode_installation(version, platform) |
|
75 |
||
76 |
if (check) { |
|
77 |
if (install_ok) progress.echo(install_dir.expand.implode) |
|
78 |
else { |
|
79 |
error("Bad Isabelle/VSCode installation: " + install_dir.expand + |
|
75092 | 80 |
"\n(use \"isabelle vscode_setup\" for download and installation)") |
75083 | 81 |
} |
82 |
} |
|
83 |
else { |
|
84 |
if (install_ok) { |
|
85 |
progress.echo_warning("Isabelle/VSCode installation already present: " + install_dir.expand) |
|
86 |
} |
|
87 |
||
88 |
val name = download_name(version, platform) |
|
89 |
val is_zip = name.endsWith(".zip") |
|
90 |
if (is_zip) Isabelle_System.require_command("unzip", test = "-h") |
|
91 |
||
92 |
Isabelle_System.make_directory(install_dir) |
|
75089
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
93 |
val exe = exe_path(install_dir) |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
94 |
|
75083 | 95 |
Isabelle_System.with_tmp_file("download")(download => |
96 |
{ |
|
97 |
Isabelle_System.download_file(download_url + "/" + version + "/" + name, download, |
|
75099 | 98 |
progress = if (quiet) new Progress else progress) |
99 |
if (!quiet) progress.echo("Installing " + install_dir.expand) |
|
75083 | 100 |
if (is_zip) { |
101 |
Isabelle_System.bash("unzip -x " + File.bash_path(download), |
|
102 |
cwd = install_dir.file).check |
|
103 |
} |
|
104 |
else { |
|
105 |
Isabelle_System.gnutar("-xzf " + File.bash_path(download), |
|
106 |
dir = install_dir).check |
|
107 |
} |
|
75089
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
108 |
platform match { |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
109 |
case Platform.Family.macos => |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
110 |
Isabelle_System.make_directory(exe.dir) |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
111 |
File.write(exe, macos_exe) |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
112 |
File.set_executable(exe, true) |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
113 |
case Platform.Family.windows => |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
114 |
val files1 = File.find_files(exe.dir.file) |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
115 |
val files2 = |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
116 |
File.find_files(install_dir.file, |
1e230ff31fb0
provide macos_exe, based on bin/codium from linux;
wenzelm
parents:
75088
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
case _ => |
75083 | 120 |
} |
121 |
}) |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
||
126 |
/* Isabelle tool wrapper */ |
|
127 |
||
128 |
val isabelle_tool = |
|
129 |
Isabelle_Tool("vscode_setup", "setup VSCode from VSCodium distribution", |
|
130 |
Scala_Project.here, args => |
|
131 |
{ |
|
132 |
var check = false |
|
133 |
var download_url = default_download_url |
|
134 |
var version = vscode_version |
|
75088 | 135 |
var platforms = List(default_platform) |
75099 | 136 |
var quiet = false |
75083 | 137 |
|
138 |
val getopts = Getopts(""" |
|
139 |
Usage: vscode_setup [OPTIONS] |
|
140 |
||
141 |
Options are: |
|
142 |
-C check and print installation directory |
|
143 |
-U URL download URL |
|
144 |
(default: """" + default_download_url + """") |
|
145 |
-V VERSION version (default: """" + vscode_version + """") |
|
75088 | 146 |
-p NAMES platform families: comma-separated names |
147 |
(""" + commas_quote(Platform.Family.list.map(_.toString)) + """, default: """ + |
|
148 |
quote(default_platform.toString) + """) |
|
75099 | 149 |
-q quiet mode |
75083 | 150 |
|
151 |
Maintain local installation of VSCode, see also https://vscodium.com |
|
152 |
||
153 |
Option -C checks the existing installation (without download), and |
|
154 |
prints its directory location. |
|
155 |
""", |
|
156 |
"C" -> (_ => check = true), |
|
157 |
"U:" -> (arg => download_url = arg), |
|
158 |
"V:" -> (arg => version = arg), |
|
75088 | 159 |
"p:" -> (arg => platforms = Library.space_explode(',', arg).map(Platform.Family.parse)), |
75099 | 160 |
"q" -> (_ => quiet = true)) |
75083 | 161 |
|
162 |
val more_args = getopts(args) |
|
163 |
if (more_args.nonEmpty) getopts.usage() |
|
164 |
||
165 |
val progress = new Console_Progress() |
|
75088 | 166 |
for (platform <- platforms) { |
167 |
vscode_setup(check = check, download_url = download_url, version = version, |
|
75099 | 168 |
platform = platform, quiet = quiet, progress = progress) |
75088 | 169 |
} |
75083 | 170 |
}) |
171 |
} |