| author | Fabian Huch <huch@in.tum.de> | 
| Tue, 09 Jan 2024 17:35:56 +0100 | |
| changeset 79443 | 0d7c7fe65638 | 
| parent 78311 | b9d9906716f9 | 
| child 79782 | 8bde94328b05 | 
| permissions | -rw-r--r-- | 
| 
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 | 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: 
76553 
diff
changeset
 | 
10  | 
object Component_Cygwin {
 | 
| 
78304
 
e4b57eea7f86
update cygwin for Isabelle2023 -- somewhere after cygwin 3.4.0-1 (see https://cygwin.com/pipermail/cygwin-announce/2022-December/010821.html);
 
wenzelm 
parents: 
78299 
diff
changeset
 | 
11  | 
val default_mirror: String = "https://isabelle.sketis.net/cygwin_2023"  | 
| 65071 | 12  | 
|
| 
78311
 
b9d9906716f9
avoid bloat of approx. 300MB due to implicit dependency on python;
 
wenzelm 
parents: 
78310 
diff
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: 
76239 
diff
changeset
 | 
15  | 
def build_cygwin(  | 
| 
 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 
wenzelm 
parents: 
76239 
diff
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: 
76239 
diff
changeset
 | 
18  | 
more_packages: List[String] = Nil,  | 
| 
 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 
wenzelm 
parents: 
76239 
diff
changeset
 | 
19  | 
progress: Progress = new Progress  | 
| 75393 | 20  | 
  ): Unit = {
 | 
| 
73120
 
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
 
wenzelm 
parents: 
72763 
diff
changeset
 | 
21  | 
require(Platform.is_windows, "Windows platform expected")  | 
| 65071 | 22  | 
|
| 75394 | 23  | 
    Isabelle_System.with_tmp_dir("cygwin") { tmp_dir =>
 | 
| 65071 | 24  | 
        val cygwin = tmp_dir + Path.explode("cygwin")
 | 
25  | 
        val cygwin_etc = cygwin + Path.explode("etc")
 | 
|
| 72376 | 26  | 
        val cygwin_isabelle = Isabelle_System.make_directory(cygwin + Path.explode("isabelle"))
 | 
| 65071 | 27  | 
|
| 66727 | 28  | 
val cygwin_exe_name = mirror + "/setup-x86_64.exe"  | 
| 65071 | 29  | 
        val cygwin_exe = cygwin_isabelle + Path.explode("cygwin.exe")
 | 
30  | 
Bytes.write(cygwin_exe,  | 
|
| 77717 | 31  | 
          try { Bytes.read_url(cygwin_exe_name) }
 | 
| 65071 | 32  | 
          catch { case ERROR(_) => error("Failed to download " + quote(cygwin_exe_name)) })
 | 
33  | 
||
| 
68374
 
8740e1241555
updated to current Cygwin, after 2.10.0-1 from 02-Feb-2018;
 
wenzelm 
parents: 
66727 
diff
changeset
 | 
34  | 
        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
 | 
35  | 
|
| 78158 | 36  | 
File.set_executable(cygwin_exe)  | 
| 
69405
 
22428643351f
more direct File.executable operation: avoid external process (on Unix);
 
wenzelm 
parents: 
69277 
diff
changeset
 | 
37  | 
Isabelle_System.bash(File.bash_path(cygwin_exe) + " -h </dev/null >/dev/null").check  | 
| 65071 | 38  | 
|
39  | 
val res =  | 
|
40  | 
progress.bash(  | 
|
41  | 
File.bash_path(cygwin_exe) + " --site " + Bash.string(mirror) + " --no-verify" +  | 
|
42  | 
" --local-package-dir 'C:\\temp'" +  | 
|
| 72036 | 43  | 
" --root " + File.bash_platform_path(cygwin) +  | 
| 65071 | 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")
 | 
|
48  | 
||
49  | 
        for (name <- List("hosts", "protocols", "services", "networks", "passwd", "group"))
 | 
|
50  | 
(cygwin_etc + Path.explode(name)).file.delete  | 
|
51  | 
||
52  | 
        (cygwin + Path.explode("Cygwin.bat")).file.delete
 | 
|
53  | 
||
| 
78310
 
6872c8d95ebc
suppress bad file, which does not work on regular Windows;
 
wenzelm 
parents: 
78304 
diff
changeset
 | 
54  | 
        Isabelle_System.bash("rm -f cygwin/usr/share/man/man1/:.1.gz", cwd = tmp_dir.file).check
 | 
| 
 
6872c8d95ebc
suppress bad file, which does not work on regular Windows;
 
wenzelm 
parents: 
78304 
diff
changeset
 | 
55  | 
|
| 
76526
 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 
wenzelm 
parents: 
76239 
diff
changeset
 | 
56  | 
val archive =  | 
| 
 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 
wenzelm 
parents: 
76239 
diff
changeset
 | 
57  | 
          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
 | 
58  | 
        Isabelle_System.gnutar("-czf " + File.bash_path(archive) + " cygwin", dir = tmp_dir).check
 | 
| 75394 | 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: 
76553 
diff
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: 
76239 
diff
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: 
76553 
diff
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: 
76239 
diff
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: 
76239 
diff
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: 
76239 
diff
changeset
 | 
92  | 
val progress = new Console_Progress()  | 
| 
 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 
wenzelm 
parents: 
76239 
diff
changeset
 | 
93  | 
|
| 
 
33025e13dcdc
clarified command-line arguments: follow more recent isabelle build_XYZ;
 
wenzelm 
parents: 
76239 
diff
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: 
76239 
diff
changeset
 | 
95  | 
progress = progress)  | 
| 75394 | 96  | 
})  | 
| 65071 | 97  | 
}  |