simplified Cygwin root: warm start via env, cold start via property, no registry magic;
--- a/lib/scripts/getsettings Thu May 24 22:49:39 2012 +0200
+++ b/lib/scripts/getsettings Thu May 24 23:13:06 2012 +0200
@@ -23,7 +23,7 @@
CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
- THIS_CYGWIN="$(jvmpath "/")"
+ CYGWIN_ROOT="$(jvmpath "/")"
else
if [ -z "$USER_HOME" ]; then
USER_HOME="$HOME"
--- a/src/Pure/System/cygwin.scala Thu May 24 22:49:39 2012 +0200
+++ b/src/Pure/System/cygwin.scala Thu May 24 23:13:06 2012 +0200
@@ -8,7 +8,6 @@
package isabelle
import java.lang.System
-import java.lang.reflect.Method
import java.io.File
import java.net.URL
import java.awt.Component
@@ -16,73 +15,8 @@
object Cygwin
{
- /* registry access */
-
- // Some black magic involving private WindowsPreferences from Sun, cf.
- // http://www.docjar.com/html/api/java/util/prefs/WindowsPreferences.java.html
-
- private val WindowsPreferences = Class.forName("java.util.prefs.WindowsPreferences")
-
- private val HKEY_CURRENT_USER = 0x80000001
- private val HKEY_LOCAL_MACHINE = 0x80000002
- private val KEY_READ = 0x20019
- private val NATIVE_HANDLE = 0
- private val ERROR_CODE = 1
-
- private def C_string(s: String): Array[Byte] =
- (s + "\0").getBytes("US-ASCII")
-
- private def J_string(bs: Array[Byte]): String =
- new String(bs, 0, bs.length - 1, "US-ASCII")
-
- private val INT = Integer.TYPE
- private val BYTES = (new Array[Byte](0)).getClass
-
- private def open_key(handle: Int, subkey: Array[Byte], mask: Int): Array[Int] =
- {
- val m = WindowsPreferences.getDeclaredMethod("WindowsRegOpenKey", INT, BYTES, INT)
- m.setAccessible(true)
- m.invoke(null, handle.asInstanceOf[Object], subkey.asInstanceOf[Object],
- mask.asInstanceOf[Object]).asInstanceOf[Array[Int]]
- }
-
- private def close_key(handle: Int): Int =
- {
- val m = WindowsPreferences.getDeclaredMethod("WindowsRegCloseKey", INT)
- m.setAccessible(true)
- m.invoke(null, handle.asInstanceOf[Object]).asInstanceOf[Int]
- }
-
- private def query(handle: Int, name: Array[Byte]) =
- {
- val m = WindowsPreferences.getDeclaredMethod("WindowsRegQueryValueEx", INT, BYTES)
- m.setAccessible(true)
- m.invoke(null, handle.asInstanceOf[Object], name.asInstanceOf[Object]).
- asInstanceOf[Array[Byte]]
- }
-
- def query_registry(sys: Boolean, path: String, name: String): Option[String] =
- {
- val handle = if (sys) HKEY_LOCAL_MACHINE else HKEY_CURRENT_USER
- val result = open_key(handle, C_string(path), KEY_READ)
- if (result(ERROR_CODE) != 0) None
- else {
- val res = query(result(NATIVE_HANDLE), C_string(name))
- if (res == null) None
- else Some(J_string(res))
- }
- }
-
- def query_registry(path: String, name: String): Option[String] =
- query_registry(false, path, name) orElse
- query_registry(true, path, name)
-
-
/* Cygwin installation */
- private val CYGWIN_SETUP1 = "Software\\Cygwin\\setup"
- private val CYGWIN_SETUP2 = "Software\\Wow6432Node\\Cygwin\\setup"
-
private def sanity_check(root: File)
{
if (!new File(root, "bin\\bash.exe").isFile ||
@@ -93,15 +27,12 @@
def check_root(): String =
{
- val this_cygwin = System.getenv("THIS_CYGWIN")
- val cygwin_root = System.getProperty("cygwin.root")
+ val cygwin_root1 = System.getenv("CYGWIN_ROOT")
+ val cygwin_root2 = System.getProperty("cygwin.root")
val root =
- if (this_cygwin != null && this_cygwin != "") this_cygwin
- else if (cygwin_root != null && cygwin_root != "") cygwin_root
- else
- query_registry(CYGWIN_SETUP1, "rootdir") orElse
- query_registry(CYGWIN_SETUP2, "rootdir") getOrElse
- error("Failed to determine Cygwin installation -- version 1.7.x required")
+ if (cygwin_root1 != null && cygwin_root1 != "") cygwin_root1
+ else if (cygwin_root2 != null && cygwin_root2 != "") cygwin_root2
+ else error("Bad Cygwin installation: unknown root")
sanity_check(new File(root))
root
}