src/Pure/System/cygwin_init.scala
changeset 53419 1c87e79bb838
parent 52672 8de4235298cb
child 53423 b5a279c7d7f3
equal deleted inserted replaced
53418:d47a7cebe6b2 53419:1c87e79bb838
     5 */
     5 */
     6 
     6 
     7 package isabelle
     7 package isabelle
     8 
     8 
     9 
     9 
    10 import java.lang.System
       
    11 import java.io.{File => JFile, BufferedReader, InputStreamReader}
    10 import java.io.{File => JFile, BufferedReader, InputStreamReader}
    12 import java.nio.file.{Paths, Files}
    11 import java.nio.file.{Paths, Files}
    13 import java.awt.{GraphicsEnvironment, Point, Font}
    12 import java.awt.{GraphicsEnvironment, Point, Font}
    14 import javax.swing.ImageIcon
    13 import javax.swing.ImageIcon
    15 
    14 
    19 import scala.swing.event.ButtonClicked
    18 import scala.swing.event.ButtonClicked
    20 
    19 
    21 
    20 
    22 object Cygwin_Init
    21 object Cygwin_Init
    23 {
    22 {
    24   /* command-line entry point */
    23   /* main GUI entry point */
    25 
    24 
    26   def main(args: Array[String]) =
    25   def main_frame(isabelle_home: String, start: => Unit) = new MainFrame
    27   {
       
    28     GUI.init_laf()
       
    29     try {
       
    30       require(Platform.is_windows)
       
    31 
       
    32       val isabelle_home = System.getProperty("isabelle.home")
       
    33       if (isabelle_home == null || isabelle_home == "")
       
    34         error("Unknown Isabelle home directory")
       
    35       if (!(new JFile(isabelle_home)).isDirectory)
       
    36         error("Bad Isabelle home directory: " + quote(isabelle_home))
       
    37 
       
    38       Swing_Thread.later { main_frame(isabelle_home) }
       
    39     }
       
    40     catch {
       
    41       case exn: Throwable =>
       
    42         GUI.error_dialog(null, "Isabelle init failure", GUI.scrollable_text(Exn.message(exn)))
       
    43         sys.exit(2)
       
    44     }
       
    45   }
       
    46 
       
    47 
       
    48   /* main window */
       
    49 
       
    50   private def main_frame(isabelle_home: String) = new MainFrame
       
    51   {
    26   {
    52     title = "Isabelle system initialization"
    27     title = "Isabelle system initialization"
    53     iconImage = new ImageIcon(isabelle_home + "\\lib\\logo\\isabelle.gif").getImage
    28     iconImage = new ImageIcon(isabelle_home + "\\lib\\logo\\isabelle.gif").getImage
    54 
    29 
    55     val layout_panel = new BorderPanel
    30     val layout_panel = new BorderPanel
    71 
    46 
    72 
    47 
    73     /* exit button */
    48     /* exit button */
    74 
    49 
    75     var _return_code: Option[Int] = None
    50     var _return_code: Option[Int] = None
    76     def maybe_exit(): Unit = _return_code.foreach(sys.exit(_))
    51     def maybe_exit()
       
    52     {
       
    53       _return_code match {
       
    54         case None =>
       
    55         case Some(0) => start
       
    56         case Some(rc) => sys.exit(rc)
       
    57       }
       
    58     }
    77 
    59 
    78     def return_code(rc: Int): Unit =
    60     def return_code(rc: Int): Unit =
    79       Swing_Thread.later {
    61       Swing_Thread.later {
    80         _return_code = Some(rc)
    62         _return_code = Some(rc)
    81         button.peer.getRootPane.setDefaultButton(button.peer)
    63         button.peer.getRootPane.setDefaultButton(button.peer)
   100     location = new Point(point.x - size.width / 2, point.y - size.height / 2)
    82     location = new Point(point.x - size.width / 2, point.y - size.height / 2)
   101     visible = true
    83     visible = true
   102 
    84 
   103     default_thread_pool.submit(() =>
    85     default_thread_pool.submit(() =>
   104       try {
    86       try {
   105         init(isabelle_home, echo)
    87         init_filesystem(isabelle_home, echo)
   106         return_code(0)
    88         return_code(0)
   107       }
    89       }
   108       catch {
    90       catch {
   109         case exn: Throwable =>
    91         case exn: Throwable =>
   110           text_area.append("Error:\n" + Exn.message(exn) + "\n")
    92           text_area.append("Error:\n" + Exn.message(exn) + "\n")
   114   }
    96   }
   115 
    97 
   116 
    98 
   117   /* init Cygwin file-system */
    99   /* init Cygwin file-system */
   118 
   100 
   119   private def init(isabelle_home: String, echo: String => Unit)
   101   private def init_filesystem(isabelle_home: String, echo: String => Unit)
   120   {
   102   {
   121     val cygwin_root = isabelle_home + "\\contrib\\cygwin"
       
   122 
       
   123     if (!(new JFile(cygwin_root)).isDirectory)
       
   124       error("Bad Isabelle Cygwin directory: " + quote(cygwin_root))
       
   125 
       
   126     def execute(args: String*): Int =
   103     def execute(args: String*): Int =
   127     {
   104     {
   128       val cwd = new JFile(isabelle_home)
   105       val cwd = new JFile(isabelle_home)
   129       val env = Map("CYGWIN" -> "nodosfilewarning")
   106       val env = Map("CYGWIN" -> "nodosfilewarning")
   130       val proc = Isabelle_System.raw_execute(cwd, env, true, args: _*)
   107       val proc = Isabelle_System.raw_execute(cwd, env, true, args: _*)
   146     echo("Initializing Cygwin:")
   123     echo("Initializing Cygwin:")
   147 
   124 
   148     echo("symlinks ...")
   125     echo("symlinks ...")
   149     val symlinks =
   126     val symlinks =
   150     {
   127     {
   151       val path = (new JFile(cygwin_root, "isabelle\\symlinks")).toPath
   128       val path = (new JFile("contrib\\cygwin\\isabelle\\symlinks")).toPath
   152       Files.readAllLines(path, UTF8.charset).toArray.toList.asInstanceOf[List[String]]
   129       Files.readAllLines(path, UTF8.charset).toArray.toList.asInstanceOf[List[String]]
   153     }
   130     }
   154     @tailrec def recover_symlinks(list: List[String]): Unit =
   131     @tailrec def recover_symlinks(list: List[String]): Unit =
   155     {
   132     {
   156       list match {
   133       list match {
   169       }
   146       }
   170     }
   147     }
   171     recover_symlinks(symlinks)
   148     recover_symlinks(symlinks)
   172 
   149 
   173     echo("rebaseall ...")
   150     echo("rebaseall ...")
   174     execute(cygwin_root + "\\bin\\dash.exe", "/isabelle/rebaseall")
   151     execute("contrib\\cygwin\\bin\\dash.exe", "/isabelle/rebaseall")
   175 
   152 
   176     echo("postinstall ...")
   153     echo("postinstall ...")
   177     execute(cygwin_root + "\\bin\\bash.exe", "/isabelle/postinstall")
   154     execute("contrib\\cygwin\\bin\\bash.exe", "/isabelle/postinstall")
   178 
   155 
   179     echo("init ...")
   156     echo("init ...")
   180     System.setProperty("cygwin.root", cygwin_root)
       
   181     Isabelle_System.init()
   157     Isabelle_System.init()
   182     echo("OK")
   158     echo("OK")
   183   }
   159   }
   184 }
   160 }
   185 
   161