author | wenzelm |
Sat, 18 Jan 2025 23:19:23 +0100 | |
changeset 81920 | 8d5989ab1e42 |
parent 81918 | deb6cb34a37f |
child 81921 | 86e3ad5034a1 |
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, |
|
23 |
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
|
24 |
hol_light_rev: String = default_hol_light_rev |
81834 | 25 |
): Unit = { |
26 |
/* system */ |
|
27 |
||
28 |
if (!only_offline) { |
|
29 |
Linux.check_system() |
|
30 |
Isabelle_System.require_command("patch") |
|
81920 | 31 |
Isabelle_System.require_command("zstd") |
81834 | 32 |
} |
33 |
||
34 |
||
35 |
/* component */ |
|
36 |
||
37 |
val component_name = "hol_light_import-" + Date.Format.alt_date(Date.now()) |
|
38 |
val component_dir = Components.Directory(target_dir + Path.basic(component_name)).create() |
|
39 |
||
40 |
val platform = Isabelle_Platform.self.ISABELLE_PLATFORM(windows = true, apple = true) |
|
41 |
val platform_dir = Isabelle_System.make_directory(component_dir.path + Path.basic(platform)) |
|
42 |
||
43 |
||
44 |
/* settings */ |
|
45 |
||
46 |
component_dir.write_settings(""" |
|
47 |
HOL_LIGHT_IMPORT="$COMPONENT" |
|
48 |
HOL_LIGTH_BUNDLE="$HOL_LIGHT_IMPORT/bundle/proofs" |
|
49 |
HOL_LIGHT_OFFLINE="$HOL_LIGHT_IMPORT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}/offline" |
|
50 |
""") |
|
51 |
||
52 |
||
53 |
/* README */ |
|
54 |
||
55 |
File.write(component_dir.README, |
|
56 |
"""Author: Cezary Kaliszyk, University of Innsbruck, 2013 |
|
57 |
Author: Alexander Krauss, QAware GmbH, 2013 |
|
58 |
Author: Sophie Tourret, INRIA, 2024 |
|
59 |
Author: Stéphane Glondu, INRIA, 2024 |
|
60 |
LICENSE (export tools): BSD-3 from Isabelle |
|
61 |
LICENSE (HOL Light proofs): BSD-2 from HOL Light |
|
62 |
||
63 |
||
64 |
This is an export of primitive proofs from HOL Light """ + hol_light_rev + """. |
|
65 |
||
66 |
The original repository """ + hol_light_url + """ |
|
81918 | 67 |
has been patched in 2 phases. The overall export process works like this: |
81834 | 68 |
|
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
|
69 |
cd hol-light |
81834 | 70 |
make |
71 |
||
81918 | 72 |
patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch1" |
81834 | 73 |
./ocaml-hol -I +compiler-libs stage1.ml |
74 |
||
81918 | 75 |
patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch2" |
81834 | 76 |
export MAXTMS=10000 |
77 |
./ocaml-hol -I +compiler-libs stage2.ml |
|
78 |
||
79 |
> 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
|
80 |
"$HOL_LIGHT_IMPORT/x86_64-linux/offline" |
81834 | 81 |
|
82 |
||
83 |
Makarius |
|
84 |
""" + Date.Format.date(Date.now()) + "\n") |
|
85 |
||
86 |
||
87 |
Isabelle_System.with_tmp_dir("build") { tmp_dir => |
|
88 |
||
89 |
/* OCaml setup */ |
|
90 |
||
91 |
progress.echo("Setup OCaml ...") |
|
92 |
progress.bash( |
|
93 |
if (only_offline) "isabelle ocaml_setup_base" |
|
94 |
else "isabelle ocaml_setup && isabelle ocaml_opam install -y camlp5", |
|
95 |
echo = progress.verbose).check |
|
96 |
||
97 |
val opam_env = Isabelle_System.bash("isabelle ocaml_opam env").check.out |
|
98 |
||
99 |
||
100 |
/* "offline" tool */ |
|
101 |
||
102 |
progress.echo("Building offline tool ...") |
|
103 |
||
104 |
val offline_path = Path.explode("offline") |
|
105 |
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
|
106 |
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
|
107 |
|
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 |
Isabelle_System.copy_dir(hol_import_dir + offline_path, offline_dir, direct = true) |
81834 | 109 |
|
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
|
110 |
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
|
111 |
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
|
112 |
Isabelle_System.copy_file(offline_dir + offline_exe, platform_dir + offline_exe) |
81834 | 113 |
File.set_executable(platform_dir + offline_exe) |
114 |
||
115 |
||
81918 | 116 |
if (!only_offline) { |
117 |
/* clone repository */ |
|
81834 | 118 |
|
81916 | 119 |
val hol_light_dir = tmp_dir + Path.basic("hol-light") |
120 |
Isabelle_System.git_clone(hol_light_url, hol_light_dir, checkout = hol_light_rev, |
|
121 |
progress = progress) |
|
122 |
||
81918 | 123 |
|
124 |
/* patches */ |
|
125 |
||
126 |
Isabelle_System.make_directory(component_dir.path + Path.basic("patches")) |
|
127 |
||
128 |
def patch(n: Int, source: Boolean = false): Path = |
|
129 |
(if (source) hol_import_dir else component_dir.path) + Path.explode("patches/patch" + n) |
|
130 |
||
131 |
for (n <- List(1, 2)) Isabelle_System.copy_file(patch(n, source = true), patch(n)) |
|
132 |
||
133 |
||
134 |
/* export stages */ |
|
135 |
||
81917 | 136 |
def run(n: Int, lines: String*): Unit = { |
137 |
val title = "stage " + n |
|
138 |
if (n > 0) progress.echo("Running " + title + " ...") |
|
139 |
||
140 |
val start = Time.now() |
|
141 |
progress.bash(cat_lines("set -e" :: opam_env :: lines.toList), |
|
81918 | 142 |
cwd = hol_light_dir, echo = progress.verbose).check.timing |
81917 | 143 |
val elapsed = Time.now() - start |
144 |
||
145 |
if (n > 0) { |
|
146 |
progress.echo("Finished " + title + " (" + elapsed.message_hms + " elapsed time)") |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
run(0, "make") |
|
151 |
run(1, |
|
81918 | 152 |
"patch -p1 < " + File.bash_path(patch(1)), |
81917 | 153 |
"./ocaml-hol -I +compiler-libs stage1.ml") |
154 |
run(2, |
|
81918 | 155 |
"patch -p1 < " + File.bash_path(patch(2)), |
81917 | 156 |
"export MAXTMS=10000", |
157 |
"./ocaml-hol -I +compiler-libs stage2.ml") |
|
158 |
run(3, |
|
159 |
"> maps.lst", |
|
81920 | 160 |
File.bash_path(platform_dir + offline_exe) + " proofs", |
161 |
"zstd -8 proofs") |
|
81834 | 162 |
|
163 |
val bundle_dir = Isabelle_System.make_directory(component_dir.path + Path.explode("bundle")) |
|
81920 | 164 |
Isabelle_System.copy_file(hol_light_dir + Path.explode("proofs.zst"), bundle_dir) |
81834 | 165 |
} |
166 |
} |
|
167 |
} |
|
168 |
||
169 |
||
170 |
/* Isabelle tool wrapper */ |
|
171 |
||
172 |
val isabelle_tool = |
|
173 |
Isabelle_Tool("component_hol_light_import", "build Isabelle component for HOL Light import", |
|
174 |
Scala_Project.here, |
|
175 |
{ args => |
|
176 |
var target_dir = Path.current |
|
177 |
var only_offline = false |
|
178 |
var hol_light_url = default_hol_light_url |
|
179 |
var hol_light_rev = default_hol_light_rev |
|
180 |
var verbose = false |
|
181 |
||
182 |
val getopts = Getopts(""" |
|
183 |
Usage: isabelle component_hol_light_import [OPTIONS] |
|
184 |
||
185 |
Options are: |
|
186 |
-D DIR target directory (default ".") |
|
187 |
-O only build the "offline" tool |
|
188 |
-U URL git URL for original HOL Light repository, default: |
|
189 |
""" + default_hol_light_url + """ |
|
190 |
-r REV revision or branch to checkout HOL Light (default: """ + |
|
191 |
default_hol_light_rev + """) |
|
192 |
-v verbose |
|
193 |
||
194 |
Build Isabelle component for HOL Light import. |
|
195 |
""", |
|
196 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
197 |
"O" -> (_ => only_offline = true), |
|
198 |
"U:" -> (arg => hol_light_url = arg), |
|
199 |
"r:" -> (arg => hol_light_rev = arg), |
|
200 |
"v" -> (_ => verbose = true)) |
|
201 |
||
202 |
val more_args = getopts(args) |
|
203 |
if (more_args.nonEmpty) getopts.usage() |
|
204 |
||
205 |
val progress = new Console_Progress(verbose = verbose) |
|
206 |
||
207 |
build_hol_light_import( |
|
208 |
only_offline = only_offline, progress = progress, target_dir = target_dir, |
|
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
|
209 |
hol_light_url = hol_light_url, hol_light_rev = hol_light_rev) |
81834 | 210 |
}) |
211 |
} |