src/Pure/Admin/build_minisat.scala
author wenzelm
Sat, 04 Mar 2023 23:25:30 +0100
changeset 77510 f5d6cd98b16a
parent 76548 0af64cc2eee9
permissions -rw-r--r--
clarified signature: manage "verbose" flag via "progress";
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Admin/build_minisat.scala
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     3
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     4
Build Isabelle Minisat from sources.
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     5
*/
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     6
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     7
package isabelle
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     8
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
     9
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75202
diff changeset
    10
object Build_Minisat {
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    11
  val default_download_url = "https://github.com/stp/minisat/archive/releases/2.2.1.tar.gz"
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    12
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    13
  def make_component_name(version: String): String = "minisat-" + version
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    14
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    15
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    16
  /* build Minisat */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    17
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    18
  def build_minisat(
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    19
    download_url: String = default_download_url,
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    20
    component_name: String = "",
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    21
    progress: Progress = new Progress,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75202
diff changeset
    22
    target_dir: Path = Path.current
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75202
diff changeset
    23
  ): Unit = {
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
    24
    Isabelle_System.with_tmp_dir("build") { tmp_dir =>
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    25
      /* component */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    26
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    27
      val Archive_Name = """^.*?([^/]+)$""".r
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    28
      val Version = """^v?([0-9.]+)\.tar.gz$""".r
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    29
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    30
      val archive_name =
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    31
        download_url match {
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    32
          case Archive_Name(name) => name
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    33
          case _ => error("Failed to determine source archive name from " + quote(download_url))
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    34
        }
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    35
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    36
      val version =
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    37
        archive_name match {
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    38
          case Version(version) => version
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    39
          case _ => error("Failed to determine component version from " + quote(archive_name))
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    40
        }
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    41
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    42
      val component = proper_string(component_name) getOrElse make_component_name(version)
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
    43
      val component_dir =
76547
9fe5d8c70352 tuned signature;
wenzelm
parents: 76541
diff changeset
    44
        Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    45
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    46
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    47
      /* platform */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    48
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    49
      val platform_name =
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    50
        proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    51
          error("No 64bit platform")
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    52
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
    53
      val platform_dir =
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
    54
        Isabelle_System.make_directory(component_dir.path + Path.basic(platform_name))
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    55
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    56
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    57
      /* download source */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    58
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    59
      val archive_path = tmp_dir + Path.basic(archive_name)
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    60
      Isabelle_System.download_file(download_url, archive_path, progress = progress)
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    61
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76529
diff changeset
    62
      Isabelle_System.extract(archive_path, tmp_dir)
76529
ded37aade88e clarified signature;
wenzelm
parents: 76518
diff changeset
    63
      val source_dir = File.get_dir(tmp_dir, title = download_url)
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    64
76541
3706b88035d2 more direct target directory;
wenzelm
parents: 76540
diff changeset
    65
      Isabelle_System.extract(archive_path, component_dir.src, strip = true)
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    66
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    67
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    68
      /* build */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    69
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    70
      progress.echo("Building Minisat for " + platform_name + " ...")
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    71
76529
ded37aade88e clarified signature;
wenzelm
parents: 76518
diff changeset
    72
      Isabelle_System.copy_file(source_dir + Path.explode("LICENSE"), component_dir.path)
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    73
74483
60eeb9952145 proper build on macOS;
wenzelm
parents: 74482
diff changeset
    74
      if (Platform.is_macos) {
76529
ded37aade88e clarified signature;
wenzelm
parents: 76518
diff changeset
    75
        File.change(source_dir + Path.explode("Makefile")) {
75202
4fdde010086f clarified signature;
wenzelm
parents: 74734
diff changeset
    76
          _.replaceAll("--static", "").replaceAll("-Wl,-soname\\S+", "")
4fdde010086f clarified signature;
wenzelm
parents: 74734
diff changeset
    77
        }
74483
60eeb9952145 proper build on macOS;
wenzelm
parents: 74482
diff changeset
    78
      }
77510
f5d6cd98b16a clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 76548
diff changeset
    79
      progress.bash("make r", source_dir.file, echo = progress.verbose).check
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    80
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    81
      Isabelle_System.copy_file(
76529
ded37aade88e clarified signature;
wenzelm
parents: 76518
diff changeset
    82
        source_dir + Path.explode("build/release/bin/minisat").platform_exe, platform_dir)
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    83
74734
f345da8defff repackage minisat-2.2.1 with cygwin1.dll: required to run the executable without existing Cygwin context (normally provided by bash_process);
wenzelm
parents: 74484
diff changeset
    84
      if (Platform.is_windows) {
f345da8defff repackage minisat-2.2.1 with cygwin1.dll: required to run the executable without existing Cygwin context (normally provided by bash_process);
wenzelm
parents: 74484
diff changeset
    85
        Isabelle_System.copy_file(Path.explode("/bin/cygwin1.dll"), platform_dir)
f345da8defff repackage minisat-2.2.1 with cygwin1.dll: required to run the executable without existing Cygwin context (normally provided by bash_process);
wenzelm
parents: 74484
diff changeset
    86
      }
f345da8defff repackage minisat-2.2.1 with cygwin1.dll: required to run the executable without existing Cygwin context (normally provided by bash_process);
wenzelm
parents: 74484
diff changeset
    87
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    88
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    89
      /* settings */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    90
76548
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
    91
      component_dir.write_settings("""
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    92
MINISAT_HOME="$COMPONENT/$ISABELLE_PLATFORM64"
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    93
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    94
ISABELLE_MINISAT="$MINISAT_HOME/minisat"
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    95
""")
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    96
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    97
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    98
      /* README */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
    99
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 75394
diff changeset
   100
      File.write(component_dir.README,
74484
ef07e6d672cb tuned message;
wenzelm
parents: 74483
diff changeset
   101
        "This Isabelle component provides Minisat " + version + """ using the
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   102
sources from """.stripMargin + download_url + """
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   103
74483
60eeb9952145 proper build on macOS;
wenzelm
parents: 74482
diff changeset
   104
The executables have been built via "make r"; macOS requires to
60eeb9952145 proper build on macOS;
wenzelm
parents: 74482
diff changeset
   105
remove options "--static" and "-Wl,-soname,..." from the Makefile.
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   106
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   107
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   108
        Makarius
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   109
        """ + Date.Format.date(Date.now()) + "\n")
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   110
    }
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   111
  }
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   112
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   113
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   114
  /* Isabelle tool wrapper */
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   115
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   116
  val isabelle_tool =
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   117
    Isabelle_Tool("build_minisat", "build prover component from sources", Scala_Project.here,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   118
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   119
        var target_dir = Path.current
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   120
        var download_url = default_download_url
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   121
        var component_name = ""
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   122
        var verbose = false
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   123
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   124
        val getopts = Getopts("""
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   125
Usage: isabelle build_minisat [OPTIONS]
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   126
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   127
  Options are:
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   128
    -D DIR       target directory (default ".")
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   129
    -U URL       download URL
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   130
                 (default: """" + default_download_url + """")
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   131
    -n NAME      component name (default: """" + make_component_name("VERSION") + """")
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   132
    -v           verbose
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   133
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   134
  Build prover component from official download.
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   135
""",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   136
          "D:" -> (arg => target_dir = Path.explode(arg)),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   137
          "U:" -> (arg => download_url = arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   138
          "n:" -> (arg => component_name = arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   139
          "v" -> (_ => verbose = true))
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   140
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   141
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   142
        if (more_args.nonEmpty) getopts.usage()
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   143
77510
f5d6cd98b16a clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 76548
diff changeset
   144
        val progress = new Console_Progress(verbose = verbose)
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   145
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   146
        build_minisat(download_url = download_url, component_name = component_name,
77510
f5d6cd98b16a clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 76548
diff changeset
   147
          progress = progress, target_dir = target_dir)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   148
      })
74482
bd5998580edb build minisat, using recent fork from original sources;
wenzelm
parents:
diff changeset
   149
}