src/Pure/Admin/component_jdk.scala
author Fabian Huch <huch@in.tum.de>
Thu, 06 Jun 2024 13:37:27 +0200
changeset 80260 ed9b1598d293
parent 80131 68fc6839679e
permissions -rw-r--r--
manage components of ci builds;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     3
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
     4
Build Isabelle jdk component using downloads from Azul.
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     5
*/
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     6
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     7
package isabelle
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     8
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
     9
64933
wenzelm
parents: 64931
diff changeset
    10
import java.nio.file.Files
64934
795055a0be98 hardlink within JVM;
wenzelm
parents: 64933
diff changeset
    11
import java.nio.file.attribute.PosixFilePermission
64933
wenzelm
parents: 64931
diff changeset
    12
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    13
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 77047
diff changeset
    14
object Component_JDK {
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    15
  /* platform information */
73081
120ffea2c244 prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents: 72894
diff changeset
    16
78300
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    17
  sealed case class Download_Platform(name: String, url_template: String) {
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    18
    override def toString: String = name
73081
120ffea2c244 prefer OpenJDK from Azul: supports more versions and platforms;
wenzelm
parents: 72894
diff changeset
    19
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    20
    def url(base_url: String, jdk_version: String, zulu_version: String): String =
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    21
      base_url + "/" + url_template.replace("{V}", jdk_version).replace("{Z}", zulu_version)
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    22
  }
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    23
78300
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    24
  val platforms: List[Download_Platform] =
66906
03a96b8c7c06 updated to jdk-8u152, which is for x86_64 only;
wenzelm
parents: 65879
diff changeset
    25
    List(
78300
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    26
      Download_Platform("arm64-darwin", "zulu{Z}-jdk{V}-macosx_aarch64.tar.gz"),
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    27
      Download_Platform("arm64-linux", "zulu{Z}-jdk{V}-linux_aarch64.tar.gz"),
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    28
      Download_Platform("x86_64-darwin", "zulu{Z}-jdk{V}-macosx_x64.tar.gz"),
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    29
      Download_Platform("x86_64-linux", "zulu{Z}-jdk{V}-linux_x64.tar.gz"),
ab95c9f2d55c tuned signature;
wenzelm
parents: 78011
diff changeset
    30
      Download_Platform("x86_64-windows", "zulu{Z}-jdk{V}-win_x64.zip"))
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    31
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    32
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    33
  /* build jdk */
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    34
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    35
  val default_base_url = "https://cdn.azul.com/zulu/bin"
80131
68fc6839679e update to jdk-21.0.3;
wenzelm
parents: 79556
diff changeset
    36
  val default_jdk_version = "21.0.3"
68fc6839679e update to jdk-21.0.3;
wenzelm
parents: 79556
diff changeset
    37
  val default_zulu_version = "21.34.19-ca"
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    38
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    39
  def build_jdk(
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    40
    target_dir: Path = Path.current,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    41
    base_url: String = default_base_url,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    42
    jdk_version: String = default_jdk_version,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    43
    zulu_version: String = default_zulu_version,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    44
    progress: Progress = new Progress,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    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
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    49
    /* component */
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    50
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    51
    val component = "jdk-" + jdk_version
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    52
    val component_dir =
76547
9fe5d8c70352 tuned signature;
wenzelm
parents: 76541
diff changeset
    53
      Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    54
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    55
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    56
    /* download */
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    57
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    58
    for (platform <- platforms) {
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    59
      Isabelle_System.with_tmp_dir("download", component_dir.path.file) { dir =>
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    60
        val url = platform.url(base_url, jdk_version, zulu_version)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    61
        val name = Library.take_suffix(_ != '/', url.toList)._2.mkString
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    62
        val file = dir + Path.basic(name)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    63
        Isabelle_System.download_file(url, file, progress = progress)
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    64
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    65
        val platform_dir = component_dir.path + Path.basic(platform.name)
76541
3706b88035d2 more direct target directory;
wenzelm
parents: 76536
diff changeset
    66
        Isabelle_System.extract(file, platform_dir, strip = true)
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    67
      }
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    68
    }
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    69
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    70
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    71
    /* permissions */
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    72
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    73
    for (file <- File.find_files(component_dir.path.file, include_dirs = true)) {
77047
39f8051f71d4 update to jdk-17.0.6;
wenzelm
parents: 76548
diff changeset
    74
      val name = file.getName
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    75
      val path = file.toPath
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    76
      val perms = Files.getPosixFilePermissions(path)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    77
      perms.add(PosixFilePermission.OWNER_READ)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    78
      perms.add(PosixFilePermission.GROUP_READ)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    79
      perms.add(PosixFilePermission.OTHERS_READ)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    80
      perms.add(PosixFilePermission.OWNER_WRITE)
77047
39f8051f71d4 update to jdk-17.0.6;
wenzelm
parents: 76548
diff changeset
    81
      if (File.is_dll(name) || File.is_exe(name) || file.isDirectory) {
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    82
        perms.add(PosixFilePermission.OWNER_EXECUTE)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    83
        perms.add(PosixFilePermission.GROUP_EXECUTE)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    84
        perms.add(PosixFilePermission.OTHERS_EXECUTE)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    85
      }
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    86
      Files.setPosixFilePermissions(path, perms)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    87
    }
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    88
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    89
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    90
    /* settings */
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
    91
76548
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
    92
    component_dir.write_settings("""
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    93
case "$ISABELLE_PLATFORM_FAMILY" in
79556
0631dfc0db07 more robust check of ISABELLE_PLATFORM_FAMILY within settings environment, to support its reunification with Isabelle/Scala (see also a33a6e541cbb, f3a356c64193);
wenzelm
parents: 79528
diff changeset
    94
  linux*)
66906
03a96b8c7c06 updated to jdk-8u152, which is for x86_64 only;
wenzelm
parents: 65879
diff changeset
    95
    ISABELLE_JAVA_PLATFORM="$ISABELLE_PLATFORM64"
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    96
    ISABELLE_JDK_HOME="$COMPONENT/$ISABELLE_JAVA_PLATFORM"
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
    97
    ;;
79556
0631dfc0db07 more robust check of ISABELLE_PLATFORM_FAMILY within settings environment, to support its reunification with Isabelle/Scala (see also a33a6e541cbb, f3a356c64193);
wenzelm
parents: 79528
diff changeset
    98
  windows*)
66906
03a96b8c7c06 updated to jdk-8u152, which is for x86_64 only;
wenzelm
parents: 65879
diff changeset
    99
    ISABELLE_JAVA_PLATFORM="$ISABELLE_WINDOWS_PLATFORM64"
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   100
    ISABELLE_JDK_HOME="$COMPONENT/$ISABELLE_JAVA_PLATFORM"
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   101
    ;;
79556
0631dfc0db07 more robust check of ISABELLE_PLATFORM_FAMILY within settings environment, to support its reunification with Isabelle/Scala (see also a33a6e541cbb, f3a356c64193);
wenzelm
parents: 79528
diff changeset
   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
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   110
    ;;
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   111
esac
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   112
""")
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   113
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   114
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   115
    /* README */
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   116
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   117
    File.write(component_dir.README,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   118
      """This is OpenJDK """ + jdk_version + """ based on downloads by Azul, see also
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   119
https://www.azul.com/downloads/?package=jdk
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   120
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   121
The main license is GPL2, but some modules are covered by other (more liberal)
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   122
licenses, see legal/* for details.
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   123
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   124
Linux, Windows, macOS all work uniformly, depending on platform-specific
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   125
subdirectories.
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   126
""")
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   127
  }
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   128
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   129
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   130
  /* Isabelle tool wrapper */
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   131
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   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
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   134
      Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   135
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   136
        var target_dir = Path.current
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   137
        var base_url = default_base_url
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   138
        var jdk_version = default_jdk_version
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   139
        var zulu_version = default_zulu_version
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   140
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   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
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   143
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   144
  Options are:
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   145
    -D DIR       target directory (default ".")
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   146
    -U URL       base URL (default: """" + default_base_url + """")
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   147
    -V NAME      JDK version (default: """" + default_jdk_version + """")
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   148
    -Z NAME      Zulu version (default: """" + default_zulu_version + """")
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   149
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   150
  Build Isabelle jdk component using downloads from Azul.
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   151
""",
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   152
          "D:" -> (arg => target_dir = Path.explode(arg)),
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   153
          "U:" -> (arg => base_url = arg),
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   154
          "V:" -> (arg => jdk_version = arg),
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   155
          "Z:" -> (arg => zulu_version = arg))
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   156
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   157
        val more_args = getopts(args)
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   158
        if (more_args.nonEmpty) getopts.usage()
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   159
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   160
        val progress = new Console_Progress()
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   161
76534
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   162
        build_jdk(target_dir = target_dir, base_url = base_url,
69139cc01ba1 more standard component build process;
wenzelm
parents: 76530
diff changeset
   163
          jdk_version = jdk_version, zulu_version = zulu_version, progress = progress)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   164
      })
64929
3b4e5fad4dc2 build_jdk in Scala;
wenzelm
parents:
diff changeset
   165
}