author | wenzelm |
Sat, 07 Sep 2013 17:11:44 +0200 | |
changeset 53459 | 33f773731f0c |
parent 53452 | 8181bc357dc4 |
child 53460 | 6015a663b889 |
permissions | -rw-r--r-- |
52667 | 1 |
/* Title: Pure/System/cygwin_init.scala |
52553 | 2 |
Author: Makarius |
3 |
||
53459 | 4 |
Initialize raw Isabelle distribution (e.g. after extraction via 7zip). |
52553 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
52667 | 10 |
import java.io.{File => JFile, BufferedReader, InputStreamReader} |
53459 | 11 |
import java.nio.file.Files |
52667 | 12 |
|
52669
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
13 |
import scala.annotation.tailrec |
52553 | 14 |
|
15 |
||
52667 | 16 |
object Cygwin_Init |
52553 | 17 |
{ |
53459 | 18 |
def filesystem(system_dialog: System_Dialog, isabelle_home: String) |
52667 | 19 |
{ |
53459 | 20 |
system_dialog.title("Isabelle system initialization") |
21 |
system_dialog.echo("Initializing Cygwin:") |
|
53423
b5a279c7d7f3
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents:
53419
diff
changeset
|
22 |
|
52672 | 23 |
def execute(args: String*): Int = |
24 |
{ |
|
25 |
val cwd = new JFile(isabelle_home) |
|
26 |
val env = Map("CYGWIN" -> "nodosfilewarning") |
|
27 |
val proc = Isabelle_System.raw_execute(cwd, env, true, args: _*) |
|
28 |
proc.getOutputStream.close |
|
29 |
||
30 |
val stdout = new BufferedReader(new InputStreamReader(proc.getInputStream, UTF8.charset)) |
|
31 |
try { |
|
32 |
var line = stdout.readLine |
|
33 |
while (line != null) { |
|
53459 | 34 |
system_dialog.echo(line) |
52672 | 35 |
line = stdout.readLine |
36 |
} |
|
37 |
} |
|
38 |
finally { stdout.close } |
|
39 |
||
40 |
proc.waitFor |
|
41 |
} |
|
42 |
||
53459 | 43 |
val cygwin_root = isabelle_home + "\\contrib\\cygwin" |
52669
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
44 |
|
53459 | 45 |
system_dialog.echo("symlinks ...") |
52669
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
46 |
val symlinks = |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
47 |
{ |
53423
b5a279c7d7f3
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents:
53419
diff
changeset
|
48 |
val path = (new JFile(cygwin_root + "\\isabelle\\symlinks")).toPath |
52669
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
49 |
Files.readAllLines(path, UTF8.charset).toArray.toList.asInstanceOf[List[String]] |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
50 |
} |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
51 |
@tailrec def recover_symlinks(list: List[String]): Unit = |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
52 |
{ |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
53 |
list match { |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
54 |
case Nil | List("") => |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
55 |
case link :: content :: rest => |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
56 |
val path = (new JFile(isabelle_home, link)).toPath |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
57 |
|
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
58 |
val writer = Files.newBufferedWriter(path, UTF8.charset) |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
59 |
try { writer.write("!<symlink>" + content + "\0") } |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
60 |
finally { writer.close } |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
61 |
|
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
62 |
Files.setAttribute(path, "dos:system", true) |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
63 |
|
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
64 |
recover_symlinks(rest) |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
65 |
case _ => error("Unbalanced symlinks list") |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
66 |
} |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
67 |
} |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
68 |
recover_symlinks(symlinks) |
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
69 |
|
53459 | 70 |
system_dialog.echo("rebaseall ...") |
53423
b5a279c7d7f3
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents:
53419
diff
changeset
|
71 |
execute(cygwin_root + "\\bin\\dash.exe", "/isabelle/rebaseall") |
52669
fb59e6e9442a
recover Cygwin symlinks via Windows file-system operations;
wenzelm
parents:
52667
diff
changeset
|
72 |
|
53459 | 73 |
system_dialog.echo("postinstall ...") |
53423
b5a279c7d7f3
more explicit cygwin_root (again) -- do not rely on isabelle_home as cwd;
wenzelm
parents:
53419
diff
changeset
|
74 |
execute(cygwin_root + "\\bin\\bash.exe", "/isabelle/postinstall") |
52672 | 75 |
|
53459 | 76 |
system_dialog.echo("init ...") |
52672 | 77 |
Isabelle_System.init() |
53459 | 78 |
system_dialog.echo("OK") |
52667 | 79 |
} |
52553 | 80 |
} |
81 |