src/Pure/Admin/component_hol_light.scala
author wenzelm
Wed, 12 Mar 2025 11:39:00 +0100
changeset 82265 4b875a4c83b0
parent 81971 bd8e174b6f95
child 82610 3133f9748ea8
permissions -rw-r--r--
update for release;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/component_hol_light.scala
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     3
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     4
Build component for HOL-Light, with export of facts and proofs, offline
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     5
optimization, and import to Isabelle/HOL.
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     6
*/
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     7
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     8
package isabelle
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
     9
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    10
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    11
object Component_HOL_Light {
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    12
  /* resources */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    13
81928
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
    14
  val hol_import_dir: Path = Path.explode("~~/src/HOL/Import")
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
    15
  def default_maps: Path = hol_import_dir + Path.explode("offline/maps.lst")
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
    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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    21
  val default_hol_light_url = "https://github.com/jrh13/hol-light.git"
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    22
  val default_hol_light_rev = "Release-3.0.0"
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    23
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    24
  def build_hol_light_import(
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    25
    only_offline: Boolean = false,
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    26
    progress: Progress = new Progress,
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    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
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
    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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    33
  ): Unit = {
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    34
    /* system */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    35
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    36
    if (!only_offline) {
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    37
      Linux.check_system()
81971
bd8e174b6f95 more explicit system dependencies;
wenzelm
parents: 81970
diff changeset
    38
      Isabelle_System.require_command("bzip2")
bd8e174b6f95 more explicit system dependencies;
wenzelm
parents: 81970
diff changeset
    39
      Isabelle_System.require_command("m4")
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    40
      Isabelle_System.require_command("patch")
81920
8d5989ab1e42 clarified compression;
wenzelm
parents: 81918
diff changeset
    41
      Isabelle_System.require_command("zstd")
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    42
    }
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    43
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    44
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    45
    /* component */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    46
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    47
    val component_name = "hol_light_import-" + Date.Format.alt_date(Date.now())
81927
d59262da07ac tuned output: proper progress;
wenzelm
parents: 81925
diff changeset
    48
    val component_dir =
d59262da07ac tuned output: proper progress;
wenzelm
parents: 81925
diff changeset
    49
      Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress)
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    50
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    51
    val platform = Isabelle_Platform.self.ISABELLE_PLATFORM(windows = true, apple = true)
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    52
    val platform_dir = Isabelle_System.make_directory(component_dir.path + Path.basic(platform))
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    53
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    54
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    55
    /* settings */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    56
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    57
    component_dir.write_settings("""
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    60
HOL_LIGHT_OFFLINE="$HOL_LIGHT_IMPORT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}/offline"
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    61
""")
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    62
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    63
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    64
    /* README */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    65
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    66
    File.write(component_dir.README,
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    67
      """Author: Cezary Kaliszyk, University of Innsbruck, 2013
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    68
Author: Alexander Krauss, QAware GmbH, 2013
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    69
Author: Sophie Tourret, INRIA, 2024
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    70
Author: Stéphane Glondu, INRIA, 2024
81922
aa9800b48193 tuned README;
wenzelm
parents: 81921
diff changeset
    71
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    72
LICENSE (export tools): BSD-3 from Isabelle
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    73
LICENSE (HOL Light proofs): BSD-2 from HOL Light
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    74
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    75
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    76
This is an export of primitive proofs from HOL Light """ + hol_light_rev + """.
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    77
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    78
The original repository """ + hol_light_url + """
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
    79
has been patched in 2 phases. The overall export process works like this:
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    80
81925
27854cbcadf1 more README;
wenzelm
parents: 81924
diff changeset
    81
  isabelle ocaml_setup
27854cbcadf1 more README;
wenzelm
parents: 81924
diff changeset
    82
  isabelle ocaml_opam install -y camlp5
27854cbcadf1 more README;
wenzelm
parents: 81924
diff changeset
    83
  eval $(isabelle ocaml_opam env)
27854cbcadf1 more README;
wenzelm
parents: 81924
diff changeset
    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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    86
  make
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    87
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
    88
  patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch1"
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    89
  ./ocaml-hol -I +compiler-libs stage1.ml
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    90
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
    91
  patch -p1 < "$HOL_LIGHT_IMPORT/patches/patch2"
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    92
  export MAXTMS=10000
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    93
  ./ocaml-hol -I +compiler-libs stage2.ml
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    94
81928
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
    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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    97
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    98
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
    99
      Makarius
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   100
      """ + Date.Format.date(Date.now()) + "\n")
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   101
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   102
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   103
    Isabelle_System.with_tmp_dir("build") { tmp_dir =>
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   104
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   105
      /* OCaml setup */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   106
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   107
      progress.echo("Setup OCaml ...")
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   108
      progress.bash(
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   109
        if (only_offline) "isabelle ocaml_setup_base"
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   110
        else "isabelle ocaml_setup && isabelle ocaml_opam install -y camlp5",
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   111
        echo = progress.verbose).check
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   112
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   113
      val opam_env = Isabelle_System.bash("isabelle ocaml_opam env").check.out
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   114
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   115
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   116
      /* "offline" tool */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   117
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   118
      progress.echo("Building offline tool ...")
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   119
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   120
      val offline_path = Path.explode("offline")
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   129
      File.set_executable(platform_dir + offline_exe)
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   130
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   131
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   132
      if (!only_offline) {
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   133
        /* clone repository */
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   134
81916
2bb448f2ac51 avoid redundant repository clone;
wenzelm
parents: 81915
diff changeset
   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
2bb448f2ac51 avoid redundant repository clone;
wenzelm
parents: 81915
diff changeset
   137
        Isabelle_System.git_clone(hol_light_url, hol_light_dir, checkout = hol_light_rev,
2bb448f2ac51 avoid redundant repository clone;
wenzelm
parents: 81915
diff changeset
   138
          progress = progress)
2bb448f2ac51 avoid redundant repository clone;
wenzelm
parents: 81915
diff changeset
   139
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   140
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   141
        /* patches */
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   142
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   143
        Isabelle_System.make_directory(component_dir.path + Path.basic("patches"))
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   144
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   145
        def patch(n: Int, source: Boolean = false): Path =
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   146
          (if (source) hol_import_dir else component_dir.path) + Path.explode("patches/patch" + n)
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   147
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   148
        for (n <- List(1, 2)) Isabelle_System.copy_file(patch(n, source = true), patch(n))
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   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
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   159
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   160
        /* export stages */
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   161
81917
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   162
        def run(n: Int, lines: String*): Unit = {
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   163
          val title = "stage " + n
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   164
          if (n > 0) progress.echo("Running " + title + " ...")
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   165
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   166
          val start = Time.now()
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   167
          progress.bash(cat_lines("set -e" :: opam_env :: lines.toList),
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   168
            cwd = hol_light_dir, echo = progress.verbose).check.timing
81917
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   169
          val elapsed = Time.now() - start
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   170
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   171
          if (n > 0) {
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   172
            progress.echo("Finished " + title + " (" + elapsed.message_hms + " elapsed time)")
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   173
          }
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   174
        }
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   175
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   176
        run(0, "make")
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   177
        run(1,
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   178
          "patch -p1 < " + File.bash_path(patch(1)),
81917
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   179
          "./ocaml-hol -I +compiler-libs stage1.ml")
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   180
        run(2,
81918
deb6cb34a37f clarified patches;
wenzelm
parents: 81917
diff changeset
   181
          "patch -p1 < " + File.bash_path(patch(2)),
81917
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   182
          "export MAXTMS=10000",
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   183
          "./ocaml-hol -I +compiler-libs stage2.ml")
81928
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   184
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   185
        Bytes.write(hol_light_dir + Path.explode("maps.lst"),
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   186
          if (maps.isEmpty) Bytes.empty else Bytes.read(maps.get))
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   187
81917
50cd5037aff7 more explicit stages, with timing messages;
wenzelm
parents: 81916
diff changeset
   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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   191
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   194
          Isabelle_System.copy_file(hol_light_dir + Path.explode(name), bundle_dir)
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   195
        }
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   196
      }
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   197
    }
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   198
  }
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   199
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   200
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   201
  /* Isabelle tool wrapper */
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   202
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   203
  val isabelle_tool =
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   204
    Isabelle_Tool("component_hol_light_import", "build Isabelle component for HOL Light import",
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   205
      Scala_Project.here,
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   206
      { args =>
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   209
        var maps: Option[Path] = Some(default_maps)
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   212
        var hol_light_url = default_hol_light_url
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   213
        var hol_light_rev = default_hol_light_rev
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   214
        var verbose = false
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   215
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   216
        val getopts = Getopts("""
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   217
Usage: isabelle component_hol_light_import [OPTIONS]
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   218
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   219
  Options are:
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   222
    -M PATH      alternative maps.lst for offline alignment of facts
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   223
                 ("." means empty, default: """ + default_maps + """)
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   226
    -U URL       git URL for original HOL Light repository, default:
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   227
                 """ + default_hol_light_url + """
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   228
    -r REV       revision or branch to checkout HOL Light (default: """ +
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   229
                    default_hol_light_rev + """)
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   230
    -v           verbose
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
bd8e174b6f95 more explicit system dependencies;
wenzelm
parents: 81970
diff changeset
   236
bd8e174b6f95 more explicit system dependencies;
wenzelm
parents: 81970
diff changeset
   237
  The HOL Light build process uses OCaml/OPAM from Isabelle; this requires
bd8e174b6f95 more explicit system dependencies;
wenzelm
parents: 81970
diff changeset
   238
  C development tools with libgmp-dev.
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   239
""",
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   242
          "M:" -> (arg => maps = if (arg == ".") None else Some(Path.explode(arg))),
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   245
          "U:" -> (arg => hol_light_url = arg),
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   246
          "r:" -> (arg => hol_light_rev = arg),
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   247
          "v" -> (_ => verbose = true))
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   248
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   249
        val more_args = getopts(args)
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   250
        if (more_args.nonEmpty) getopts.usage()
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   251
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   252
        val progress = new Console_Progress(verbose = verbose)
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   253
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   254
        build_hol_light_import(
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   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
d6366c0c9d5c optional maps.lst;
wenzelm
parents: 81927
diff changeset
   257
          hol_light_url = hol_light_url, hol_light_rev = hol_light_rev)
81834
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   258
      })
9e25f6e2748c reproducible construction of HOL Light export bundle;
wenzelm
parents:
diff changeset
   259
}