| author | wenzelm | 
| Thu, 29 Dec 2022 12:27:55 +0100 | |
| changeset 76811 | 56d76e8cecf4 | 
| parent 76548 | 0af64cc2eee9 | 
| child 77047 | 39f8051f71d4 | 
| permissions | -rw-r--r-- | 
| 64929 | 1 | /* Title: Pure/Admin/build_jdk.scala | 
| 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 | |
| 75393 | 14 | object Build_JDK {
 | 
| 76534 | 15 | /* platform information */ | 
| 73081 
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
 wenzelm parents: 
72894diff
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: 
72894diff
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" | |
| 36 | val default_jdk_version = "17.0.5" | |
| 37 | val default_zulu_version = "17.38.21-ca" | |
| 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: 
76534diff
changeset | 46 |     if (Platform.is_windows) error("Cannot build on Windows")
 | 
| 
80dc20ffd31b
recovered check from 69139cc01ba1: Windows does not support PosixFilePermission;
 wenzelm parents: 
76534diff
changeset | 47 | |
| 
80dc20ffd31b
recovered check from 69139cc01ba1: Windows does not support PosixFilePermission;
 wenzelm parents: 
76534diff
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)) {
 | 
| 74 | val path = file.toPath | |
| 75 | val perms = Files.getPosixFilePermissions(path) | |
| 76 | perms.add(PosixFilePermission.OWNER_READ) | |
| 77 | perms.add(PosixFilePermission.GROUP_READ) | |
| 78 | perms.add(PosixFilePermission.OTHERS_READ) | |
| 79 | perms.add(PosixFilePermission.OWNER_WRITE) | |
| 80 |       if (file.isDirectory) {
 | |
| 81 | perms.add(PosixFilePermission.OWNER_WRITE) | |
| 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: 
73081diff
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: 
72894diff
changeset | 104 | then | 
| 
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
 wenzelm parents: 
72894diff
changeset | 105 | ISABELLE_JAVA_PLATFORM="$ISABELLE_APPLE_PLATFORM64" | 
| 
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
 wenzelm parents: 
72894diff
changeset | 106 | else | 
| 
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
 wenzelm parents: 
72894diff
changeset | 107 | ISABELLE_JAVA_PLATFORM="$ISABELLE_PLATFORM64" | 
| 
120ffea2c244
prefer OpenJDK from Azul: supports more versions and platforms;
 wenzelm parents: 
72894diff
changeset | 108 | fi | 
| 73082 
e67d659d7a41
more direct ISABELLE_JDK_HOME, thanks to zulu-jdk directory layout;
 wenzelm parents: 
73081diff
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 = | |
| 76534 | 133 |     Isabelle_Tool("build_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("""
 | 
| 76534 | 142 | Usage: isabelle build_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 | } |