| author | nipkow | 
| Fri, 23 Aug 2024 18:40:12 +0200 | |
| changeset 80738 | 6adf6cc82013 | 
| parent 80224 | db92e0b6a11a | 
| child 81755 | 1609254b74c5 | 
| permissions | -rw-r--r-- | 
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76553diff
changeset | 1 | /* Title: Pure/Admin/component_cygwin.scala | 
| 65071 | 2 | Author: Makarius | 
| 3 | ||
| 4 | Produce pre-canned Cygwin distribution for Isabelle. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76553diff
changeset | 10 | object Component_Cygwin {
 | 
| 79782 
8bde94328b05
update cygwin near 3.5.1-1, also see https://cygwin.com/pipermail/cygwin-announce/2024-February/011524.html and https://cygwin.com/pipermail/cygwin-announce/2024-February/011611.html
 wenzelm parents: 
78311diff
changeset | 11 | val default_mirror: String = "https://isabelle.sketis.net/cygwin_2024" | 
| 65071 | 12 | |
| 78311 
b9d9906716f9
avoid bloat of approx. 300MB due to implicit dependency on python;
 wenzelm parents: 
78310diff
changeset | 13 |   val packages: List[String] = List("curl", "libgmp-devel", "nano", "openssh", "perl")
 | 
| 65071 | 14 | |
| 76526 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 15 | def build_cygwin( | 
| 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 16 | target_dir: Path = Path.current, | 
| 65071 | 17 | mirror: String = default_mirror, | 
| 76526 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 18 | more_packages: List[String] = Nil, | 
| 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 19 | progress: Progress = new Progress | 
| 75393 | 20 |   ): Unit = {
 | 
| 73120 
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
 wenzelm parents: 
72763diff
changeset | 21 | require(Platform.is_windows, "Windows platform expected") | 
| 65071 | 22 | |
| 75394 | 23 |     Isabelle_System.with_tmp_dir("cygwin") { tmp_dir =>
 | 
| 79786 | 24 |       val cygwin = tmp_dir + Path.explode("cygwin")
 | 
| 25 |       val cygwin_etc = cygwin + Path.explode("etc")
 | |
| 26 |       val cygwin_isabelle = Isabelle_System.make_directory(cygwin + Path.explode("isabelle"))
 | |
| 65071 | 27 | |
| 79786 | 28 | val cygwin_exe_name = mirror + "/setup-x86_64.exe" | 
| 29 |       val cygwin_exe = cygwin_isabelle + Path.explode("cygwin.exe")
 | |
| 30 | Bytes.write(cygwin_exe, | |
| 31 |         try { Bytes.read_url(cygwin_exe_name) }
 | |
| 32 |         catch { case ERROR(_) => error("Failed to download " + quote(cygwin_exe_name)) })
 | |
| 65071 | 33 | |
| 79786 | 34 |       File.write(cygwin_isabelle + Path.explode("cygwin_mirror"), mirror)
 | 
| 68374 
8740e1241555
updated to current Cygwin, after 2.10.0-1 from 02-Feb-2018;
 wenzelm parents: 
66727diff
changeset | 35 | |
| 79786 | 36 | File.set_executable(cygwin_exe) | 
| 37 | Isabelle_System.bash(File.bash_path(cygwin_exe) + " -h </dev/null >/dev/null").check | |
| 65071 | 38 | |
| 79786 | 39 | val res = | 
| 40 | progress.bash( | |
| 41 | File.bash_path(cygwin_exe) + " --site " + Bash.string(mirror) + " --no-verify" + | |
| 42 | " --local-package-dir 'C:\\temp'" + | |
| 43 | " --root " + File.bash_platform_path(cygwin) + | |
| 44 |             " --packages " + quote((packages ::: more_packages).mkString(",")) +
 | |
| 45 | " --no-shortcuts --no-startmenu --no-desktop --quiet-mode", | |
| 46 | echo = true) | |
| 47 |       if (!res.ok || !cygwin_etc.is_dir) error("Failed")
 | |
| 65071 | 48 | |
| 79786 | 49 |       for (name <- List("hosts", "protocols", "services", "networks", "passwd", "group"))
 | 
| 50 | (cygwin_etc + Path.explode(name)).file.delete | |
| 65071 | 51 | |
| 79786 | 52 |       (cygwin + Path.explode("Cygwin.bat")).file.delete
 | 
| 65071 | 53 | |
| 80224 
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
 wenzelm parents: 
79786diff
changeset | 54 |       Isabelle_System.bash("rm -f cygwin/usr/share/man/man1/:.1.gz", cwd = tmp_dir).check
 | 
| 78310 
6872c8d95ebc
suppress bad file, which does not work on regular Windows;
 wenzelm parents: 
78304diff
changeset | 55 | |
| 79786 | 56 | val archive = | 
| 57 |         target_dir + Path.explode("cygwin-" + Date.Format.alt_date(Date.now()) + ".tar.gz")
 | |
| 58 |       Isabelle_System.gnutar("-czf " + File.bash_path(archive) + " cygwin", dir = tmp_dir).check
 | |
| 59 | } | |
| 65071 | 60 | } | 
| 61 | ||
| 62 | ||
| 63 | /* Isabelle tool wrapper */ | |
| 64 | ||
| 65 | val isabelle_tool = | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76553diff
changeset | 66 |     Isabelle_Tool("component_cygwin", "produce pre-canned Cygwin distribution for Isabelle",
 | 
| 75394 | 67 | Scala_Project.here, | 
| 68 |       { args =>
 | |
| 76526 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 69 | var target_dir = Path.current | 
| 75394 | 70 | var mirror = default_mirror | 
| 71 | var more_packages: List[String] = Nil | |
| 65071 | 72 | |
| 75394 | 73 | val getopts = | 
| 74 |           Getopts("""
 | |
| 77566 
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
 wenzelm parents: 
76553diff
changeset | 75 | Usage: isabelle component_cygwin [OPTIONS] | 
| 65071 | 76 | |
| 77 | Options are: | |
| 76526 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 78 | -D DIR target directory (default ".") | 
| 65071 | 79 | -R MIRROR Cygwin mirror site (default """ + quote(default_mirror) + """) | 
| 80 | -p NAME additional Cygwin package | |
| 81 | ||
| 82 | Produce pre-canned Cygwin distribution for Isabelle: this requires | |
| 83 | Windows administrator mode. | |
| 84 | """, | |
| 76526 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 85 | "D:" -> (arg => target_dir = Path.explode(arg)), | 
| 75394 | 86 | "R:" -> (arg => mirror = arg), | 
| 87 | "p:" -> (arg => more_packages ::= arg)) | |
| 65071 | 88 | |
| 75394 | 89 | val more_args = getopts(args) | 
| 90 | if (more_args.nonEmpty) getopts.usage() | |
| 65071 | 91 | |
| 76526 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 92 | val progress = new Console_Progress() | 
| 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 93 | |
| 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 wenzelm parents: 
76239diff
changeset | 94 | 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: 
76239diff
changeset | 95 | progress = progress) | 
| 75394 | 96 | }) | 
| 65071 | 97 | } |