simplified Cygwin root: warm start via env, cold start via property, no registry magic;
authorwenzelm
Thu May 24 23:13:06 2012 +0200 (2012-05-24)
changeset 4799625b9f59ab1b9
parent 47995 72f52cd7c633
child 47997 0a43fc778cd2
simplified Cygwin root: warm start via env, cold start via property, no registry magic;
lib/scripts/getsettings
src/Pure/System/cygwin.scala
     1.1 --- a/lib/scripts/getsettings	Thu May 24 22:49:39 2012 +0200
     1.2 +++ b/lib/scripts/getsettings	Thu May 24 23:13:06 2012 +0200
     1.3 @@ -23,7 +23,7 @@
     1.4  
     1.5    CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
     1.6    function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
     1.7 -  THIS_CYGWIN="$(jvmpath "/")"
     1.8 +  CYGWIN_ROOT="$(jvmpath "/")"
     1.9  else
    1.10    if [ -z "$USER_HOME" ]; then
    1.11      USER_HOME="$HOME"
     2.1 --- a/src/Pure/System/cygwin.scala	Thu May 24 22:49:39 2012 +0200
     2.2 +++ b/src/Pure/System/cygwin.scala	Thu May 24 23:13:06 2012 +0200
     2.3 @@ -8,7 +8,6 @@
     2.4  package isabelle
     2.5  
     2.6  import java.lang.System
     2.7 -import java.lang.reflect.Method
     2.8  import java.io.File
     2.9  import java.net.URL
    2.10  import java.awt.Component
    2.11 @@ -16,73 +15,8 @@
    2.12  
    2.13  object Cygwin
    2.14  {
    2.15 -  /* registry access */
    2.16 -
    2.17 -  // Some black magic involving private WindowsPreferences from Sun, cf.
    2.18 -  // http://www.docjar.com/html/api/java/util/prefs/WindowsPreferences.java.html
    2.19 -
    2.20 -  private val WindowsPreferences = Class.forName("java.util.prefs.WindowsPreferences")
    2.21 -
    2.22 -  private val HKEY_CURRENT_USER = 0x80000001
    2.23 -  private val HKEY_LOCAL_MACHINE = 0x80000002
    2.24 -  private val KEY_READ = 0x20019
    2.25 -  private val NATIVE_HANDLE = 0
    2.26 -  private val ERROR_CODE = 1
    2.27 -
    2.28 -  private def C_string(s: String): Array[Byte] =
    2.29 -    (s + "\0").getBytes("US-ASCII")
    2.30 -
    2.31 -  private def J_string(bs: Array[Byte]): String =
    2.32 -    new String(bs, 0, bs.length - 1, "US-ASCII")
    2.33 -
    2.34 -  private val INT = Integer.TYPE
    2.35 -  private val BYTES = (new Array[Byte](0)).getClass
    2.36 -
    2.37 -  private def open_key(handle: Int, subkey: Array[Byte], mask: Int): Array[Int] =
    2.38 -  {
    2.39 -    val m = WindowsPreferences.getDeclaredMethod("WindowsRegOpenKey", INT, BYTES, INT)
    2.40 -    m.setAccessible(true)
    2.41 -    m.invoke(null, handle.asInstanceOf[Object], subkey.asInstanceOf[Object],
    2.42 -      mask.asInstanceOf[Object]).asInstanceOf[Array[Int]]
    2.43 -  }
    2.44 -
    2.45 -  private def close_key(handle: Int): Int =
    2.46 -  {
    2.47 -    val m = WindowsPreferences.getDeclaredMethod("WindowsRegCloseKey", INT)
    2.48 -    m.setAccessible(true)
    2.49 -    m.invoke(null, handle.asInstanceOf[Object]).asInstanceOf[Int]
    2.50 -  }
    2.51 -
    2.52 -  private def query(handle: Int, name: Array[Byte]) =
    2.53 -  {
    2.54 -    val m = WindowsPreferences.getDeclaredMethod("WindowsRegQueryValueEx", INT, BYTES)
    2.55 -    m.setAccessible(true)
    2.56 -    m.invoke(null, handle.asInstanceOf[Object], name.asInstanceOf[Object]).
    2.57 -      asInstanceOf[Array[Byte]]
    2.58 -  }
    2.59 -
    2.60 -  def query_registry(sys: Boolean, path: String, name: String): Option[String] =
    2.61 -  {
    2.62 -    val handle = if (sys) HKEY_LOCAL_MACHINE else HKEY_CURRENT_USER
    2.63 -    val result = open_key(handle, C_string(path), KEY_READ)
    2.64 -    if (result(ERROR_CODE) != 0) None
    2.65 -    else {
    2.66 -      val res = query(result(NATIVE_HANDLE), C_string(name))
    2.67 -      if (res == null) None
    2.68 -      else Some(J_string(res))
    2.69 -    }
    2.70 -  }
    2.71 -
    2.72 -  def query_registry(path: String, name: String): Option[String] =
    2.73 -    query_registry(false, path, name) orElse
    2.74 -      query_registry(true, path, name)
    2.75 -
    2.76 -
    2.77    /* Cygwin installation */
    2.78  
    2.79 -  private val CYGWIN_SETUP1 = "Software\\Cygwin\\setup"
    2.80 -  private val CYGWIN_SETUP2 = "Software\\Wow6432Node\\Cygwin\\setup"
    2.81 -
    2.82    private def sanity_check(root: File)
    2.83    {
    2.84      if (!new File(root, "bin\\bash.exe").isFile ||
    2.85 @@ -93,15 +27,12 @@
    2.86  
    2.87    def check_root(): String =
    2.88    {
    2.89 -    val this_cygwin = System.getenv("THIS_CYGWIN")
    2.90 -    val cygwin_root = System.getProperty("cygwin.root")
    2.91 +    val cygwin_root1 = System.getenv("CYGWIN_ROOT")
    2.92 +    val cygwin_root2 = System.getProperty("cygwin.root")
    2.93      val root =
    2.94 -      if (this_cygwin != null && this_cygwin != "") this_cygwin
    2.95 -      else if (cygwin_root != null && cygwin_root != "") cygwin_root
    2.96 -      else
    2.97 -        query_registry(CYGWIN_SETUP1, "rootdir") orElse
    2.98 -        query_registry(CYGWIN_SETUP2, "rootdir") getOrElse
    2.99 -        error("Failed to determine Cygwin installation -- version 1.7.x required")
   2.100 +      if (cygwin_root1 != null && cygwin_root1 != "") cygwin_root1
   2.101 +      else if (cygwin_root2 != null && cygwin_root2 != "") cygwin_root2
   2.102 +      else error("Bad Cygwin installation: unknown root")
   2.103      sanity_check(new File(root))
   2.104      root
   2.105    }