src/Pure/Admin/build_jdk.scala
changeset 75393 87ebf5a50283
parent 74356 2a3fe3489bae
child 75394 42267c650205
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    12 import java.nio.file.attribute.PosixFilePermission
    12 import java.nio.file.attribute.PosixFilePermission
    13 
    13 
    14 import scala.util.matching.Regex
    14 import scala.util.matching.Regex
    15 
    15 
    16 
    16 
    17 object Build_JDK
    17 object Build_JDK {
    18 {
       
    19   /* platform and version information */
    18   /* platform and version information */
    20 
    19 
    21   sealed case class JDK_Platform(
    20   sealed case class JDK_Platform(
    22     platform_name: String,
    21     platform_name: String,
    23     platform_regex: Regex,
    22     platform_regex: Regex,
    24     exe: String = "java",
    23     exe: String = "java",
    25     macos_home: Boolean = false,
    24     macos_home: Boolean = false,
    26     jdk_version: String = "")
    25     jdk_version: String = ""
    27   {
    26   ) {
    28     override def toString: String = platform_name
    27     override def toString: String = platform_name
    29 
    28 
    30     def platform_path: Path = Path.explode(platform_name)
    29     def platform_path: Path = Path.explode(platform_name)
    31 
    30 
    32     def detect(jdk_dir: Path): Option[JDK_Platform] =
    31     def detect(jdk_dir: Path): Option[JDK_Platform] = {
    33     {
    32       val major_version = {
    34       val major_version =
       
    35       {
       
    36         val Major_Version = """.*jdk(\d+).*$""".r
    33         val Major_Version = """.*jdk(\d+).*$""".r
    37         val jdk_name = jdk_dir.file.getName
    34         val jdk_name = jdk_dir.file.getName
    38         jdk_name match {
    35         jdk_name match {
    39           case Major_Version(s) => s
    36           case Major_Version(s) => s
    40           case _ => error("Cannot determine major version from " + quote(jdk_name))
    37           case _ => error("Cannot determine major version from " + quote(jdk_name))
   110 """
   107 """
   111 
   108 
   112 
   109 
   113   /* extract archive */
   110   /* extract archive */
   114 
   111 
   115   def extract_archive(dir: Path, archive: Path): JDK_Platform =
   112   def extract_archive(dir: Path, archive: Path): JDK_Platform = {
   116   {
       
   117     try {
   113     try {
   118       val tmp_dir = Isabelle_System.make_directory(dir + Path.explode("tmp"))
   114       val tmp_dir = Isabelle_System.make_directory(dir + Path.explode("tmp"))
   119 
   115 
   120       if (archive.get_ext == "zip") {
   116       if (archive.get_ext == "zip") {
   121         Isabelle_System.bash(
   117         Isabelle_System.bash(
   150   /* build jdk */
   146   /* build jdk */
   151 
   147 
   152   def build_jdk(
   148   def build_jdk(
   153     archives: List[Path],
   149     archives: List[Path],
   154     progress: Progress = new Progress,
   150     progress: Progress = new Progress,
   155     target_dir: Path = Path.current): Unit =
   151     target_dir: Path = Path.current
   156   {
   152   ): Unit = {
   157     if (Platform.is_windows) error("Cannot build jdk on Windows")
   153     if (Platform.is_windows) error("Cannot build jdk on Windows")
   158 
   154 
   159     Isabelle_System.with_tmp_dir("jdk")(dir =>
   155     Isabelle_System.with_tmp_dir("jdk")(dir => {
   160       {
       
   161         progress.echo("Extracting ...")
   156         progress.echo("Extracting ...")
   162         val platforms = archives.map(extract_archive(dir, _))
   157         val platforms = archives.map(extract_archive(dir, _))
   163 
   158 
   164         val jdk_version =
   159         val jdk_version =
   165           platforms.map(_.jdk_version).distinct match {
   160           platforms.map(_.jdk_version).distinct match {
   212 
   207 
   213   /* Isabelle tool wrapper */
   208   /* Isabelle tool wrapper */
   214 
   209 
   215   val isabelle_tool =
   210   val isabelle_tool =
   216     Isabelle_Tool("build_jdk", "build Isabelle jdk component from original archives",
   211     Isabelle_Tool("build_jdk", "build Isabelle jdk component from original archives",
   217       Scala_Project.here, args =>
   212       Scala_Project.here, args => {
   218     {
       
   219       var target_dir = Path.current
   213       var target_dir = Path.current
   220 
   214 
   221       val getopts = Getopts("""
   215       val getopts = Getopts("""
   222 Usage: isabelle build_jdk [OPTIONS] ARCHIVES...
   216 Usage: isabelle build_jdk [OPTIONS] ARCHIVES...
   223 
   217