author | wenzelm |
Tue, 24 Jan 2023 14:46:51 +0100 | |
changeset 77069 | 348f4d95d110 |
parent 77055 | f56800b8b085 |
child 77071 | 7a89ef6b0276 |
permissions | -rw-r--r-- |
64188 | 1 |
/* Title: Pure/Admin/other_isabelle.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Manage other Isabelle distributions. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
75393 | 10 |
object Other_Isabelle { |
77050 | 11 |
def apply( |
12 |
isabelle_home: Path, |
|
13 |
isabelle_identifier: String = "", |
|
14 |
user_home: Path = Path.USER_HOME, |
|
15 |
progress: Progress = new Progress |
|
16 |
): Other_Isabelle = { |
|
69408
fb26935838c7
more robust, notably for macos /var vs. /private/var;
wenzelm
parents:
69404
diff
changeset
|
17 |
new Other_Isabelle(isabelle_home.canonical, isabelle_identifier, user_home, progress) |
77050 | 18 |
} |
67045 | 19 |
} |
20 |
||
77041 | 21 |
final class Other_Isabelle private( |
67045 | 22 |
val isabelle_home: Path, |
23 |
val isabelle_identifier: String, |
|
67046 | 24 |
user_home: Path, |
75393 | 25 |
progress: Progress |
26 |
) { |
|
64188 | 27 |
other_isabelle => |
28 |
||
69404
de88761edbe2
clarified absolute isabelle_home and (implicitly) isabelle_home_user;
wenzelm
parents:
69401
diff
changeset
|
29 |
override def toString: String = isabelle_home.toString |
67046 | 30 |
|
77042 | 31 |
if (proper_string(System.getenv("ISABELLE_SETTINGS_PRESENT")).isDefined) { |
67046 | 32 |
error("Cannot initialize with enclosing ISABELLE_SETTINGS_PRESENT") |
77042 | 33 |
} |
67046 | 34 |
|
64188 | 35 |
|
36 |
/* static system */ |
|
37 |
||
65930 | 38 |
def bash( |
77042 | 39 |
script: String, |
40 |
redirect: Boolean = false, |
|
41 |
echo: Boolean = false, |
|
42 |
strict: Boolean = true |
|
43 |
): Process_Result = { |
|
67046 | 44 |
progress.bash( |
45 |
"export USER_HOME=" + File.bash_path(user_home) + "\n" + |
|
46 |
Isabelle_System.export_isabelle_identifier(isabelle_identifier) + script, |
|
65930 | 47 |
env = null, cwd = isabelle_home.file, redirect = redirect, echo = echo, strict = strict) |
77042 | 48 |
} |
64188 | 49 |
|
69166 | 50 |
def getenv(name: String): String = |
77044 | 51 |
other_isabelle.bash("bin/isabelle getenv -b " + Bash.string(name)).check.out |
69166 | 52 |
|
53 |
val isabelle_home_user: Path = Path.explode(getenv("ISABELLE_HOME_USER")) |
|
64188 | 54 |
|
68754 | 55 |
val etc: Path = isabelle_home_user + Path.explode("etc") |
56 |
val etc_settings: Path = etc + Path.explode("settings") |
|
57 |
val etc_preferences: Path = etc + Path.explode("preferences") |
|
64188 | 58 |
|
77069
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
59 |
def resolve_components(echo: Boolean): Unit = { |
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
60 |
val missing = Path.split(getenv("ISABELLE_COMPONENTS_MISSING")) |
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
61 |
for (path <- missing) { |
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
62 |
Components.resolve(path.dir, path.file_name, progress = if (echo) progress else new Progress) |
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
63 |
} |
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
64 |
} |
348f4d95d110
more robust (see also 7f55a3e28c88): resolve components from current Isabelle context, using Isabelle/Scala instead of shell scripts;
wenzelm
parents:
77055
diff
changeset
|
65 |
|
73625
f8f065e20837
misc tuning and clarification: more explicit types Release_Context, Release_Archive;
wenzelm
parents:
73522
diff
changeset
|
66 |
|
69388 | 67 |
/* components */ |
68 |
||
69 |
def init_components( |
|
73240
3e963d68d394
more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents:
72375
diff
changeset
|
70 |
component_repository: String = Components.default_component_repository, |
69434 | 71 |
components_base: Path = Components.default_components_base, |
77055 | 72 |
catalogs: List[String] = Components.default_catalogs, |
75393 | 73 |
components: List[String] = Nil |
74 |
): List[String] = { |
|
69404
de88761edbe2
clarified absolute isabelle_home and (implicitly) isabelle_home_user;
wenzelm
parents:
69401
diff
changeset
|
75 |
val dir = Components.admin(isabelle_home) |
73240
3e963d68d394
more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents:
72375
diff
changeset
|
76 |
|
3e963d68d394
more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents:
72375
diff
changeset
|
77 |
("ISABELLE_COMPONENT_REPOSITORY=" + Bash.string(component_repository)) :: |
69396 | 78 |
catalogs.map(name => |
69434 | 79 |
"init_components " + File.bash_path(components_base) + " " + |
80 |
File.bash_path(dir + Path.basic(name))) ::: |
|
69396 | 81 |
components.map(name => |
69434 | 82 |
"init_component " + File.bash_path(components_base + Path.basic(name))) |
69388 | 83 |
} |
84 |
||
85 |
||
69168
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
86 |
/* settings */ |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
87 |
|
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
88 |
def clean_settings(): Boolean = |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
89 |
if (!etc_settings.is_file) true |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
90 |
else if (File.read(etc_settings).startsWith("# generated by Isabelle")) { |
77042 | 91 |
etc_settings.file.delete |
92 |
true |
|
69168
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
93 |
} |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
94 |
else false |
64188 | 95 |
|
75393 | 96 |
def init_settings(settings: List[String]): Unit = { |
77042 | 97 |
if (!clean_settings()) { |
64188 | 98 |
error("Cannot proceed with existing user settings file: " + etc_settings) |
77042 | 99 |
} |
64188 | 100 |
|
72375 | 101 |
Isabelle_System.make_directory(etc_settings.dir) |
64188 | 102 |
File.write(etc_settings, |
103 |
"# generated by Isabelle " + Date.now() + "\n" + |
|
69388 | 104 |
"#-*- shell-script -*- :mode=shellscript:\n" + |
105 |
settings.mkString("\n", "\n", "\n")) |
|
64188 | 106 |
} |
69168
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
107 |
|
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
108 |
|
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
109 |
/* cleanup */ |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
110 |
|
75393 | 111 |
def cleanup(): Unit = { |
69168
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
112 |
clean_settings() |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
113 |
etc.file.delete |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
114 |
isabelle_home_user.file.delete |
68816d1c73a7
eliminated "isabelle makedist" -- prefer Scala over bash/perl scripting;
wenzelm
parents:
69166
diff
changeset
|
115 |
} |
64188 | 116 |
} |