author | wenzelm |
Wed, 12 Mar 2025 11:39:00 +0100 | |
changeset 82265 | 4b875a4c83b0 |
parent 81971 | bd8e174b6f95 |
child 82610 | 3133f9748ea8 |
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 |
||
81928 | 14 |
val hol_import_dir: Path = Path.explode("~~/src/HOL/Import") |
15 |
def default_maps: Path = hol_import_dir + Path.explode("offline/maps.lst") |
|
16 |
||
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
17 |
def bundle_contents(preserve_raw: Boolean = false): List[String] = |
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
18 |
List("facts.lstN", "maps.lst", "proofsN.zst") ::: |
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
19 |
(if (preserve_raw) List("facts.lst", "proofs") else Nil) |
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
20 |
|
81834 | 21 |
val default_hol_light_url = "https://github.com/jrh13/hol-light.git" |
22 |
val default_hol_light_rev = "Release-3.0.0" |
|
23 |
||
24 |
def build_hol_light_import( |
|
25 |
only_offline: Boolean = false, |
|
26 |
progress: Progress = new Progress, |
|
27 |
target_dir: Path = Path.current, |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
28 |
load_more: List[Path] = Nil, |
81928 | 29 |
maps: Option[Path] = Some(default_maps), |
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
30 |
preserve_raw: Boolean = false, |
81834 | 31 |
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
|
32 |
hol_light_rev: String = default_hol_light_rev |
81834 | 33 |
): Unit = { |
34 |
/* system */ |
|
35 |
||
36 |
if (!only_offline) { |
|
37 |
Linux.check_system() |
|
81971 | 38 |
Isabelle_System.require_command("bzip2") |
39 |
Isabelle_System.require_command("m4") |
|
81834 | 40 |
Isabelle_System.require_command("patch") |
81920 | 41 |
Isabelle_System.require_command("zstd") |
81834 | 42 |
} |
43 |
||
44 |
||
45 |
/* component */ |
|
46 |
||
47 |
val component_name = "hol_light_import-" + Date.Format.alt_date(Date.now()) |
|
81927 | 48 |
val component_dir = |
49 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) |
|
81834 | 50 |
|
51 |
val platform = Isabelle_Platform.self.ISABELLE_PLATFORM(windows = true, apple = true) |
|
52 |
val platform_dir = Isabelle_System.make_directory(component_dir.path + Path.basic(platform)) |
|
53 |
||
54 |
||
55 |
/* settings */ |
|
56 |
||
57 |
component_dir.write_settings(""" |
|
58 |
HOL_LIGHT_IMPORT="$COMPONENT" |
|
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
59 |
HOL_LIGHT_BUNDLE="$HOL_LIGHT_IMPORT/bundle/proofsN.zst" |
81834 | 60 |
HOL_LIGHT_OFFLINE="$HOL_LIGHT_IMPORT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}/offline" |
61 |
""") |
|
62 |
||
63 |
||
64 |
/* README */ |
|
65 |
||
66 |
File.write(component_dir.README, |
|
67 |
"""Author: Cezary Kaliszyk, University of Innsbruck, 2013 |
|
68 |
Author: Alexander Krauss, QAware GmbH, 2013 |
|
69 |
Author: Sophie Tourret, INRIA, 2024 |
|
70 |
Author: Stéphane Glondu, INRIA, 2024 |
|
81922 | 71 |
|
81834 | 72 |
LICENSE (export tools): BSD-3 from Isabelle |
73 |
LICENSE (HOL Light proofs): BSD-2 from HOL Light |
|
74 |
||
75 |
||
76 |
This is an export of primitive proofs from HOL Light """ + hol_light_rev + """. |
|
77 |
||
78 |
The original repository """ + hol_light_url + """ |
|
81918 | 79 |
has been patched in 2 phases. The overall export process works like this: |
81834 | 80 |
|
81925 | 81 |
isabelle ocaml_setup |
82 |
isabelle ocaml_opam install -y camlp5 |
|
83 |
eval $(isabelle ocaml_opam env) |
|
84 |
||
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
|
85 |
cd hol-light |
81834 | 86 |
make |
87 |
||
81918 | 88 |
patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch1" |
81834 | 89 |
./ocaml-hol -I +compiler-libs stage1.ml |
90 |
||
81918 | 91 |
patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch2" |
81834 | 92 |
export MAXTMS=10000 |
93 |
./ocaml-hol -I +compiler-libs stage2.ml |
|
94 |
||
81928 | 95 |
cp "$HOL_LIGHT_IMPORT/bundle/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
|
96 |
"$HOL_LIGHT_IMPORT/x86_64-linux/offline" |
81834 | 97 |
|
98 |
||
99 |
Makarius |
|
100 |
""" + Date.Format.date(Date.now()) + "\n") |
|
101 |
||
102 |
||
103 |
Isabelle_System.with_tmp_dir("build") { tmp_dir => |
|
104 |
||
105 |
/* OCaml setup */ |
|
106 |
||
107 |
progress.echo("Setup OCaml ...") |
|
108 |
progress.bash( |
|
109 |
if (only_offline) "isabelle ocaml_setup_base" |
|
110 |
else "isabelle ocaml_setup && isabelle ocaml_opam install -y camlp5", |
|
111 |
echo = progress.verbose).check |
|
112 |
||
113 |
val opam_env = Isabelle_System.bash("isabelle ocaml_opam env").check.out |
|
114 |
||
115 |
||
116 |
/* "offline" tool */ |
|
117 |
||
118 |
progress.echo("Building offline tool ...") |
|
119 |
||
120 |
val offline_path = Path.explode("offline") |
|
121 |
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
|
122 |
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
|
123 |
|
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
|
124 |
Isabelle_System.copy_dir(hol_import_dir + offline_path, offline_dir, direct = true) |
81834 | 125 |
|
81970
6a2f889fa3b9
proper executable from "isabelle ocaml_opam env";
wenzelm
parents:
81930
diff
changeset
|
126 |
progress.bash("ocamlc.opt offline.ml -o offline", |
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
|
127 |
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
|
128 |
Isabelle_System.copy_file(offline_dir + offline_exe, platform_dir + offline_exe) |
81834 | 129 |
File.set_executable(platform_dir + offline_exe) |
130 |
||
131 |
||
81918 | 132 |
if (!only_offline) { |
133 |
/* clone repository */ |
|
81834 | 134 |
|
81916 | 135 |
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
|
136 |
|
81916 | 137 |
Isabelle_System.git_clone(hol_light_url, hol_light_dir, checkout = hol_light_rev, |
138 |
progress = progress) |
|
139 |
||
81918 | 140 |
|
141 |
/* patches */ |
|
142 |
||
143 |
Isabelle_System.make_directory(component_dir.path + Path.basic("patches")) |
|
144 |
||
145 |
def patch(n: Int, source: Boolean = false): Path = |
|
146 |
(if (source) hol_import_dir else component_dir.path) + Path.explode("patches/patch" + n) |
|
147 |
||
148 |
for (n <- List(1, 2)) Isabelle_System.copy_file(patch(n, source = true), patch(n)) |
|
149 |
||
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
150 |
if (load_more.nonEmpty) { |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
|
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
if (line == "+(*LOAD MORE*)") more else line)) |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
157 |
} |
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
158 |
|
81918 | 159 |
|
160 |
/* export stages */ |
|
161 |
||
81917 | 162 |
def run(n: Int, lines: String*): Unit = { |
163 |
val title = "stage " + n |
|
164 |
if (n > 0) progress.echo("Running " + title + " ...") |
|
165 |
||
166 |
val start = Time.now() |
|
167 |
progress.bash(cat_lines("set -e" :: opam_env :: lines.toList), |
|
81918 | 168 |
cwd = hol_light_dir, echo = progress.verbose).check.timing |
81917 | 169 |
val elapsed = Time.now() - start |
170 |
||
171 |
if (n > 0) { |
|
172 |
progress.echo("Finished " + title + " (" + elapsed.message_hms + " elapsed time)") |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
run(0, "make") |
|
177 |
run(1, |
|
81918 | 178 |
"patch -p1 < " + File.bash_path(patch(1)), |
81917 | 179 |
"./ocaml-hol -I +compiler-libs stage1.ml") |
180 |
run(2, |
|
81918 | 181 |
"patch -p1 < " + File.bash_path(patch(2)), |
81917 | 182 |
"export MAXTMS=10000", |
183 |
"./ocaml-hol -I +compiler-libs stage2.ml") |
|
81928 | 184 |
|
185 |
Bytes.write(hol_light_dir + Path.explode("maps.lst"), |
|
186 |
if (maps.isEmpty) Bytes.empty else Bytes.read(maps.get)) |
|
187 |
||
81917 | 188 |
run(3, |
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
189 |
File.bash_path(platform_dir + offline_exe), |
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
190 |
"zstd -8 proofsN") |
81834 | 191 |
|
192 |
val bundle_dir = Isabelle_System.make_directory(component_dir.path + Path.explode("bundle")) |
|
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
193 |
for (name <- bundle_contents(preserve_raw = preserve_raw)) { |
81928 | 194 |
Isabelle_System.copy_file(hol_light_dir + Path.explode(name), bundle_dir) |
195 |
} |
|
81834 | 196 |
} |
197 |
} |
|
198 |
} |
|
199 |
||
200 |
||
201 |
/* Isabelle tool wrapper */ |
|
202 |
||
203 |
val isabelle_tool = |
|
204 |
Isabelle_Tool("component_hol_light_import", "build Isabelle component for HOL Light import", |
|
205 |
Scala_Project.here, |
|
206 |
{ args => |
|
207 |
var target_dir = Path.current |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
208 |
var load_more = List.empty[Path] |
81928 | 209 |
var maps: Option[Path] = Some(default_maps) |
81834 | 210 |
var only_offline = false |
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
211 |
var preserve_raw = false |
81834 | 212 |
var hol_light_url = default_hol_light_url |
213 |
var hol_light_rev = default_hol_light_rev |
|
214 |
var verbose = false |
|
215 |
||
216 |
val getopts = Getopts(""" |
|
217 |
Usage: isabelle component_hol_light_import [OPTIONS] |
|
218 |
||
219 |
Options are: |
|
220 |
-D DIR target directory (default ".") |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
221 |
-L PATH load additional HOL Light files, after "hol.ml" |
81928 | 222 |
-M PATH alternative maps.lst for offline alignment of facts |
223 |
("." means empty, default: """ + default_maps + """) |
|
81834 | 224 |
-O only build the "offline" tool |
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
225 |
-P preserve raw proofs, before offline alignment of facts |
81834 | 226 |
-U URL git URL for original HOL Light repository, default: |
227 |
""" + default_hol_light_url + """ |
|
228 |
-r REV revision or branch to checkout HOL Light (default: """ + |
|
229 |
default_hol_light_rev + """) |
|
230 |
-v verbose |
|
231 |
||
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
232 |
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
|
233 |
|
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
234 |
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
|
235 |
isabelle component_hol_light_import -L 100/thales.ml -L 100/ceva.ml |
81971 | 236 |
|
237 |
The HOL Light build process uses OCaml/OPAM from Isabelle; this requires |
|
238 |
C development tools with libgmp-dev. |
|
81834 | 239 |
""", |
240 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
81924
61b711122061
allow to load additional HOL Light files, after "hol.ml";
wenzelm
parents:
81923
diff
changeset
|
241 |
"L:" -> (arg => load_more = load_more ::: List(Path.explode(arg))), |
81928 | 242 |
"M:" -> (arg => maps = if (arg == ".") None else Some(Path.explode(arg))), |
81834 | 243 |
"O" -> (_ => only_offline = true), |
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
244 |
"P" -> (_ => preserve_raw = true), |
81834 | 245 |
"U:" -> (arg => hol_light_url = arg), |
246 |
"r:" -> (arg => hol_light_rev = arg), |
|
247 |
"v" -> (_ => verbose = true)) |
|
248 |
||
249 |
val more_args = getopts(args) |
|
250 |
if (more_args.nonEmpty) getopts.usage() |
|
251 |
||
252 |
val progress = new Console_Progress(verbose = verbose) |
|
253 |
||
254 |
build_hol_light_import( |
|
255 |
only_offline = only_offline, progress = progress, target_dir = target_dir, |
|
81930
8c8726e82b71
clarified bundle names, in terms of the "offline" tool;
wenzelm
parents:
81929
diff
changeset
|
256 |
load_more = load_more, maps = maps, preserve_raw = preserve_raw, |
81928 | 257 |
hol_light_url = hol_light_url, hol_light_rev = hol_light_rev) |
81834 | 258 |
}) |
259 |
} |