src/Pure/Admin/component_cvc5.scala
changeset 77566 2a99fcb283ee
parent 76548 0af64cc2eee9
child 78158 8b5a2e4b16d4
equal deleted inserted replaced
77565:fd87490429aa 77566:2a99fcb283ee
       
     1 /*  Title:      Pure/Admin/component_cvc5.scala
       
     2     Author:     Makarius
       
     3 
       
     4 Build Isabelle component for cvc5. See also:
       
     5 
       
     6   - https://cvc5.github.io/
       
     7   - https://github.com/cvc5/cvc5
       
     8 */
       
     9 
       
    10 package isabelle
       
    11 
       
    12 
       
    13 object Component_CVC5 {
       
    14   /* platform information */
       
    15 
       
    16   sealed case class CVC5_Platform(platform_name: String, download_name: String) {
       
    17     def is_windows: Boolean = platform_name.endsWith("-windows")
       
    18   }
       
    19 
       
    20   val platforms: List[CVC5_Platform] =
       
    21     List(
       
    22       CVC5_Platform("arm64-darwin", "cvc5-macOS-arm64"),
       
    23       CVC5_Platform("x86_64-darwin", "cvc5-macOS"),
       
    24       CVC5_Platform("x86_64-linux", "cvc5-Linux"),
       
    25       CVC5_Platform("x86_64-windows", "cvc5-Win64.exe"))
       
    26 
       
    27 
       
    28   /* build cvc5 */
       
    29 
       
    30   val default_url = "https://github.com/cvc5/cvc5/releases/download"
       
    31   val default_version = "1.0.2"
       
    32 
       
    33   def build_cvc5(
       
    34     base_url: String = default_url,
       
    35     version: String = default_version,
       
    36     target_dir: Path = Path.current,
       
    37     progress: Progress = new Progress
       
    38   ): Unit = {
       
    39     /* component name */
       
    40 
       
    41     val component = "cvc5-" + version
       
    42     val component_dir =
       
    43       Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
       
    44 
       
    45 
       
    46     /* download executables */
       
    47 
       
    48     for (platform <- platforms) {
       
    49       val url = base_url + "/cvc5-" + version + "/" + platform.download_name
       
    50 
       
    51       val platform_dir = component_dir.path + Path.explode(platform.platform_name)
       
    52       val platform_exe = platform_dir + Path.explode("cvc5").exe_if(platform.is_windows)
       
    53 
       
    54       Isabelle_System.make_directory(platform_dir)
       
    55       Isabelle_System.download_file(url, platform_exe, progress = progress)
       
    56       File.set_executable(platform_exe, true)
       
    57     }
       
    58 
       
    59 
       
    60     /* settings */
       
    61 
       
    62     component_dir.write_settings("""
       
    63 CVC5_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}"
       
    64 CVC5_VERSION=""" + Bash.string(version) + """
       
    65 
       
    66 CVC5_SOLVER="$CVC5_HOME/cvc5"
       
    67 
       
    68 if [ -e "$CVC5_HOME" ]
       
    69 then
       
    70   CVC5_INSTALLED="yes"
       
    71 fi
       
    72 """)
       
    73 
       
    74 
       
    75     /* README */
       
    76 
       
    77     File.write(component_dir.README,
       
    78       """This distribution of cvc5 was assembled from the official downloads
       
    79 from """ + base_url + """ for 64bit macOS,
       
    80 Linux, and Windows. There is native support for macOS ARM64, but
       
    81 Linux ARM64 is missing.
       
    82 
       
    83 The oldest supported version of macOS is 10.14 Mojave.
       
    84 
       
    85 The downloaded files were renamed and made executable.
       
    86 
       
    87 
       
    88         Makarius
       
    89         """ + Date.Format.date(Date.now()) + "\n")
       
    90 
       
    91 
       
    92     /* AUTHORS and COPYING */
       
    93 
       
    94     // download "latest" versions as reasonable approximation
       
    95     def raw_download(name: String): Unit =
       
    96       Isabelle_System.download_file("https://raw.githubusercontent.com/cvc5/cvc5/main/" + name,
       
    97         component_dir.path + Path.explode(name))
       
    98 
       
    99     raw_download("AUTHORS")
       
   100     raw_download("COPYING")
       
   101   }
       
   102 
       
   103 
       
   104   /* Isabelle tool wrapper */
       
   105 
       
   106   val isabelle_tool =
       
   107     Isabelle_Tool("component_cvc5", "build component for cvc5", Scala_Project.here,
       
   108       { args =>
       
   109         var target_dir = Path.current
       
   110         var base_url = default_url
       
   111         var version = default_version
       
   112 
       
   113         val getopts = Getopts("""
       
   114 Usage: isabelle component_cvc5 [OPTIONS]
       
   115 
       
   116   Options are:
       
   117     -D DIR       target directory (default ".")
       
   118     -U URL       download URL (default: """" + default_url + """")
       
   119     -V VERSION   version (default: """" + default_version + """")
       
   120 
       
   121   Build component for cvc5 solver.
       
   122 """,
       
   123           "D:" -> (arg => target_dir = Path.explode(arg)),
       
   124           "U:" -> (arg => base_url = arg),
       
   125           "V:" -> (arg => version = arg))
       
   126 
       
   127         val more_args = getopts(args)
       
   128         if (more_args.nonEmpty) getopts.usage()
       
   129 
       
   130         val progress = new Console_Progress()
       
   131 
       
   132         build_cvc5(base_url = base_url, version = version, target_dir = target_dir,
       
   133           progress = progress)
       
   134       })
       
   135 }