Standard_System.raw_execute: optional cwd;
authorwenzelm
Sat Jan 02 01:14:49 2010 +0100 (2010-01-02)
changeset 34219d37cfca69887
parent 34218 f65c717952c0
child 34220 f7a0088518e1
Standard_System.raw_execute: optional cwd;
basic Cygwin.setup with download and unattended installation;
src/Pure/General/download.scala
src/Pure/System/cygwin.scala
src/Pure/System/isabelle_system.scala
src/Pure/System/standard_system.scala
     1.1 --- a/src/Pure/General/download.scala	Sat Jan 02 00:08:47 2010 +0100
     1.2 +++ b/src/Pure/General/download.scala	Sat Jan 02 01:14:49 2010 +0100
     1.3 @@ -29,8 +29,8 @@
     1.4      (connection, new BufferedInputStream(stream))
     1.5    }
     1.6  
     1.7 -  // FIXME error handling
     1.8 -  def file(parent: Component, url: URL, file: File)
     1.9 +  // FIXME error handling (dialogs)
    1.10 +  def file(parent: Component, url: URL, file: File): Boolean =
    1.11    {
    1.12      val outstream = new BufferedOutputStream(new FileOutputStream(file))
    1.13  
     2.1 --- a/src/Pure/System/cygwin.scala	Sat Jan 02 00:08:47 2010 +0100
     2.2 +++ b/src/Pure/System/cygwin.scala	Sat Jan 02 01:14:49 2010 +0100
     2.3 @@ -8,6 +8,8 @@
     2.4  
     2.5  import java.lang.reflect.Method
     2.6  import java.io.File
     2.7 +import java.net.URL
     2.8 +import java.awt.Component
     2.9  
    2.10  
    2.11  object Cygwin
    2.12 @@ -95,13 +97,23 @@
    2.13      root
    2.14    }
    2.15  
    2.16 -  def setup(exe: String, root: String): Int =
    2.17 +  // FIXME error handling (dialogs)
    2.18 +  def setup(parent: Component, root: File)
    2.19    {
    2.20 -    val (output, rc) = Standard_System.process_output(
    2.21 -    	Standard_System.raw_execute(null, true, exe, "-R", root, "-P", "perl,python", "-q", "-n"))
    2.22 -    val root_dir = new File(root)
    2.23 -    if (root_dir.isDirectory) Standard_System.write_file(new File(root, "setup.log"), output)
    2.24 -    rc
    2.25 +    if (!root.mkdirs) error("Failed to create root directory: " + root)
    2.26 +
    2.27 +    val download = new File(root, "download")
    2.28 +    if (!download.mkdir) error("Failed to create download directory: " + download)
    2.29 +
    2.30 +    val setup_exe = new File(root, "setup.exe")
    2.31 +    if (!Download.file(parent, new URL("http://www.cygwin.com/setup.exe"), setup_exe))
    2.32 +      error("Failed to download Cygwin setup program")
    2.33 +
    2.34 +    val (_, rc) = Standard_System.process_output(
    2.35 +    	Standard_System.raw_execute(root, null, true,
    2.36 +    	  setup_exe.toString, "-R", root.toString, "-l", download.toString,
    2.37 +    	    "-P", "perl,python", "-q", "-n"))
    2.38 +    if (rc != 0) error("Cygwin setup failed!")
    2.39    }
    2.40  }
    2.41  
     3.1 --- a/src/Pure/System/isabelle_system.scala	Sat Jan 02 00:08:47 2010 +0100
     3.2 +++ b/src/Pure/System/isabelle_system.scala	Sat Jan 02 01:14:49 2010 +0100
     3.3 @@ -43,7 +43,7 @@
     3.4          val cmdline =
     3.5            shell_prefix ::: List(isabelle_home + "/bin/isabelle", "getenv", "-d", dump.toString)
     3.6          val (output, rc) =
     3.7 -          Standard_System.process_output(Standard_System.raw_execute(env0, true, cmdline: _*))
     3.8 +          Standard_System.process_output(Standard_System.raw_execute(null, env0, true, cmdline: _*))
     3.9          if (rc != 0) error(output)
    3.10  
    3.11          val entries =
    3.12 @@ -66,7 +66,7 @@
    3.13      val cmdline =
    3.14        if (Platform.is_windows) List(platform_root + "\\bin\\env.exe") ++ args
    3.15        else args
    3.16 -    Standard_System.raw_execute(environment, redirect, cmdline: _*)
    3.17 +    Standard_System.raw_execute(null, environment, redirect, cmdline: _*)
    3.18    }
    3.19  
    3.20  
     4.1 --- a/src/Pure/System/standard_system.scala	Sat Jan 02 00:08:47 2010 +0100
     4.2 +++ b/src/Pure/System/standard_system.scala	Sat Jan 02 01:14:49 2010 +0100
     4.3 @@ -101,12 +101,13 @@
     4.4  
     4.5    /* shell processes */
     4.6  
     4.7 -  def raw_execute(env: Map[String, String], redirect: Boolean, args: String*): Process =
     4.8 +  def raw_execute(cwd: File, env: Map[String, String], redirect: Boolean, args: String*): Process =
     4.9    {
    4.10      val cmdline = new java.util.LinkedList[String]
    4.11      for (s <- args) cmdline.add(s)
    4.12  
    4.13      val proc = new ProcessBuilder(cmdline)
    4.14 +    if (cwd != null) proc.directory(cwd)
    4.15      if (env != null) {
    4.16        proc.environment.clear
    4.17        for ((x, y) <- env) proc.environment.put(x, y)