author | wenzelm |
Sat, 18 Jan 2025 22:29:47 +0100 | |
changeset 81918 | deb6cb34a37f |
parent 81917 | 50cd5037aff7 |
child 81920 | 8d5989ab1e42 |
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("buffer", test = "-i /dev/null") |
|
31 |
Isabelle_System.require_command("patch") |
|
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 |
gzip -d proofs.gz |
|
80 |
> 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
|
81 |
"$HOL_LIGHT_IMPORT/x86_64-linux/offline" |
81834 | 82 |
|
83 |
||
84 |
Makarius |
|
85 |
""" + Date.Format.date(Date.now()) + "\n") |
|
86 |
||
87 |
||
88 |
Isabelle_System.with_tmp_dir("build") { tmp_dir => |
|
89 |
||
90 |
/* OCaml setup */ |
|
91 |
||
92 |
progress.echo("Setup OCaml ...") |
|
93 |
progress.bash( |
|
94 |
if (only_offline) "isabelle ocaml_setup_base" |
|
95 |
else "isabelle ocaml_setup && isabelle ocaml_opam install -y camlp5", |
|
96 |
echo = progress.verbose).check |
|
97 |
||
98 |
val opam_env = Isabelle_System.bash("isabelle ocaml_opam env").check.out |
|
99 |
||
100 |
||
101 |
/* "offline" tool */ |
|
102 |
||
103 |
progress.echo("Building offline tool ...") |
|
104 |
||
105 |
val offline_path = Path.explode("offline") |
|
106 |
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
|
107 |
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
|
108 |
|
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 |
Isabelle_System.copy_dir(hol_import_dir + offline_path, offline_dir, direct = true) |
81834 | 110 |
|
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
|
111 |
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
|
112 |
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
|
113 |
Isabelle_System.copy_file(offline_dir + offline_exe, platform_dir + offline_exe) |
81834 | 114 |
File.set_executable(platform_dir + offline_exe) |
115 |
||
116 |
||
81918 | 117 |
if (!only_offline) { |
118 |
/* clone repository */ |
|
81834 | 119 |
|
81916 | 120 |
val hol_light_dir = tmp_dir + Path.basic("hol-light") |
121 |
Isabelle_System.git_clone(hol_light_url, hol_light_dir, checkout = hol_light_rev, |
|
122 |
progress = progress) |
|
123 |
||
81918 | 124 |
|
125 |
/* patches */ |
|
126 |
||
127 |
Isabelle_System.make_directory(component_dir.path + Path.basic("patches")) |
|
128 |
||
129 |
def patch(n: Int, source: Boolean = false): Path = |
|
130 |
(if (source) hol_import_dir else component_dir.path) + Path.explode("patches/patch" + n) |
|
131 |
||
132 |
for (n <- List(1, 2)) Isabelle_System.copy_file(patch(n, source = true), patch(n)) |
|
133 |
||
134 |
||
135 |
/* export stages */ |
|
136 |
||
81917 | 137 |
def run(n: Int, lines: String*): Unit = { |
138 |
val title = "stage " + n |
|
139 |
if (n > 0) progress.echo("Running " + title + " ...") |
|
140 |
||
141 |
val start = Time.now() |
|
142 |
progress.bash(cat_lines("set -e" :: opam_env :: lines.toList), |
|
81918 | 143 |
cwd = hol_light_dir, echo = progress.verbose).check.timing |
81917 | 144 |
val elapsed = Time.now() - start |
145 |
||
146 |
if (n > 0) { |
|
147 |
progress.echo("Finished " + title + " (" + elapsed.message_hms + " elapsed time)") |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
run(0, "make") |
|
152 |
run(1, |
|
81918 | 153 |
"patch -p1 < " + File.bash_path(patch(1)), |
81917 | 154 |
"./ocaml-hol -I +compiler-libs stage1.ml") |
155 |
run(2, |
|
81918 | 156 |
"patch -p1 < " + File.bash_path(patch(2)), |
81917 | 157 |
"export MAXTMS=10000", |
158 |
"./ocaml-hol -I +compiler-libs stage2.ml") |
|
159 |
run(3, |
|
160 |
"gzip -d proofs.gz", |
|
161 |
"> maps.lst", |
|
162 |
File.bash_path(platform_dir + offline_exe) + " proofs") |
|
81834 | 163 |
|
164 |
val bundle_dir = Isabelle_System.make_directory(component_dir.path + Path.explode("bundle")) |
|
165 |
Isabelle_System.copy_file(hol_light_dir + Path.explode("proofs"), bundle_dir) |
|
166 |
} |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
||
171 |
/* Isabelle tool wrapper */ |
|
172 |
||
173 |
val isabelle_tool = |
|
174 |
Isabelle_Tool("component_hol_light_import", "build Isabelle component for HOL Light import", |
|
175 |
Scala_Project.here, |
|
176 |
{ args => |
|
177 |
var target_dir = Path.current |
|
178 |
var only_offline = false |
|
179 |
var hol_light_url = default_hol_light_url |
|
180 |
var hol_light_rev = default_hol_light_rev |
|
181 |
var verbose = false |
|
182 |
||
183 |
val getopts = Getopts(""" |
|
184 |
Usage: isabelle component_hol_light_import [OPTIONS] |
|
185 |
||
186 |
Options are: |
|
187 |
-D DIR target directory (default ".") |
|
188 |
-O only build the "offline" tool |
|
189 |
-U URL git URL for original HOL Light repository, default: |
|
190 |
""" + default_hol_light_url + """ |
|
191 |
-r REV revision or branch to checkout HOL Light (default: """ + |
|
192 |
default_hol_light_rev + """) |
|
193 |
-v verbose |
|
194 |
||
195 |
Build Isabelle component for HOL Light import. |
|
196 |
""", |
|
197 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
198 |
"O" -> (_ => only_offline = true), |
|
199 |
"U:" -> (arg => hol_light_url = arg), |
|
200 |
"r:" -> (arg => hol_light_rev = arg), |
|
201 |
"v" -> (_ => verbose = true)) |
|
202 |
||
203 |
val more_args = getopts(args) |
|
204 |
if (more_args.nonEmpty) getopts.usage() |
|
205 |
||
206 |
val progress = new Console_Progress(verbose = verbose) |
|
207 |
||
208 |
build_hol_light_import( |
|
209 |
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
|
210 |
hol_light_url = hol_light_url, hol_light_rev = hol_light_rev) |
81834 | 211 |
}) |
212 |
} |