author | wenzelm |
Sun, 19 Jan 2025 14:23:13 +0100 (5 weeks ago) | |
changeset 81924 | 61b711122061 |
parent 81923 | 02b4ae06974d |
child 81925 | 27854cbcadf1 |
permissions | -rw-r--r-- |
81834 | 1 |
/* Title: Pure/Admin/component_hol_light.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build component for HOL-Light, with export of facts and proofs, offline |
|
5 |
optimization, and import to Isabelle/HOL. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
11 |
object Component_HOL_Light { |
|
12 |
/* resources */ |
|
13 |
||
14 |
val default_hol_light_url = "https://github.com/jrh13/hol-light.git" |
|
15 |
val default_hol_light_rev = "Release-3.0.0" |
|
16 |
||
81915
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
17 |
val hol_import_dir: Path = Path.explode("~~/src/HOL/Import") |
81834 | 18 |
|
19 |
def build_hol_light_import( |
|
20 |
only_offline: Boolean = false, |
|
21 |
progress: Progress = new Progress, |
|
22 |
target_dir: Path = Path.current, |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
23 |
load_more: List[Path] = Nil, |
81834 | 24 |
hol_light_url: String = default_hol_light_url, |
81915
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
25 |
hol_light_rev: String = default_hol_light_rev |
81834 | 26 |
): Unit = { |
27 |
/* system */ |
|
28 |
||
29 |
if (!only_offline) { |
|
30 |
Linux.check_system() |
|
31 |
Isabelle_System.require_command("patch") |
|
81920 | 32 |
Isabelle_System.require_command("zstd") |
81834 | 33 |
} |
34 |
||
35 |
||
36 |
/* component */ |
|
37 |
||
38 |
val component_name = "hol_light_import-" + Date.Format.alt_date(Date.now()) |
|
39 |
val component_dir = Components.Directory(target_dir + Path.basic(component_name)).create() |
|
40 |
||
41 |
val platform = Isabelle_Platform.self.ISABELLE_PLATFORM(windows = true, apple = true) |
|
42 |
val platform_dir = Isabelle_System.make_directory(component_dir.path + Path.basic(platform)) |
|
43 |
||
44 |
||
45 |
/* settings */ |
|
46 |
||
47 |
component_dir.write_settings(""" |
|
48 |
HOL_LIGHT_IMPORT="$COMPONENT" |
|
81921 | 49 |
HOL_LIGHT_BUNDLE="$HOL_LIGHT_IMPORT/bundle/proofs.zst" |
81834 | 50 |
HOL_LIGHT_OFFLINE="$HOL_LIGHT_IMPORT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}/offline" |
51 |
""") |
|
52 |
||
53 |
||
54 |
/* README */ |
|
55 |
||
56 |
File.write(component_dir.README, |
|
57 |
"""Author: Cezary Kaliszyk, University of Innsbruck, 2013 |
|
58 |
Author: Alexander Krauss, QAware GmbH, 2013 |
|
59 |
Author: Sophie Tourret, INRIA, 2024 |
|
60 |
Author: Stéphane Glondu, INRIA, 2024 |
|
81922 | 61 |
|
81834 | 62 |
LICENSE (export tools): BSD-3 from Isabelle |
63 |
LICENSE (HOL Light proofs): BSD-2 from HOL Light |
|
64 |
||
65 |
||
66 |
This is an export of primitive proofs from HOL Light """ + hol_light_rev + """. |
|
67 |
||
68 |
The original repository """ + hol_light_url + """ |
|
81918 | 69 |
has been patched in 2 phases. The overall export process works like this: |
81834 | 70 |
|
81915
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
71 |
cd hol-light |
81834 | 72 |
make |
73 |
||
81918 | 74 |
patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch1" |
81834 | 75 |
./ocaml-hol -I +compiler-libs stage1.ml |
76 |
||
81918 | 77 |
patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch2" |
81834 | 78 |
export MAXTMS=10000 |
79 |
./ocaml-hol -I +compiler-libs stage2.ml |
|
80 |
||
81 |
> maps.lst |
|
81915
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
82 |
"$HOL_LIGHT_IMPORT/x86_64-linux/offline" |
81834 | 83 |
|
84 |
||
85 |
Makarius |
|
86 |
""" + Date.Format.date(Date.now()) + "\n") |
|
87 |
||
88 |
||
89 |
Isabelle_System.with_tmp_dir("build") { tmp_dir => |
|
90 |
||
91 |
/* OCaml setup */ |
|
92 |
||
93 |
progress.echo("Setup OCaml ...") |
|
94 |
progress.bash( |
|
95 |
if (only_offline) "isabelle ocaml_setup_base" |
|
96 |
else "isabelle ocaml_setup && isabelle ocaml_opam install -y camlp5", |
|
97 |
echo = progress.verbose).check |
|
98 |
||
99 |
val opam_env = Isabelle_System.bash("isabelle ocaml_opam env").check.out |
|
100 |
||
101 |
||
102 |
/* "offline" tool */ |
|
103 |
||
104 |
progress.echo("Building offline tool ...") |
|
105 |
||
106 |
val offline_path = Path.explode("offline") |
|
107 |
val offline_exe = offline_path.platform_exe |
|
81915
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
108 |
val offline_dir = Isabelle_System.make_directory(tmp_dir + offline_path) |
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
109 |
|
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
110 |
Isabelle_System.copy_dir(hol_import_dir + offline_path, offline_dir, direct = true) |
81834 | 111 |
|
81915
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
112 |
progress.bash("ocamlopt offline.ml -o offline", |
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
113 |
cwd = offline_dir, echo = progress.verbose).check |
02e107686442
move material from https://gitlab.inria.fr/hol-light-isabelle/hol-light 72b2b702eadb and https://gitlab.inria.fr/hol-light-isabelle/import ce58755b0232 into Isabelle repository: results from running "isabelle component_hol_light_import" of previous version;
wenzelm
parents:
81834
diff
changeset
|
114 |
Isabelle_System.copy_file(offline_dir + offline_exe, platform_dir + offline_exe) |
81834 | 115 |
File.set_executable(platform_dir + offline_exe) |
116 |
||
117 |
||
81918 | 118 |
if (!only_offline) { |
119 |
/* clone repository */ |
|
81834 | 120 |
|
81916 | 121 |
val hol_light_dir = tmp_dir + Path.basic("hol-light") |
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
122 |
|
81916 | 123 |
Isabelle_System.git_clone(hol_light_url, hol_light_dir, checkout = hol_light_rev, |
124 |
progress = progress) |
|
125 |
||
81918 | 126 |
|
127 |
/* patches */ |
|
128 |
||
129 |
Isabelle_System.make_directory(component_dir.path + Path.basic("patches")) |
|
130 |
||
131 |
def patch(n: Int, source: Boolean = false): Path = |
|
132 |
(if (source) hol_import_dir else component_dir.path) + Path.explode("patches/patch" + n) |
|
133 |
||
134 |
for (n <- List(1, 2)) Isabelle_System.copy_file(patch(n, source = true), patch(n)) |
|
135 |
||
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
136 |
if (load_more.nonEmpty) { |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
137 |
val bad = load_more.filter(path => !(hol_light_dir + path).is_file) |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
138 |
if (bad.nonEmpty) error("Bad HOL Light files: " + bad.mkString(", ")) |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
139 |
|
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
140 |
val more = load_more.map(path => "needs " + path + ";; ").mkString("+", "", "") |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
141 |
File.change_lines(patch(1), strict = true)(_.map(line => |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
142 |
if (line == "+(*LOAD MORE*)") more else line)) |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
143 |
} |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
144 |
|
81918 | 145 |
|
146 |
/* export stages */ |
|
147 |
||
81917 | 148 |
def run(n: Int, lines: String*): Unit = { |
149 |
val title = "stage " + n |
|
150 |
if (n > 0) progress.echo("Running " + title + " ...") |
|
151 |
||
152 |
val start = Time.now() |
|
153 |
progress.bash(cat_lines("set -e" :: opam_env :: lines.toList), |
|
81918 | 154 |
cwd = hol_light_dir, echo = progress.verbose).check.timing |
81917 | 155 |
val elapsed = Time.now() - start |
156 |
||
157 |
if (n > 0) { |
|
158 |
progress.echo("Finished " + title + " (" + elapsed.message_hms + " elapsed time)") |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
run(0, "make") |
|
163 |
run(1, |
|
81918 | 164 |
"patch -p1 < " + File.bash_path(patch(1)), |
81917 | 165 |
"./ocaml-hol -I +compiler-libs stage1.ml") |
166 |
run(2, |
|
81918 | 167 |
"patch -p1 < " + File.bash_path(patch(2)), |
81917 | 168 |
"export MAXTMS=10000", |
169 |
"./ocaml-hol -I +compiler-libs stage2.ml") |
|
170 |
run(3, |
|
171 |
"> maps.lst", |
|
81920 | 172 |
File.bash_path(platform_dir + offline_exe) + " proofs", |
173 |
"zstd -8 proofs") |
|
81834 | 174 |
|
175 |
val bundle_dir = Isabelle_System.make_directory(component_dir.path + Path.explode("bundle")) |
|
81923 | 176 |
Isabelle_System.copy_file(hol_light_dir + Path.explode("facts.lst"), bundle_dir) |
81920 | 177 |
Isabelle_System.copy_file(hol_light_dir + Path.explode("proofs.zst"), bundle_dir) |
81834 | 178 |
} |
179 |
} |
|
180 |
} |
|
181 |
||
182 |
||
183 |
/* Isabelle tool wrapper */ |
|
184 |
||
185 |
val isabelle_tool = |
|
186 |
Isabelle_Tool("component_hol_light_import", "build Isabelle component for HOL Light import", |
|
187 |
Scala_Project.here, |
|
188 |
{ args => |
|
189 |
var target_dir = Path.current |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
190 |
var load_more = List.empty[Path] |
81834 | 191 |
var only_offline = false |
192 |
var hol_light_url = default_hol_light_url |
|
193 |
var hol_light_rev = default_hol_light_rev |
|
194 |
var verbose = false |
|
195 |
||
196 |
val getopts = Getopts(""" |
|
197 |
Usage: isabelle component_hol_light_import [OPTIONS] |
|
198 |
||
199 |
Options are: |
|
200 |
-D DIR target directory (default ".") |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
201 |
-L PATH load additional HOL Light files, after "hol.ml" |
81834 | 202 |
-O only build the "offline" tool |
203 |
-U URL git URL for original HOL Light repository, default: |
|
204 |
""" + default_hol_light_url + """ |
|
205 |
-r REV revision or branch to checkout HOL Light (default: """ + |
|
206 |
default_hol_light_rev + """) |
|
207 |
-v verbose |
|
208 |
||
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
209 |
Build Isabelle component for HOL Light import. For example: |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
210 |
|
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
211 |
isabelle component_hol_light_import -L Logic/make.ml |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
212 |
isabelle component_hol_light_import -L 100/thales.ml -L 100/ceva.ml |
81834 | 213 |
""", |
214 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
215 |
"L:" -> (arg => load_more = load_more ::: List(Path.explode(arg))), |
81834 | 216 |
"O" -> (_ => only_offline = true), |
217 |
"U:" -> (arg => hol_light_url = arg), |
|
218 |
"r:" -> (arg => hol_light_rev = arg), |
|
219 |
"v" -> (_ => verbose = true)) |
|
220 |
||
221 |
val more_args = getopts(args) |
|
222 |
if (more_args.nonEmpty) getopts.usage() |
|
223 |
||
224 |
val progress = new Console_Progress(verbose = verbose) |
|
225 |
||
226 |
build_hol_light_import( |
|
227 |
only_offline = only_offline, progress = progress, target_dir = target_dir, |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
228 |
load_more = load_more, hol_light_url = hol_light_url, hol_light_rev = hol_light_rev) |
81834 | 229 |
}) |
230 |
} |