provide tool for GHC stack component;
authorwenzelm
Tue, 11 Jul 2023 15:01:38 +0200
changeset 78301 9776f5278ae8
parent 78300 ab95c9f2d55c
child 78302 27521a4779bd
provide tool for GHC stack component;
etc/build.props
src/Pure/Admin/component_stack.scala
src/Pure/System/isabelle_tool.scala
--- a/etc/build.props	Tue Jul 11 12:12:21 2023 +0200
+++ b/etc/build.props	Tue Jul 11 15:01:38 2023 +0200
@@ -40,6 +40,7 @@
   src/Pure/Admin/component_scala.scala \
   src/Pure/Admin/component_spass.scala \
   src/Pure/Admin/component_sqlite.scala \
+  src/Pure/Admin/component_stack.scala \
   src/Pure/Admin/component_vampire.scala \
   src/Pure/Admin/component_verit.scala \
   src/Pure/Admin/component_zipperposition.scala \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/Admin/component_stack.scala	Tue Jul 11 15:01:38 2023 +0200
@@ -0,0 +1,132 @@
+/*  Title:      Pure/Admin/component_stack.scala
+    Author:     Makarius
+
+Build Isabelle component for GHC stack. See also:
+
+  - https://www.haskellstack.org
+  - https://github.com/commercialhaskell
+*/
+
+package isabelle
+
+
+object Component_Stack {
+  /* platform information */
+
+  sealed case class Download_Platform(platform_name: String, download_name: String) {
+    def is_windows: Boolean = platform_name.endsWith("-windows")
+  }
+
+  val platforms: List[Download_Platform] =
+    List(
+      Download_Platform("arm64-linux", "linux-aarch64"),
+      Download_Platform("x86_64-darwin", "osx-x86_64"),
+      Download_Platform("x86_64-linux", "linux-x86_64"),
+      Download_Platform("x86_64-windows", "windows-x86_64"))
+
+
+  /* build stack */
+
+  val default_url = "https://github.com/commercialhaskell/stack/releases/download"
+  val default_version = "2.9.3"
+
+  def build_stack(
+    base_url: String = default_url,
+    version: String = default_version,
+    target_dir: Path = Path.current,
+    progress: Progress = new Progress
+  ): Unit = {
+    /* component name */
+
+    val component = "stack-" + version
+    val component_dir =
+      Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
+
+
+    /* download executables */
+
+    for (platform <- platforms) {
+      val platform_dir =
+        Isabelle_System.make_directory(component_dir.path + Path.explode(platform.platform_name))
+
+      val url =
+        Url.append_path(base_url,
+          "v" + version + "/stack-" + version + "-" + platform.download_name + ".tar.gz")
+
+      val exe = Path.explode("stack").exe_if(platform.is_windows)
+
+      Isabelle_System.with_tmp_file("archive", ext = "tar.gz") { archive_file =>
+        Isabelle_System.with_tmp_dir("tmp") { tmp_dir =>
+          Isabelle_System.download_file(url, archive_file, progress = progress)
+          Isabelle_System.extract(archive_file, tmp_dir, strip = true)
+          Isabelle_System.move_file(tmp_dir + exe, platform_dir)
+          File.set_executable(platform_dir + exe)
+        }
+      }
+    }
+
+
+    /* settings */
+
+    component_dir.write_settings("""
+ISABELLE_STACK="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/stack"
+""")
+
+
+    /* README */
+
+    File.write(component_dir.README,
+      """This is stack """ + version + """ -- the Haskell Tool Stack.
+
+See also https://www.haskellstack.org and executables from
+""" + base_url + """
+
+The oldest supported version of macOS is 10.14 Mojave.
+
+The downloaded files were renamed and made executable.
+
+
+        Makarius
+        """ + Date.Format.date(Date.now()) + "\n")
+
+
+    /* AUTHORS and COPYING */
+
+    // download "latest" versions as reasonable approximation
+    Isabelle_System.download_file("https://raw.githubusercontent.com/commercialhaskell/stack/master/LICENSE",
+        component_dir.LICENSE)
+  }
+
+
+  /* Isabelle tool wrapper */
+
+  val isabelle_tool =
+    Isabelle_Tool("component_stack", "build component for GHC stack", Scala_Project.here,
+      { args =>
+        var target_dir = Path.current
+        var base_url = default_url
+        var version = default_version
+
+        val getopts = Getopts("""
+Usage: isabelle component_stack [OPTIONS]
+
+  Options are:
+    -D DIR       target directory (default ".")
+    -U URL       download URL (default: """" + default_url + """")
+    -V VERSION   version (default: """" + default_version + """")
+
+  Build component for GHC stack.
+""",
+          "D:" -> (arg => target_dir = Path.explode(arg)),
+          "U:" -> (arg => base_url = arg),
+          "V:" -> (arg => version = arg))
+
+        val more_args = getopts(args)
+        if (more_args.nonEmpty) getopts.usage()
+
+        val progress = new Console_Progress()
+
+        build_stack(base_url = base_url, version = version, target_dir = target_dir,
+          progress = progress)
+      })
+}
--- a/src/Pure/System/isabelle_tool.scala	Tue Jul 11 12:12:21 2023 +0200
+++ b/src/Pure/System/isabelle_tool.scala	Tue Jul 11 15:01:38 2023 +0200
@@ -183,6 +183,7 @@
   Component_SPASS.isabelle_tool,
   Component_SQLite.isabelle_tool,
   Component_Scala.isabelle_tool,
+  Component_Stack.isabelle_tool,
   Component_Vampire.isabelle_tool,
   Component_VeriT.isabelle_tool,
   Component_Zipperposition.isabelle_tool,