src/Pure/System/cygwin.scala
changeset 73893 eb7655fcb090
parent 73892 2847a3deedf9
equal deleted inserted replaced
73892:2847a3deedf9 73893:eb7655fcb090
    13 import scala.annotation.tailrec
    13 import scala.annotation.tailrec
    14 
    14 
    15 
    15 
    16 object Cygwin
    16 object Cygwin
    17 {
    17 {
    18   /* init (e.g. after extraction via 7zip) */
       
    19 
       
    20   def init(isabelle_root: String, cygwin_root: String): Unit =
       
    21   {
       
    22     require(Platform.is_windows, "Windows platform expected")
       
    23 
       
    24     def exec(cmdline: String*): Unit =
       
    25     {
       
    26       val cwd = new JFile(isabelle_root)
       
    27       val env = sys.env + ("CYGWIN" -> "nodosfilewarning")
       
    28       val proc = Isabelle_Env.process(cmdline.toList, cwd = cwd, env = env, redirect = true)
       
    29       val (output, rc) = Isabelle_Env.process_output(proc)
       
    30       if (rc != 0) error(output)
       
    31     }
       
    32 
       
    33     val uninitialized_file = new JFile(cygwin_root, "isabelle\\uninitialized")
       
    34     val uninitialized = uninitialized_file.isFile && uninitialized_file.delete
       
    35 
       
    36     if (uninitialized) {
       
    37       val symlinks =
       
    38       {
       
    39         val path = (new JFile(cygwin_root + "\\isabelle\\symlinks")).toPath
       
    40         Files.readAllLines(path, UTF8.charset).toArray.toList.asInstanceOf[List[String]]
       
    41       }
       
    42       @tailrec def recover_symlinks(list: List[String]): Unit =
       
    43       {
       
    44         list match {
       
    45           case Nil | List("") =>
       
    46           case target :: content :: rest =>
       
    47             link(content, new JFile(isabelle_root, target))
       
    48             recover_symlinks(rest)
       
    49           case _ => error("Unbalanced symlinks list")
       
    50         }
       
    51       }
       
    52       recover_symlinks(symlinks)
       
    53 
       
    54       exec(cygwin_root + "\\bin\\dash.exe", "/isabelle/rebaseall")
       
    55       exec(cygwin_root + "\\bin\\bash.exe", "/isabelle/postinstall")
       
    56     }
       
    57   }
       
    58 
       
    59   def link(content: String, target: JFile): Unit =
       
    60   {
       
    61     val target_path = target.toPath
       
    62     Files.writeString(target_path, "!<symlink>" + content + "\u0000")
       
    63     Files.setAttribute(target_path, "dos:system", true)
       
    64   }
       
    65 }
    18 }