author | wenzelm |
Wed, 02 Oct 2024 11:27:19 +0200 | |
changeset 81100 | 6ae3d0b2b8ad |
parent 80181 | aa92c0f96036 |
child 81295 | 66c253421be4 |
permissions | -rw-r--r-- |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77369
diff
changeset
|
1 |
/* Title: Pure/Admin/component_scala.scala |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
3 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
4 |
Build Isabelle Scala component from official downloads. |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
5 |
*/ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
6 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
8 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
9 |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77369
diff
changeset
|
10 |
object Component_Scala { |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
11 |
/* downloads */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
12 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
13 |
sealed case class Download( |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
14 |
name: String, |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
15 |
version: String, |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
16 |
url: String, |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
17 |
physical_url: String = "", |
75393 | 18 |
base_version: String = "3" |
19 |
) { |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
20 |
def make_url(template: String): String = |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
21 |
template.replace("{V}", version).replace("{B}", base_version) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
22 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
23 |
def proper_url: String = make_url(proper_string(physical_url).getOrElse(url)) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
24 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
25 |
def artifact: String = |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
26 |
Library.take_suffix[Char](_ != '/', proper_url.toList)._2.mkString |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
27 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
28 |
def get(path: Path, progress: Progress = new Progress): Unit = |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
29 |
Isabelle_System.download_file(proper_url, path, progress = progress) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
30 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
31 |
def print: String = |
77369 | 32 |
" * " + name + " " + version + if_proper(base_version, " for Scala " + base_version) + |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
33 |
":\n " + make_url(url) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
34 |
} |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
35 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
36 |
val main_download: Download = |
80181
aa92c0f96036
provide scala-3.4.2, but do not activate it: scala-3.3.x is LTS version;
wenzelm
parents:
80063
diff
changeset
|
37 |
Download("scala", "3.4.2", base_version = "", |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
38 |
url = "https://github.com/lampepfl/dotty/releases/download/{V}/scala3-{V}.tar.gz") |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
39 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
40 |
val lib_downloads: List[Download] = List( |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
41 |
Download("scala-parallel-collections", "1.0.4", |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
42 |
"https://mvnrepository.com/artifact/org.scala-lang.modules/scala-parallel-collections_{B}/{V}", |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
43 |
physical_url = "https://repo1.maven.org/maven2/org/scala-lang/modules/scala-parallel-collections_{B}/{V}/scala-parallel-collections_{B}-{V}.jar"), |
78125 | 44 |
Download("scala-parser-combinators", "2.3.0", |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
45 |
"https://mvnrepository.com/artifact/org.scala-lang.modules/scala-parser-combinators_{B}/{V}", |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
46 |
physical_url = "https://repo1.maven.org/maven2/org/scala-lang/modules/scala-parser-combinators_{B}/{V}/scala-parser-combinators_{B}-{V}.jar"), |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
47 |
Download("scala-swing", "3.0.0", |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
48 |
"https://mvnrepository.com/artifact/org.scala-lang.modules/scala-swing_{B}/{V}", |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
49 |
physical_url = "https://repo1.maven.org/maven2/org/scala-lang/modules/scala-swing_{B}/{V}/scala-swing_{B}-{V}.jar"), |
79753 | 50 |
Download("scala-xml", "2.2.0", |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
51 |
"https://mvnrepository.com/artifact/org.scala-lang.modules/scala-xml_{B}/{V}", |
75421
3c710067b178
back to more ambitious scala-3.1.1 (see 8b7497992301);
wenzelm
parents:
75394
diff
changeset
|
52 |
physical_url = "https://repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_{B}/{V}/scala-xml_{B}-{V}.jar") |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
53 |
) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
54 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
55 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
56 |
/* build Scala component */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
57 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
58 |
def build_scala( |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
59 |
target_dir: Path = Path.current, |
75393 | 60 |
progress: Progress = new Progress |
61 |
): Unit = { |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
62 |
/* component */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
63 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
64 |
val component_name = main_download.name + "-" + main_download.version |
76518 | 65 |
val component_dir = |
76547 | 66 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
67 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
68 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
69 |
/* download */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
70 |
|
76542 | 71 |
Isabelle_System.with_tmp_file("archive", ext = "tar.gz") { archive_path => |
72 |
main_download.get(archive_path, progress = progress) |
|
73 |
Isabelle_System.extract(archive_path, component_dir.path, strip = true) |
|
74 |
} |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
75 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
76 |
lib_downloads.foreach(download => |
76518 | 77 |
download.get(component_dir.lib + Path.basic(download.artifact), progress = progress)) |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
78 |
|
76518 | 79 |
File.write(component_dir.LICENSE, |
76662 | 80 |
Url.read("https://www.apache.org/licenses/LICENSE-2.0.txt")) |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
81 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
82 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
83 |
/* classpath */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
84 |
|
75393 | 85 |
val classpath: List[String] = { |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
86 |
def no_function(name: String): String = "function " + name + "() {\n:\n}" |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
87 |
val script = |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
88 |
cat_lines(List( |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
89 |
no_function("stty"), |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
90 |
no_function("tput"), |
76518 | 91 |
"PROG_HOME=" + File.bash_path(component_dir.path), |
92 |
File.read(component_dir.path + Path.explode("bin/common")) |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
93 |
.replace("scala_exit_status=127", "scala_exit_status=0"), |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
94 |
"compilerJavaClasspathArgs", |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
95 |
"echo \"$jvm_cp_args\"")) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
96 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
97 |
val main_classpath = Path.split(Isabelle_System.bash(script).check.out).map(_.file_name) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
98 |
val lib_classpath = lib_downloads.map(_.artifact) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
99 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
100 |
main_classpath ::: lib_classpath |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
101 |
} |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
102 |
|
75378 | 103 |
val interfaces = |
104 |
classpath.find(_.startsWith("scala3-interfaces")) |
|
105 |
.getOrElse(error("Missing jar for scala3-interfaces")) |
|
106 |
||
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
107 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
108 |
/* settings */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
109 |
|
76548 | 110 |
component_dir.write_settings(""" |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
111 |
SCALA_HOME="$COMPONENT" |
75378 | 112 |
SCALA_INTERFACES="$SCALA_HOME/lib/""" + interfaces + """" |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
113 |
""" + terminate_lines(classpath.map(jar => "classpath \"$SCALA_HOME/lib/" + jar + "\""))) |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
114 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
115 |
|
76327 | 116 |
/* adhoc changes */ |
117 |
||
118 |
val patched_scripts = List("bin/scala", "bin/scalac") |
|
119 |
for (name <- patched_scripts) { |
|
76518 | 120 |
File.change(component_dir.path + Path.explode(name)) { |
76327 | 121 |
_.replace(""""-Dscala.home=$PROG_HOME"""", """"-Dscala.home=\"$PROG_HOME\""""") |
122 |
} |
|
123 |
} |
|
124 |
||
125 |
||
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
126 |
/* README */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
127 |
|
76518 | 128 |
File.write(component_dir.README, |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
129 |
"This distribution of Scala integrates the following parts:\n\n" + |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
130 |
(main_download :: lib_downloads).map(_.print).mkString("\n\n") + """ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
131 |
|
76327 | 132 |
Minor changes to """ + patched_scripts.mkString(" and ") + """ allow an installation location |
133 |
with spaces in the directory name. |
|
134 |
||
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
135 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
136 |
Makarius |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
137 |
""" + Date.Format.date(Date.now()) + "\n") |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
138 |
} |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
139 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
140 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
141 |
/* Isabelle tool wrapper */ |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
142 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
143 |
val isabelle_tool = |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77369
diff
changeset
|
144 |
Isabelle_Tool("component_scala", "build Isabelle Scala component from official downloads", |
75394 | 145 |
Scala_Project.here, |
146 |
{ args => |
|
147 |
var target_dir = Path.current |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
148 |
|
75394 | 149 |
val getopts = Getopts(""" |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77369
diff
changeset
|
150 |
Usage: isabelle component_scala [OPTIONS] |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
151 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
152 |
Options are: |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
153 |
-D DIR target directory (default ".") |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
154 |
|
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
155 |
Build Isabelle Scala component from official downloads. |
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
156 |
""", |
75394 | 157 |
"D:" -> (arg => target_dir = Path.explode(arg))) |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
158 |
|
75394 | 159 |
val more_args = getopts(args) |
160 |
if (more_args.nonEmpty) getopts.usage() |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
161 |
|
75394 | 162 |
val progress = new Console_Progress() |
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
163 |
|
75394 | 164 |
build_scala(target_dir = target_dir, progress = progress) |
165 |
}) |
|
75377
4ce7d95612cb
build Isabelle Scala component from official downloads (for scala-3.1.1);
wenzelm
parents:
diff
changeset
|
166 |
} |