equal
deleted
inserted
replaced
1 /* Title: Pure/System/isabelle_system.scala |
1 /* Title: Pure/System/isabelle_system.scala |
2 Author: Makarius |
2 Author: Makarius |
3 |
3 |
4 Fundamental Isabelle system environment: settings, symbols etc. |
4 Fundamental Isabelle system environment: quasi-static module with |
5 Quasi-static module with optional init operation. |
5 optional init operation. |
6 */ |
6 */ |
7 |
7 |
8 package isabelle |
8 package isabelle |
9 |
9 |
10 import java.lang.System |
10 import java.lang.System |
22 |
22 |
23 object Isabelle_System |
23 object Isabelle_System |
24 { |
24 { |
25 /** implicit state **/ |
25 /** implicit state **/ |
26 |
26 |
27 private case class State( |
27 private case class State(standard_system: Standard_System, settings: Map[String, String]) |
28 standard_system: Standard_System, |
|
29 settings: Map[String, String], |
|
30 symbols: Symbol.Interpretation) |
|
31 |
28 |
32 @volatile private var _state: Option[State] = None |
29 @volatile private var _state: Option[State] = None |
33 |
30 |
34 private def check_state(): State = |
31 private def check_state(): State = |
35 { |
32 { |
37 _state.get |
34 _state.get |
38 } |
35 } |
39 |
36 |
40 def standard_system: Standard_System = check_state().standard_system |
37 def standard_system: Standard_System = check_state().standard_system |
41 def settings: Map[String, String] = check_state().settings |
38 def settings: Map[String, String] = check_state().settings |
42 def symbols: Symbol.Interpretation = check_state().symbols |
|
43 |
39 |
44 /* |
40 /* |
45 isabelle_home precedence: |
41 isabelle_home precedence: |
46 (1) this_isabelle_home as explicit argument |
42 (1) this_isabelle_home as explicit argument |
47 (2) ISABELLE_HOME process environment variable (e.g. inherited from running isabelle tool) |
43 (2) ISABELLE_HOME process environment variable (e.g. inherited from running isabelle tool) |
49 */ |
45 */ |
50 def init(this_isabelle_home: String = null) = synchronized { |
46 def init(this_isabelle_home: String = null) = synchronized { |
51 if (_state.isEmpty) { |
47 if (_state.isEmpty) { |
52 import scala.collection.JavaConversions._ |
48 import scala.collection.JavaConversions._ |
53 |
49 |
|
50 System.err.println("### Isabelle system initialization") |
|
51 |
54 val standard_system = new Standard_System |
52 val standard_system = new Standard_System |
55 |
|
56 val settings = |
53 val settings = |
57 { |
54 { |
58 val env = Map(System.getenv.toList: _*) + |
55 val env = Map(System.getenv.toList: _*) + |
59 ("THIS_JAVA" -> standard_system.this_java()) |
56 ("THIS_JAVA" -> standard_system.this_java()) |
60 |
57 |
87 Map(entries: _*) + |
84 Map(entries: _*) + |
88 ("HOME" -> System.getenv("HOME")) + |
85 ("HOME" -> System.getenv("HOME")) + |
89 ("PATH" -> System.getenv("PATH")) |
86 ("PATH" -> System.getenv("PATH")) |
90 } |
87 } |
91 } |
88 } |
92 |
89 _state = Some(State(standard_system, settings)) |
93 val symbols = |
|
94 { |
|
95 val isabelle_symbols = settings.getOrElse("ISABELLE_SYMBOLS", "") |
|
96 if (isabelle_symbols == "") error("Undefined environment variable: ISABELLE_SYMBOLS") |
|
97 val files = |
|
98 Path.split(isabelle_symbols).map(p => new File(standard_system.jvm_path(p.implode))) |
|
99 new Symbol.Interpretation(split_lines(Standard_System.try_read(files))) |
|
100 } |
|
101 |
|
102 _state = Some(State(standard_system, settings, symbols)) |
|
103 } |
90 } |
104 } |
91 } |
105 |
92 |
106 |
93 |
107 /* getenv */ |
94 /* getenv */ |