author | wenzelm |
Sun, 09 Apr 2023 23:09:24 +0200 | |
changeset 77799 | 3fb2c47a7605 |
parent 77566 | 2a99fcb283ee |
child 78011 | 896e255d4fc4 |
permissions | -rw-r--r-- |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77047
diff
changeset
|
1 |
/* Title: Pure/Admin/component_jdk.scala |
64929 | 2 |
Author: Makarius |
3 |
||
76534 | 4 |
Build Isabelle jdk component using downloads from Azul. |
64929 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
64933 | 10 |
import java.nio.file.Files |
64934 | 11 |
import java.nio.file.attribute.PosixFilePermission |
64933 | 12 |
|
64929 | 13 |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77047
diff
changeset
|
14 |
object Component_JDK { |
76534 | 15 |
/* platform information */ |
73081
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
16 |
|
76534 | 17 |
sealed case class JDK_Platform(name: String, url_template: String) { |
18 |
override def toString: String = name |
|
73081
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
19 |
|
76534 | 20 |
def url(base_url: String, jdk_version: String, zulu_version: String): String = |
21 |
base_url + "/" + url_template.replace("{V}", jdk_version).replace("{Z}", zulu_version) |
|
64929 | 22 |
} |
23 |
||
76534 | 24 |
val platforms: List[JDK_Platform] = |
66906 | 25 |
List( |
76534 | 26 |
JDK_Platform("arm64-darwin", "zulu{Z}-jdk{V}-macosx_aarch64.tar.gz"), |
27 |
JDK_Platform("arm64-linux", "zulu{Z}-jdk{V}-linux_aarch64.tar.gz"), |
|
28 |
JDK_Platform("x86_64-darwin", "zulu{Z}-jdk{V}-macosx_x64.tar.gz"), |
|
29 |
JDK_Platform("x86_64-linux", "zulu{Z}-jdk{V}-linux_x64.tar.gz"), |
|
30 |
JDK_Platform("x86_64-windows", "zulu{Z}-jdk{V}-win_x64.zip")) |
|
31 |
||
32 |
||
33 |
/* build jdk */ |
|
34 |
||
35 |
val default_base_url = "https://cdn.azul.com/zulu/bin" |
|
77047 | 36 |
val default_jdk_version = "17.0.6" |
37 |
val default_zulu_version = "17.40.19-ca" |
|
76534 | 38 |
|
39 |
def build_jdk( |
|
40 |
target_dir: Path = Path.current, |
|
41 |
base_url: String = default_base_url, |
|
42 |
jdk_version: String = default_jdk_version, |
|
43 |
zulu_version: String = default_zulu_version, |
|
44 |
progress: Progress = new Progress, |
|
45 |
): Unit = { |
|
76536
80dc20ffd31b
recovered check from 69139cc01ba1: Windows does not support PosixFilePermission;
wenzelm
parents:
76534
diff
changeset
|
46 |
if (Platform.is_windows) error("Cannot build on Windows") |
80dc20ffd31b
recovered check from 69139cc01ba1: Windows does not support PosixFilePermission;
wenzelm
parents:
76534
diff
changeset
|
47 |
|
80dc20ffd31b
recovered check from 69139cc01ba1: Windows does not support PosixFilePermission;
wenzelm
parents:
76534
diff
changeset
|
48 |
|
76534 | 49 |
/* component */ |
50 |
||
51 |
val component = "jdk-" + jdk_version |
|
52 |
val component_dir = |
|
76547 | 53 |
Components.Directory(target_dir + Path.basic(component)).create(progress = progress) |
64929 | 54 |
|
55 |
||
76534 | 56 |
/* download */ |
64929 | 57 |
|
76534 | 58 |
for (platform <- platforms) { |
59 |
Isabelle_System.with_tmp_dir("download", component_dir.path.file) { dir => |
|
60 |
val url = platform.url(base_url, jdk_version, zulu_version) |
|
61 |
val name = Library.take_suffix(_ != '/', url.toList)._2.mkString |
|
62 |
val file = dir + Path.basic(name) |
|
63 |
Isabelle_System.download_file(url, file, progress = progress) |
|
64929 | 64 |
|
76534 | 65 |
val platform_dir = component_dir.path + Path.basic(platform.name) |
76541 | 66 |
Isabelle_System.extract(file, platform_dir, strip = true) |
76534 | 67 |
} |
68 |
} |
|
64929 | 69 |
|
70 |
||
76534 | 71 |
/* permissions */ |
64929 | 72 |
|
76534 | 73 |
for (file <- File.find_files(component_dir.path.file, include_dirs = true)) { |
77047 | 74 |
val name = file.getName |
76534 | 75 |
val path = file.toPath |
76 |
val perms = Files.getPosixFilePermissions(path) |
|
77 |
perms.add(PosixFilePermission.OWNER_READ) |
|
78 |
perms.add(PosixFilePermission.GROUP_READ) |
|
79 |
perms.add(PosixFilePermission.OTHERS_READ) |
|
80 |
perms.add(PosixFilePermission.OWNER_WRITE) |
|
77047 | 81 |
if (File.is_dll(name) || File.is_exe(name) || file.isDirectory) { |
76534 | 82 |
perms.add(PosixFilePermission.OWNER_EXECUTE) |
83 |
perms.add(PosixFilePermission.GROUP_EXECUTE) |
|
84 |
perms.add(PosixFilePermission.OTHERS_EXECUTE) |
|
85 |
} |
|
86 |
Files.setPosixFilePermissions(path, perms) |
|
87 |
} |
|
88 |
||
89 |
||
90 |
/* settings */ |
|
91 |
||
76548 | 92 |
component_dir.write_settings(""" |
64929 | 93 |
case "$ISABELLE_PLATFORM_FAMILY" in |
94 |
linux) |
|
66906 | 95 |
ISABELLE_JAVA_PLATFORM="$ISABELLE_PLATFORM64" |
64929 | 96 |
ISABELLE_JDK_HOME="$COMPONENT/$ISABELLE_JAVA_PLATFORM" |
97 |
;; |
|
98 |
windows) |
|
66906 | 99 |
ISABELLE_JAVA_PLATFORM="$ISABELLE_WINDOWS_PLATFORM64" |
64929 | 100 |
ISABELLE_JDK_HOME="$COMPONENT/$ISABELLE_JAVA_PLATFORM" |
101 |
;; |
|
102 |
macos) |
|
73082
e67d659d7a41
more direct ISABELLE_JDK_HOME, thanks to zulu-jdk directory layout;
wenzelm
parents:
73081
diff
changeset
|
103 |
if [ -n "$ISABELLE_APPLE_PLATFORM64" -a -d "$COMPONENT/$ISABELLE_APPLE_PLATFORM64" ] |
73081
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
104 |
then |
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
105 |
ISABELLE_JAVA_PLATFORM="$ISABELLE_APPLE_PLATFORM64" |
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
106 |
else |
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
107 |
ISABELLE_JAVA_PLATFORM="$ISABELLE_PLATFORM64" |
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents:
72894
diff
changeset
|
108 |
fi |
73082
e67d659d7a41
more direct ISABELLE_JDK_HOME, thanks to zulu-jdk directory layout;
wenzelm
parents:
73081
diff
changeset
|
109 |
ISABELLE_JDK_HOME="$COMPONENT/$ISABELLE_JAVA_PLATFORM" |
64929 | 110 |
;; |
111 |
esac |
|
76534 | 112 |
""") |
64929 | 113 |
|
114 |
||
76534 | 115 |
/* README */ |
64929 | 116 |
|
76534 | 117 |
File.write(component_dir.README, |
118 |
"""This is OpenJDK """ + jdk_version + """ based on downloads by Azul, see also |
|
119 |
https://www.azul.com/downloads/?package=jdk |
|
64929 | 120 |
|
76534 | 121 |
The main license is GPL2, but some modules are covered by other (more liberal) |
122 |
licenses, see legal/* for details. |
|
64929 | 123 |
|
76534 | 124 |
Linux, Windows, macOS all work uniformly, depending on platform-specific |
125 |
subdirectories. |
|
126 |
""") |
|
64929 | 127 |
} |
128 |
||
129 |
||
130 |
/* Isabelle tool wrapper */ |
|
131 |
||
132 |
val isabelle_tool = |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77047
diff
changeset
|
133 |
Isabelle_Tool("component_jdk", "build Isabelle jdk component using downloads from Azul", |
75394 | 134 |
Scala_Project.here, |
135 |
{ args => |
|
136 |
var target_dir = Path.current |
|
76534 | 137 |
var base_url = default_base_url |
138 |
var jdk_version = default_jdk_version |
|
139 |
var zulu_version = default_zulu_version |
|
64929 | 140 |
|
75394 | 141 |
val getopts = Getopts(""" |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77047
diff
changeset
|
142 |
Usage: isabelle component_jdk [OPTIONS] |
64929 | 143 |
|
144 |
Options are: |
|
145 |
-D DIR target directory (default ".") |
|
76534 | 146 |
-U URL base URL (default: """" + default_base_url + """") |
147 |
-V NAME JDK version (default: """" + default_jdk_version + """") |
|
148 |
-Z NAME Zulu version (default: """" + default_zulu_version + """") |
|
64929 | 149 |
|
76534 | 150 |
Build Isabelle jdk component using downloads from Azul. |
64929 | 151 |
""", |
76534 | 152 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
153 |
"U:" -> (arg => base_url = arg), |
|
154 |
"V:" -> (arg => jdk_version = arg), |
|
155 |
"Z:" -> (arg => zulu_version = arg)) |
|
64929 | 156 |
|
75394 | 157 |
val more_args = getopts(args) |
76534 | 158 |
if (more_args.nonEmpty) getopts.usage() |
64929 | 159 |
|
75394 | 160 |
val progress = new Console_Progress() |
64929 | 161 |
|
76534 | 162 |
build_jdk(target_dir = target_dir, base_url = base_url, |
163 |
jdk_version = jdk_version, zulu_version = zulu_version, progress = progress) |
|
75394 | 164 |
}) |
64929 | 165 |
} |