build Isabelle sqlite-jdbc component from official download;
authorwenzelm
Wed, 30 Sep 2020 22:55:35 +0200
changeset 72346 93e533198bf6
parent 72345 14be5c341377
child 72347 e18e15b9e2ab
build Isabelle sqlite-jdbc component from official download; support arm64-linux;
src/Pure/Admin/build_sqlite.scala
src/Pure/System/isabelle_tool.scala
src/Pure/build-jars
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/Admin/build_sqlite.scala	Wed Sep 30 22:55:35 2020 +0200
@@ -0,0 +1,126 @@
+/*  Title:      Pure/Admin/build_sqlite.scala
+    Author:     Makarius
+
+Build Isabelle sqlite-jdbc component from official download.
+*/
+
+package isabelle
+
+
+object Build_SQLite
+{
+  /* build sqlite */
+
+  def build_sqlite(
+    download_url: String,
+    progress: Progress = new Progress,
+    target_dir: Path = Path.current)
+  {
+    val Download_Name = """^.*/([^/]+)\.jar""".r
+    val download_name =
+      download_url match {
+        case Download_Name(download_name) => download_name
+        case _ => error("Malformed jar download URL: " + quote(download_url))
+      }
+
+
+    /* component */
+
+    val component_dir = target_dir + Path.basic(download_name)
+    if (component_dir.is_dir) error("Component directory already exists: " + component_dir)
+    else {
+      progress.echo("Component " + component_dir)
+      Isabelle_System.mkdirs(component_dir)
+    }
+
+
+    /* README */
+
+    File.write(component_dir + Path.basic("README"),
+      "This is " + download_name + " from\n" + download_url +
+        "\n\n    Makarius\n    " + Date.Format.date(Date.now()) + "\n")
+
+
+    /* settings */
+
+    val etc_dir = component_dir + Path.basic("etc")
+    Isabelle_System.mkdirs(etc_dir)
+
+    File.write(etc_dir + Path.basic("settings"),
+"""# -*- shell-script -*- :mode=shellscript:
+
+ISABELLE_SQLITE_HOME="$COMPONENT"
+
+classpath "$ISABELLE_SQLITE_HOME/""" + download_name + """.jar"
+""")
+
+
+    /* jar */
+
+    val jar = component_dir + Path.basic(download_name).ext("jar")
+    progress.echo("Getting " + quote(download_url))
+    try {
+      Isabelle_System.bash("curl --fail --silent --location " + Bash.string(download_url) +
+        " > " + File.bash_path(jar)).check
+    }
+    catch {
+      case ERROR(msg) => cat_error("Failed to download " + quote(download_url), msg)
+    }
+
+    Isabelle_System.with_tmp_dir("sqlite")(jar_dir =>
+    {
+      progress.echo("Unpacking " + jar)
+      Isabelle_System.bash("isabelle_jdk jar xf " + File.bash_path(jar.absolute),
+        cwd = jar_dir.file).check
+
+      val jar_files =
+        List(
+          "META-INF/maven/org.xerial/sqlite-jdbc/LICENSE" -> ".",
+          "META-INF/maven/org.xerial/sqlite-jdbc/LICENSE.zentus" -> ".",
+          "org/sqlite/native/Linux/aarch64/libsqlitejdbc.so" -> "arm64-linux",
+          "org/sqlite/native/Linux/x86_64/libsqlitejdbc.so" -> "x86_64-linux",
+          "org/sqlite/native/Mac/x86_64/libsqlitejdbc.jnilib" -> "x86_64-darwin",
+          "org/sqlite/native/Windows/x86_64/sqlitejdbc.dll" -> "x86_64-windows")
+
+      for ((file, dir) <- jar_files) {
+        val target = component_dir + Path.explode(dir)
+        Isabelle_System.mkdirs(target)
+        File.copy(jar_dir + Path.explode(file), target)
+      }
+
+      File.set_executable(component_dir + Path.explode("x86_64-windows/sqlitejdbc.dll"), true)
+    })
+  }
+
+
+  /* Isabelle tool wrapper */
+
+  val isabelle_tool =
+    Isabelle_Tool("build_sqlite", "build Isabelle sqlite-jdbc component from official download",
+    args =>
+    {
+      var target_dir = Path.current
+
+      val getopts = Getopts("""
+Usage: isabelle build_sqlite [OPTIONS] DOWNLOAD
+
+  Options are:
+    -D DIR       target directory (default ".")
+
+  Build sqlite-jdbc component from the specified download URL (JAR), see also
+  https://github.com/xerial/sqlite-jdbc/releases
+""",
+        "D:" -> (arg => target_dir = Path.explode(arg)))
+
+      val more_args = getopts(args)
+      val download_url =
+        more_args match {
+          case List(download_url) => download_url
+          case _ => getopts.usage()
+        }
+
+      val progress = new Console_Progress()
+
+      build_sqlite(download_url, progress = progress, target_dir = target_dir)
+    })
+}
--- a/src/Pure/System/isabelle_tool.scala	Wed Sep 30 13:40:42 2020 +0000
+++ b/src/Pure/System/isabelle_tool.scala	Wed Sep 30 22:55:35 2020 +0200
@@ -176,6 +176,7 @@
   Build_JDK.isabelle_tool,
   Build_PolyML.isabelle_tool1,
   Build_PolyML.isabelle_tool2,
+  Build_SQLite.isabelle_tool,
   Build_Status.isabelle_tool,
   Check_Sources.isabelle_tool,
   Components.isabelle_tool,
--- a/src/Pure/build-jars	Wed Sep 30 13:40:42 2020 +0000
+++ b/src/Pure/build-jars	Wed Sep 30 22:55:35 2020 +0200
@@ -19,6 +19,7 @@
   src/Pure/Admin/build_log.scala
   src/Pure/Admin/build_polyml.scala
   src/Pure/Admin/build_release.scala
+  src/Pure/Admin/build_sqlite.scala
   src/Pure/Admin/build_status.scala
   src/Pure/Admin/check_sources.scala
   src/Pure/Admin/ci_profile.scala