| author | wenzelm | 
| Tue, 06 Sep 2022 21:06:20 +0200 | |
| changeset 76074 | 2456721602b2 | 
| parent 76028 | 105867f98630 | 
| child 76239 | d042947e47a3 | 
| permissions | -rw-r--r-- | 
| 65071 | 1 | /* Title: Pure/Admin/build_cygwin.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Produce pre-canned Cygwin distribution for Isabelle. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 75393 | 10 | object Build_Cygwin {
 | 
| 76028 | 11 | val default_mirror: String = "https://isabelle.sketis.net/cygwin_2022" | 
| 65071 | 12 | |
| 13 | val packages: List[String] = | |
| 75468 | 14 |     List("curl", "libgmp-devel", "nano", "rsync", "unzip")
 | 
| 65071 | 15 | |
| 16 | def build_cygwin(progress: Progress, | |
| 17 | mirror: String = default_mirror, | |
| 75393 | 18 | more_packages: List[String] = Nil | 
| 19 |   ): Unit = {
 | |
| 73120 
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
 wenzelm parents: 
72763diff
changeset | 20 | require(Platform.is_windows, "Windows platform expected") | 
| 65071 | 21 | |
| 75394 | 22 |     Isabelle_System.with_tmp_dir("cygwin") { tmp_dir =>
 | 
| 65071 | 23 |         val cygwin = tmp_dir + Path.explode("cygwin")
 | 
| 24 |         val cygwin_etc = cygwin + Path.explode("etc")
 | |
| 72376 | 25 |         val cygwin_isabelle = Isabelle_System.make_directory(cygwin + Path.explode("isabelle"))
 | 
| 65071 | 26 | |
| 66727 | 27 | val cygwin_exe_name = mirror + "/setup-x86_64.exe" | 
| 65071 | 28 |         val cygwin_exe = cygwin_isabelle + Path.explode("cygwin.exe")
 | 
| 29 | Bytes.write(cygwin_exe, | |
| 30 |           try { Bytes.read(Url(cygwin_exe_name)) }
 | |
| 31 |           catch { case ERROR(_) => error("Failed to download " + quote(cygwin_exe_name)) })
 | |
| 32 | ||
| 68374 
8740e1241555
updated to current Cygwin, after 2.10.0-1 from 02-Feb-2018;
 wenzelm parents: 
66727diff
changeset | 33 |         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: 
66727diff
changeset | 34 | |
| 69789 
2c3e5e58d93f
more thorough File.set_executable, notably for Windows;
 wenzelm parents: 
69425diff
changeset | 35 | File.set_executable(cygwin_exe, true) | 
| 69405 
22428643351f
more direct File.executable operation: avoid external process (on Unix);
 wenzelm parents: 
69277diff
changeset | 36 | Isabelle_System.bash(File.bash_path(cygwin_exe) + " -h </dev/null >/dev/null").check | 
| 65071 | 37 | |
| 38 | val res = | |
| 39 | progress.bash( | |
| 40 | File.bash_path(cygwin_exe) + " --site " + Bash.string(mirror) + " --no-verify" + | |
| 41 | " --local-package-dir 'C:\\temp'" + | |
| 72036 | 42 | " --root " + File.bash_platform_path(cygwin) + | 
| 65071 | 43 |               " --packages " + quote((packages ::: more_packages).mkString(",")) +
 | 
| 44 | " --no-shortcuts --no-startmenu --no-desktop --quiet-mode", | |
| 45 | echo = true) | |
| 46 |         if (!res.ok || !cygwin_etc.is_dir) error("Failed")
 | |
| 47 | ||
| 48 |         for (name <- List("hosts", "protocols", "services", "networks", "passwd", "group"))
 | |
| 49 | (cygwin_etc + Path.explode(name)).file.delete | |
| 50 | ||
| 51 |         (cygwin + Path.explode("Cygwin.bat")).file.delete
 | |
| 52 | ||
| 73649 | 53 | val archive = "cygwin-" + Date.Format.alt_date(Date.now()) + ".tar.gz" | 
| 69425 | 54 |         Isabelle_System.gnutar("-czf " + Bash.string(archive) + " cygwin", dir = tmp_dir).check
 | 
| 75394 | 55 | } | 
| 65071 | 56 | } | 
| 57 | ||
| 58 | ||
| 59 | /* Isabelle tool wrapper */ | |
| 60 | ||
| 61 | val isabelle_tool = | |
| 72763 | 62 |     Isabelle_Tool("build_cygwin", "produce pre-canned Cygwin distribution for Isabelle",
 | 
| 75394 | 63 | Scala_Project.here, | 
| 64 |       { args =>
 | |
| 65 | var mirror = default_mirror | |
| 66 | var more_packages: List[String] = Nil | |
| 65071 | 67 | |
| 75394 | 68 | val getopts = | 
| 69 |           Getopts("""
 | |
| 65071 | 70 | Usage: isabelle build_cygwin [OPTIONS] | 
| 71 | ||
| 72 | Options are: | |
| 73 | -R MIRROR Cygwin mirror site (default """ + quote(default_mirror) + """) | |
| 74 | -p NAME additional Cygwin package | |
| 75 | ||
| 76 | Produce pre-canned Cygwin distribution for Isabelle: this requires | |
| 77 | Windows administrator mode. | |
| 78 | """, | |
| 75394 | 79 | "R:" -> (arg => mirror = arg), | 
| 80 | "p:" -> (arg => more_packages ::= arg)) | |
| 65071 | 81 | |
| 75394 | 82 | val more_args = getopts(args) | 
| 83 | if (more_args.nonEmpty) getopts.usage() | |
| 65071 | 84 | |
| 75394 | 85 | build_cygwin(new Console_Progress(), mirror = mirror, more_packages = more_packages) | 
| 86 | }) | |
| 65071 | 87 | } |