src/Pure/Admin/build_cygwin.scala
author wenzelm
Sat Sep 30 12:28:41 2017 +0200 (21 months ago)
changeset 66727 56b92ce30d87
parent 66529 f39e01e9c489
child 68374 8740e1241555
permissions -rw-r--r--
updated to x86_64-cygwin;
wenzelm@65071
     1
/*  Title:      Pure/Admin/build_cygwin.scala
wenzelm@65071
     2
    Author:     Makarius
wenzelm@65071
     3
wenzelm@65071
     4
Produce pre-canned Cygwin distribution for Isabelle.
wenzelm@65071
     5
*/
wenzelm@65071
     6
wenzelm@65071
     7
package isabelle
wenzelm@65071
     8
wenzelm@65071
     9
wenzelm@65071
    10
object Build_Cygwin
wenzelm@65071
    11
{
wenzelm@66529
    12
  val default_mirror: String = "http://isabelle.in.tum.de/cygwin_2017"
wenzelm@65071
    13
wenzelm@65071
    14
  val packages: List[String] =
wenzelm@65071
    15
    List("curl", "nano", "perl", "perl-libwww-perl", "rlwrap", "unzip")
wenzelm@65071
    16
wenzelm@65071
    17
  def build_cygwin(progress: Progress,
wenzelm@65071
    18
    mirror: String = default_mirror,
wenzelm@65071
    19
    more_packages: List[String] = Nil)
wenzelm@65071
    20
  {
wenzelm@65071
    21
    require(Platform.is_windows)
wenzelm@65071
    22
wenzelm@65071
    23
    Isabelle_System.with_tmp_dir("cygwin")(tmp_dir =>
wenzelm@65071
    24
      {
wenzelm@65071
    25
        val cygwin = tmp_dir + Path.explode("cygwin")
wenzelm@65071
    26
        val cygwin_etc = cygwin + Path.explode("etc")
wenzelm@65071
    27
        val cygwin_isabelle = cygwin + Path.explode("isabelle")
wenzelm@65071
    28
        Isabelle_System.mkdirs(cygwin_isabelle)
wenzelm@65071
    29
wenzelm@66727
    30
        val cygwin_exe_name = mirror + "/setup-x86_64.exe"
wenzelm@65071
    31
        val cygwin_exe = cygwin_isabelle + Path.explode("cygwin.exe")
wenzelm@65071
    32
        Bytes.write(cygwin_exe,
wenzelm@65071
    33
          try { Bytes.read(Url(cygwin_exe_name)) }
wenzelm@65071
    34
          catch { case ERROR(_) => error("Failed to download " + quote(cygwin_exe_name)) })
wenzelm@65071
    35
wenzelm@65071
    36
        Isabelle_System.bash(
wenzelm@65071
    37
          "chmod +x " + File.bash_path(cygwin_exe) + " && " +
wenzelm@65071
    38
          File.bash_path(cygwin_exe) + " -h </dev/null >/dev/null").check
wenzelm@65071
    39
wenzelm@65071
    40
        val res =
wenzelm@65071
    41
          progress.bash(
wenzelm@65071
    42
            File.bash_path(cygwin_exe) + " --site " + Bash.string(mirror) + " --no-verify" +
wenzelm@65071
    43
              " --local-package-dir 'C:\\temp'" +
wenzelm@65071
    44
              " --root " + Bash.string(File.platform_path(cygwin)) +
wenzelm@65071
    45
              " --packages " + quote((packages ::: more_packages).mkString(",")) +
wenzelm@65071
    46
              " --no-shortcuts --no-startmenu --no-desktop --quiet-mode",
wenzelm@65071
    47
            echo = true)
wenzelm@65071
    48
        if (!res.ok || !cygwin_etc.is_dir) error("Failed")
wenzelm@65071
    49
wenzelm@65071
    50
        for (name <- List("hosts", "protocols", "services", "networks", "passwd", "group"))
wenzelm@65071
    51
          (cygwin_etc + Path.explode(name)).file.delete
wenzelm@65071
    52
wenzelm@65071
    53
        (cygwin + Path.explode("Cygwin.bat")).file.delete
wenzelm@65071
    54
wenzelm@65071
    55
        val archive = "cygwin-" + Date.Format("uuuuMMdd")(Date.now()) + ".tar.gz"
wenzelm@65071
    56
        Isabelle_System.gnutar("-C " + File.bash_path(tmp_dir) +
wenzelm@65071
    57
          " -czf " + Bash.string(archive) + " cygwin").check
wenzelm@65071
    58
      })
wenzelm@65071
    59
  }
wenzelm@65071
    60
wenzelm@65071
    61
wenzelm@65071
    62
  /* Isabelle tool wrapper */
wenzelm@65071
    63
wenzelm@65071
    64
  val isabelle_tool =
wenzelm@65071
    65
    Isabelle_Tool("build_cygwin", "produce pre-canned Cygwin distribution for Isabelle", args =>
wenzelm@65071
    66
    {
wenzelm@65071
    67
      var mirror = default_mirror
wenzelm@65071
    68
      var more_packages: List[String] = Nil
wenzelm@65071
    69
wenzelm@65071
    70
      val getopts =
wenzelm@65071
    71
        Getopts("""
wenzelm@65071
    72
Usage: isabelle build_cygwin [OPTIONS]
wenzelm@65071
    73
wenzelm@65071
    74
  Options are:
wenzelm@65071
    75
    -R MIRROR    Cygwin mirror site (default """ + quote(default_mirror) + """)
wenzelm@65071
    76
    -p NAME      additional Cygwin package
wenzelm@65071
    77
wenzelm@65071
    78
  Produce pre-canned Cygwin distribution for Isabelle: this requires
wenzelm@65071
    79
  Windows administrator mode.
wenzelm@65071
    80
""",
wenzelm@65071
    81
          "R:" -> (arg => mirror = arg),
wenzelm@65071
    82
          "p:" -> (arg => more_packages ::= arg))
wenzelm@65071
    83
wenzelm@65071
    84
      val more_args = getopts(args)
wenzelm@65071
    85
      if (more_args.nonEmpty) getopts.usage()
wenzelm@65071
    86
wenzelm@65071
    87
      build_cygwin(new Console_Progress(), mirror = mirror, more_packages = more_packages)
wenzelm@65071
    88
    }, admin = true)
wenzelm@65071
    89
}