src/Pure/Admin/build_spass.scala
author wenzelm
Fri, 24 Feb 2023 20:52:35 +0100
changeset 77369 df17355f1e2c
parent 76548 0af64cc2eee9
child 77510 f5d6cd98b16a
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/build_spass.scala
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     3
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     4
Build Isabelle SPASS component from unofficial download.
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     5
*/
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     6
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     7
package isabelle
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     8
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
     9
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75202
diff changeset
    10
object Build_SPASS {
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    11
  /* build SPASS */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    12
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    13
  val default_download_url = "https://www.cs.vu.nl/~jbe248/spass-3.8ds-src.tar.gz"
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    14
  val standard_version = "3.8ds"
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    15
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    16
  def build_spass(
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    17
    download_url: String = default_download_url,
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    18
    verbose: Boolean = false,
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    19
    progress: Progress = new Progress,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75202
diff changeset
    20
    target_dir: Path = Path.current): Unit = {
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    21
    Isabelle_System.with_tmp_dir("build") { tmp_dir =>
73650
9ce115baaa4f clarified signature;
wenzelm
parents: 73566
diff changeset
    22
      Isabelle_System.require_command("bison")
9ce115baaa4f clarified signature;
wenzelm
parents: 73566
diff changeset
    23
      Isabelle_System.require_command("flex")
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    24
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    25
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    26
      /* component */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    27
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    28
      val Archive_Name = """^.*?([^/]+)$""".r
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    29
      val Component_Name = """^(.+)-src\.tar.gz$""".r
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    30
      val Version = """^[^-]+-([^-]+)$""".r
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    31
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    32
      val archive_name =
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    33
        download_url match {
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    34
          case Archive_Name(name) => name
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    35
          case _ => error("Failed to determine source archive name from " + quote(download_url))
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    36
        }
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    37
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    38
      val component_name =
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    39
        archive_name match {
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    40
          case Component_Name(name) => name
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    41
          case _ => error("Failed to determine component name from " + quote(archive_name))
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    42
        }
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    43
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    44
      val version =
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    45
        component_name match {
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    46
          case Version(version) => version
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    47
          case _ => error("Failed to determine component version from " + quote(component_name))
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    48
        }
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    49
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    50
      if (version != standard_version) {
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    51
        progress.echo_warning("Odd SPASS version " + version + " (expected " + standard_version + ")")
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    52
      }
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    53
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
    54
      val component_dir =
76547
9fe5d8c70352 tuned signature;
wenzelm
parents: 76541
diff changeset
    55
        Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress)
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    56
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    57
      val platform_name =
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    58
        proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64"))
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    59
          .getOrElse(error("No 64bit platform"))
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    60
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
    61
      val platform_dir =
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
    62
        Isabelle_System.make_directory(component_dir.path + Path.basic(platform_name))
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    63
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    64
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    65
      /* download source */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    66
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    67
      val archive_path = tmp_dir + Path.basic(archive_name)
73566
4e6b31ed7197 clarified signature: avoid tmp file;
wenzelm
parents: 73340
diff changeset
    68
      Isabelle_System.download_file(download_url, archive_path, progress = progress)
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    69
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    70
      Isabelle_System.extract(archive_path, tmp_dir)
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    71
      val source_dir = File.get_dir(tmp_dir, title = download_url)
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    72
76541
3706b88035d2 more direct target directory;
wenzelm
parents: 76540
diff changeset
    73
      Isabelle_System.extract(archive_path, component_dir.src, strip = true)
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    74
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    75
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    76
      /* build */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    77
72440
d0ba71b3297e tuned messages;
wenzelm
parents: 72412
diff changeset
    78
      progress.echo("Building SPASS for " + platform_name + " ...")
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    79
72412
9ed9585c495b proper support for Windows/Cygwin;
wenzelm
parents: 72411
diff changeset
    80
      if (Platform.is_windows) {
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    81
        File.change(source_dir + Path.basic("misc.c")) {
72412
9ed9585c495b proper support for Windows/Cygwin;
wenzelm
parents: 72411
diff changeset
    82
          _.replace("""#include "execinfo.h" """, "")
75202
4fdde010086f clarified signature;
wenzelm
parents: 73650
diff changeset
    83
           .replaceAll("""void misc_DumpCore\(void\)[^}]+}""", "void misc_DumpCore(void) { abort(); }")
4fdde010086f clarified signature;
wenzelm
parents: 73650
diff changeset
    84
        }
72412
9ed9585c495b proper support for Windows/Cygwin;
wenzelm
parents: 72411
diff changeset
    85
      }
9ed9585c495b proper support for Windows/Cygwin;
wenzelm
parents: 72411
diff changeset
    86
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    87
      Isabelle_System.bash("make", cwd = source_dir.file,
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    88
        progress_stdout = progress.echo_if(verbose, _),
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    89
        progress_stderr = progress.echo_if(verbose, _)).check
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    90
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    91
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    92
      /* install */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    93
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    94
      Isabelle_System.copy_file(source_dir + Path.basic("LICENCE"), component_dir.LICENSE)
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    95
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    96
      val install_files = List("SPASS")
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
    97
      for (name <- install_files ::: install_files.map(_ + ".exe")) {
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76518
diff changeset
    98
        val path = source_dir + Path.basic(name)
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 72763
diff changeset
    99
        if (path.is_file) Isabelle_System.copy_file(path, platform_dir)
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   100
      }
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   101
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   102
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   103
      /* settings */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   104
76548
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
   105
      component_dir.write_settings("""
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   106
SPASS_HOME="$COMPONENT/$ISABELLE_PLATFORM64"
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   107
SPASS_VERSION=""" + quote(version) + """
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   108
""")
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   109
76548
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
   110
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   111
      /* README */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   112
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
   113
      File.write(component_dir.README,
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   114
"""This distribution of SPASS 3.8ds, described in Blanchette, Popescu, Wand, and
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   115
Weidenbach's ITP 2012 paper "More SPASS with Isabelle", has been compiled from
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   116
sources available at """ + download_url + """
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   117
via "make".
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   118
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   119
The Windows/Cygwin compilation required commenting out the line
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   120
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   121
    #include "execinfo.h"
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   122
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   123
in "misc.c" as well as most of the body of the "misc_DumpCore" function.
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   124
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   125
The latest official SPASS sources can be downloaded from
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   126
http://www.spass-prover.org/. Be aware, however, that the official SPASS
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   127
releases are not compatible with Isabelle.
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   128
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   129
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   130
Viel SPASS!
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   131
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   132
72444
2d9a70b85009 tuned whitespace;
wenzelm
parents: 72440
diff changeset
   133
        Jasmin Blanchette
2d9a70b85009 tuned whitespace;
wenzelm
parents: 72440
diff changeset
   134
        16-May-2018
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   135
72444
2d9a70b85009 tuned whitespace;
wenzelm
parents: 72440
diff changeset
   136
        Makarius
2d9a70b85009 tuned whitespace;
wenzelm
parents: 72440
diff changeset
   137
        """ + Date.Format.date(Date.now()) + "\n")
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   138
    }
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   139
}
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   140
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   141
  /* Isabelle tool wrapper */
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   142
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   143
  val isabelle_tool =
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   144
    Isabelle_Tool("build_spass", "build prover component from source distribution",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   145
      Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   146
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   147
        var target_dir = Path.current
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   148
        var download_url = default_download_url
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   149
        var verbose = false
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   150
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   151
        val getopts = Getopts("""
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   152
Usage: isabelle build_spass [OPTIONS]
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   153
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   154
  Options are:
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   155
    -D DIR       target directory (default ".")
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   156
    -U URL       download URL
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   157
                 (default: """" + default_download_url + """")
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   158
    -v           verbose
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   159
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   160
  Build prover component from the specified source distribution.
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   161
""",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   162
          "D:" -> (arg => target_dir = Path.explode(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   163
          "U:" -> (arg => download_url = arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   164
          "v" -> (_ => verbose = true))
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   165
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   166
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   167
        if (more_args.nonEmpty) getopts.usage()
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   168
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   169
        val progress = new Console_Progress()
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   170
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   171
        build_spass(download_url = download_url, verbose = verbose, progress = progress,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   172
          target_dir = target_dir)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   173
      })
72411
b8cc129ece05 build Isabelle SPASS component from unofficial download;
wenzelm
parents:
diff changeset
   174
}