| author | wenzelm | 
| Tue, 06 Sep 2022 21:06:20 +0200 | |
| changeset 76074 | 2456721602b2 | 
| parent 75394 | 42267c650205 | 
| child 76518 | b30b8e23383c | 
| permissions | -rw-r--r-- | 
| 72886 | 1 | /* Title: Pure/Admin/build_vampire.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 74465 | 4 | Build Isabelle Vampire component from official download. | 
| 72886 | 5 | */ | 
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 75393 | 10 | object Build_Vampire {
 | 
| 74465 | 11 | val default_download_url = "https://github.com/vprover/vampire/archive/refs/tags/v4.6.tar.gz" | 
| 72890 | 12 | val default_jobs = 1 | 
| 72887 | 13 | |
| 74464 | 14 | def make_component_name(version: String): String = | 
| 15 |     "vampire-" + Library.try_unprefix("v", version).getOrElse(version)
 | |
| 72886 | 16 | |
| 17 | ||
| 18 | /* build Vampire */ | |
| 19 | ||
| 20 | def build_vampire( | |
| 74465 | 21 | download_url: String = default_download_url, | 
| 72890 | 22 | jobs: Int = default_jobs, | 
| 72887 | 23 | component_name: String = "", | 
| 72886 | 24 | verbose: Boolean = false, | 
| 25 | progress: Progress = new Progress, | |
| 75393 | 26 | target_dir: Path = Path.current | 
| 27 |   ): Unit = {
 | |
| 73650 | 28 |     Isabelle_System.require_command("cmake")
 | 
| 72938 | 29 | |
| 75394 | 30 |     Isabelle_System.with_tmp_dir("build") { tmp_dir =>
 | 
| 74465 | 31 | /* component */ | 
| 32 | ||
| 33 | val Archive_Name = """^.*?([^/]+)$""".r | |
| 34 | val Version = """^v?([0-9.]+)\.tar.gz$""".r | |
| 35 | ||
| 36 | val archive_name = | |
| 37 |         download_url match {
 | |
| 38 | case Archive_Name(name) => name | |
| 39 |           case _ => error("Failed to determine source archive name from " + quote(download_url))
 | |
| 40 | } | |
| 41 | ||
| 42 | val version = | |
| 43 |         archive_name match {
 | |
| 44 | case Version(version) => version | |
| 45 |           case _ => error("Failed to determine component version from " + quote(archive_name))
 | |
| 46 | } | |
| 72886 | 47 | |
| 74464 | 48 | val component = proper_string(component_name) getOrElse make_component_name(version) | 
| 72887 | 49 | val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component)) | 
| 72886 | 50 |       progress.echo("Component " + component_dir)
 | 
| 51 | ||
| 74465 | 52 | |
| 53 | /* platform */ | |
| 54 | ||
| 72886 | 55 | val platform_name = | 
| 56 |         proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse
 | |
| 57 |           error("No 64bit platform")
 | |
| 74465 | 58 | |
| 72886 | 59 | val platform_dir = Isabelle_System.make_directory(component_dir + Path.basic(platform_name)) | 
| 60 | ||
| 61 | ||
| 74465 | 62 | /* download source */ | 
| 63 | ||
| 64 | val archive_path = tmp_dir + Path.basic(archive_name) | |
| 65 | Isabelle_System.download_file(download_url, archive_path, progress = progress) | |
| 72886 | 66 | |
| 74465 | 67 |       Isabelle_System.bash("tar xzf " + File.bash_path(archive_path), cwd = tmp_dir.file).check
 | 
| 68 | val source_name = File.get_dir(tmp_dir) | |
| 72886 | 69 | |
| 74465 | 70 | Isabelle_System.bash( | 
| 71 | "tar xzf " + archive_path + " && mv " + Bash.string(source_name) + " src", | |
| 72 | cwd = component_dir.file).check | |
| 72888 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 73 | |
| 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 74 | |
| 74464 | 75 | /* build */ | 
| 72886 | 76 | |
| 74465 | 77 |       progress.echo("Building Vampire for " + platform_name + " ...")
 | 
| 72888 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 78 | |
| 74465 | 79 | val build_dir = tmp_dir + Path.basic(source_name) | 
| 80 |       Isabelle_System.copy_file(build_dir + Path.explode("LICENCE"), component_dir)
 | |
| 72888 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 81 | |
| 74464 | 82 | val cmake_opts = if (Platform.is_linux) "-DBUILD_SHARED_LIBS=0 " else "" | 
| 83 | val cmake_out = | |
| 74465 | 84 |         progress.bash("cmake " + cmake_opts + """-G "Unix Makefiles" .""",
 | 
| 74464 | 85 | cwd = build_dir.file, echo = verbose).check.out | 
| 72886 | 86 | |
| 74464 | 87 | val Pattern = """-- Setting binary name to '?([^\s']*)'?""".r | 
| 88 | val binary = | |
| 89 |         split_lines(cmake_out).collectFirst({ case Pattern(name) => name })
 | |
| 90 |           .getOrElse(error("Failed to determine binary name from cmake output:\n" + cmake_out))
 | |
| 72888 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 91 | |
| 74464 | 92 |       progress.bash("make -j" + jobs, cwd = build_dir.file, echo = verbose).check
 | 
| 72888 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 93 | |
| 74464 | 94 |       Isabelle_System.copy_file(build_dir + Path.basic("bin") + Path.basic(binary).platform_exe,
 | 
| 95 |         platform_dir + Path.basic("vampire").platform_exe)
 | |
| 72888 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 96 | |
| 
74d785882737
prefer cmake build for standard version: more portable;
 wenzelm parents: 
72887diff
changeset | 97 | |
| 72886 | 98 | /* settings */ | 
| 99 | ||
| 100 |       val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc"))
 | |
| 101 |       File.write(etc_dir + Path.basic("settings"),
 | |
| 102 | """# -*- shell-script -*- :mode=shellscript: | |
| 103 | ||
| 104 | VAMPIRE_HOME="$COMPONENT/$ISABELLE_PLATFORM64" | |
| 105 | ||
| 106 | ISABELLE_VAMPIRE="$VAMPIRE_HOME/vampire" | |
| 107 | """) | |
| 108 | ||
| 109 | ||
| 110 | /* README */ | |
| 111 | ||
| 112 |       File.write(component_dir + Path.basic("README"),
 | |
| 74465 | 113 | "This Isabelle component provides Vampire " + version + """using the | 
| 114 | original sources from """.stripMargin + download_url + """ | |
| 72886 | 115 | |
| 74465 | 116 | The executables have been built via "cmake . && make" | 
| 72886 | 117 | |
| 118 | ||
| 119 | Makarius | |
| 120 | """ + Date.Format.date(Date.now()) + "\n") | |
| 75394 | 121 | } | 
| 72886 | 122 | } | 
| 123 | ||
| 124 | ||
| 125 | /* Isabelle tool wrapper */ | |
| 126 | ||
| 127 | val isabelle_tool = | |
| 74480 | 128 |     Isabelle_Tool("build_vampire", "build prover component from official download",
 | 
| 75394 | 129 | Scala_Project.here, | 
| 130 |     { args =>
 | |
| 72886 | 131 | var target_dir = Path.current | 
| 74465 | 132 | var download_url = default_download_url | 
| 72890 | 133 | var jobs = default_jobs | 
| 72887 | 134 | var component_name = "" | 
| 72886 | 135 | var verbose = false | 
| 136 | ||
| 137 |       val getopts = Getopts("""
 | |
| 138 | Usage: isabelle build_vampire [OPTIONS] | |
| 139 | ||
| 140 | Options are: | |
| 141 | -D DIR target directory (default ".") | |
| 74465 | 142 | -U URL download URL | 
| 143 | (default: """" + default_download_url + """") | |
| 72890 | 144 | -j NUMBER parallel jobs for make (default: """ + default_jobs + """) | 
| 74465 | 145 |     -n NAME      component name (default: """" + make_component_name("VERSION") + """")
 | 
| 72886 | 146 | -v verbose | 
| 147 | ||
| 148 | Build prover component from official download. | |
| 149 | """, | |
| 150 | "D:" -> (arg => target_dir = Path.explode(arg)), | |
| 74465 | 151 | "U:" -> (arg => download_url = arg), | 
| 72890 | 152 | "j:" -> (arg => jobs = Value.Nat.parse(arg)), | 
| 72886 | 153 | "n:" -> (arg => component_name = arg), | 
| 154 | "v" -> (_ => verbose = true)) | |
| 155 | ||
| 156 | val more_args = getopts(args) | |
| 157 | if (more_args.nonEmpty) getopts.usage() | |
| 158 | ||
| 159 | val progress = new Console_Progress() | |
| 160 | ||
| 74465 | 161 | build_vampire(download_url = download_url, component_name = component_name, | 
| 74464 | 162 | jobs = jobs, verbose = verbose, progress = progress, target_dir = target_dir) | 
| 72886 | 163 | }) | 
| 164 | } |