src/Pure/Admin/component_cygwin.scala
author wenzelm
Tue, 07 Mar 2023 22:54:44 +0100
changeset 77566 2a99fcb283ee
parent 76553 src/Pure/Admin/build_cygwin.scala@120f79cdb492
child 77717 6a2daddc238c
permissions -rw-r--r--
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
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: 76553
diff changeset
     1
/*  Title:      Pure/Admin/component_cygwin.scala
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     3
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     4
Produce pre-canned Cygwin distribution for Isabelle.
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     5
*/
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     6
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     7
package isabelle
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     8
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
     9
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76553
diff changeset
    10
object Component_Cygwin {
76028
105867f98630 updated to current Cygwin, near 3.3.5-1;
wenzelm
parents: 75468
diff changeset
    11
  val default_mirror: String = "https://isabelle.sketis.net/cygwin_2022"
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    12
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    13
  val packages: List[String] =
76553
120f79cdb492 discontinued "unzip" executable (see also eb96243a25c5 and 662de910a96b);
wenzelm
parents: 76526
diff changeset
    14
    List("curl", "libgmp-devel", "nano", "openssh", "rsync")
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    15
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    16
  def build_cygwin(
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    17
    target_dir: Path = Path.current,
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    18
    mirror: String = default_mirror,
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    19
    more_packages: List[String] = Nil,
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    20
    progress: Progress = new Progress
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74491
diff changeset
    21
  ): Unit = {
73120
c3589f2dff31 more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents: 72763
diff changeset
    22
    require(Platform.is_windows, "Windows platform expected")
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    23
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    24
    Isabelle_System.with_tmp_dir("cygwin") { tmp_dir =>
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    25
        val cygwin = tmp_dir + Path.explode("cygwin")
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    26
        val cygwin_etc = cygwin + Path.explode("etc")
72376
04bce3478688 clarified signature;
wenzelm
parents: 72375
diff changeset
    27
        val cygwin_isabelle = Isabelle_System.make_directory(cygwin + Path.explode("isabelle"))
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    28
66727
56b92ce30d87 updated to x86_64-cygwin;
wenzelm
parents: 66529
diff changeset
    29
        val cygwin_exe_name = mirror + "/setup-x86_64.exe"
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    30
        val cygwin_exe = cygwin_isabelle + Path.explode("cygwin.exe")
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    31
        Bytes.write(cygwin_exe,
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    32
          try { Bytes.read(Url(cygwin_exe_name)) }
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    33
          catch { case ERROR(_) => error("Failed to download " + quote(cygwin_exe_name)) })
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    34
68374
8740e1241555 updated to current Cygwin, after 2.10.0-1 from 02-Feb-2018;
wenzelm
parents: 66727
diff changeset
    35
        File.write(cygwin_isabelle + Path.explode("cygwin_mirror"), mirror)
8740e1241555 updated to current Cygwin, after 2.10.0-1 from 02-Feb-2018;
wenzelm
parents: 66727
diff changeset
    36
69789
2c3e5e58d93f more thorough File.set_executable, notably for Windows;
wenzelm
parents: 69425
diff changeset
    37
        File.set_executable(cygwin_exe, true)
69405
22428643351f more direct File.executable operation: avoid external process (on Unix);
wenzelm
parents: 69277
diff changeset
    38
        Isabelle_System.bash(File.bash_path(cygwin_exe) + " -h </dev/null >/dev/null").check
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    39
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    40
        val res =
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    41
          progress.bash(
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    42
            File.bash_path(cygwin_exe) + " --site " + Bash.string(mirror) + " --no-verify" +
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    43
              " --local-package-dir 'C:\\temp'" +
72036
e48a5b6b7554 clarified signature;
wenzelm
parents: 71385
diff changeset
    44
              " --root " + File.bash_platform_path(cygwin) +
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    45
              " --packages " + quote((packages ::: more_packages).mkString(",")) +
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    46
              " --no-shortcuts --no-startmenu --no-desktop --quiet-mode",
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    47
            echo = true)
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    48
        if (!res.ok || !cygwin_etc.is_dir) error("Failed")
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    49
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    50
        for (name <- List("hosts", "protocols", "services", "networks", "passwd", "group"))
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    51
          (cygwin_etc + Path.explode(name)).file.delete
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    52
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    53
        (cygwin + Path.explode("Cygwin.bat")).file.delete
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    54
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    55
        val archive =
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    56
          target_dir + Path.explode("cygwin-" + Date.Format.alt_date(Date.now()) + ".tar.gz")
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    57
        Isabelle_System.gnutar("-czf " + File.bash_path(archive) + " cygwin", dir = tmp_dir).check
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    58
      }
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    59
  }
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    60
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    61
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    62
  /* Isabelle tool wrapper */
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    63
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    64
  val isabelle_tool =
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76553
diff changeset
    65
    Isabelle_Tool("component_cygwin", "produce pre-canned Cygwin distribution for Isabelle",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    66
      Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    67
      { args =>
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    68
        var target_dir = Path.current
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    69
        var mirror = default_mirror
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    70
        var more_packages: List[String] = Nil
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    71
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    72
        val getopts =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    73
          Getopts("""
77566
2a99fcb283ee renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents: 76553
diff changeset
    74
Usage: isabelle component_cygwin [OPTIONS]
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    75
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    76
  Options are:
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    77
    -D DIR       target directory (default ".")
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    78
    -R MIRROR    Cygwin mirror site (default """ + quote(default_mirror) + """)
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    79
    -p NAME      additional Cygwin package
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    80
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    81
  Produce pre-canned Cygwin distribution for Isabelle: this requires
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    82
  Windows administrator mode.
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    83
""",
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    84
            "D:" -> (arg => target_dir = Path.explode(arg)),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    85
            "R:" -> (arg => mirror = arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    86
            "p:" -> (arg => more_packages ::= arg))
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    87
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    88
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    89
        if (more_args.nonEmpty) getopts.usage()
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    90
76526
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    91
        val progress = new Console_Progress()
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    92
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    93
        build_cygwin(target_dir = target_dir, mirror = mirror, more_packages = more_packages,
33025e13dcdc clarified command-line arguments: follow more recent isabelle build_XYZ;
wenzelm
parents: 76239
diff changeset
    94
          progress = progress)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    95
      })
65071
9ed87c82cbe7 proper Isabelle/Scala tool;
wenzelm
parents:
diff changeset
    96
}