78301
|
1 |
/* Title: Pure/Admin/component_stack.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Build Isabelle component for GHC stack. See also:
|
|
5 |
|
|
6 |
- https://www.haskellstack.org
|
|
7 |
- https://github.com/commercialhaskell
|
|
8 |
*/
|
|
9 |
|
|
10 |
package isabelle
|
|
11 |
|
|
12 |
|
|
13 |
object Component_Stack {
|
|
14 |
/* platform information */
|
|
15 |
|
|
16 |
sealed case class Download_Platform(platform_name: String, download_name: String) {
|
|
17 |
def is_windows: Boolean = platform_name.endsWith("-windows")
|
|
18 |
}
|
|
19 |
|
|
20 |
val platforms: List[Download_Platform] =
|
|
21 |
List(
|
|
22 |
Download_Platform("arm64-linux", "linux-aarch64"),
|
|
23 |
Download_Platform("x86_64-darwin", "osx-x86_64"),
|
|
24 |
Download_Platform("x86_64-linux", "linux-x86_64"),
|
|
25 |
Download_Platform("x86_64-windows", "windows-x86_64"))
|
|
26 |
|
|
27 |
|
|
28 |
/* build stack */
|
|
29 |
|
|
30 |
val default_url = "https://github.com/commercialhaskell/stack/releases/download"
|
|
31 |
val default_version = "2.9.3"
|
|
32 |
|
|
33 |
def build_stack(
|
|
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 = "stack-" + 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 platform_dir =
|
|
50 |
Isabelle_System.make_directory(component_dir.path + Path.explode(platform.platform_name))
|
|
51 |
|
|
52 |
val url =
|
|
53 |
Url.append_path(base_url,
|
|
54 |
"v" + version + "/stack-" + version + "-" + platform.download_name + ".tar.gz")
|
|
55 |
|
|
56 |
val exe = Path.explode("stack").exe_if(platform.is_windows)
|
|
57 |
|
|
58 |
Isabelle_System.with_tmp_file("archive", ext = "tar.gz") { archive_file =>
|
|
59 |
Isabelle_System.with_tmp_dir("tmp") { tmp_dir =>
|
|
60 |
Isabelle_System.download_file(url, archive_file, progress = progress)
|
|
61 |
Isabelle_System.extract(archive_file, tmp_dir, strip = true)
|
|
62 |
Isabelle_System.move_file(tmp_dir + exe, platform_dir)
|
|
63 |
File.set_executable(platform_dir + exe)
|
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
/* settings */
|
|
70 |
|
|
71 |
component_dir.write_settings("""
|
|
72 |
ISABELLE_STACK="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/stack"
|
|
73 |
""")
|
|
74 |
|
|
75 |
|
|
76 |
/* README */
|
|
77 |
|
|
78 |
File.write(component_dir.README,
|
|
79 |
"""This is stack """ + version + """ -- the Haskell Tool Stack.
|
|
80 |
|
|
81 |
See also https://www.haskellstack.org and executables from
|
|
82 |
""" + base_url + """
|
|
83 |
|
|
84 |
The oldest supported version of macOS is 10.14 Mojave.
|
|
85 |
|
|
86 |
The downloaded files were renamed and made executable.
|
|
87 |
|
|
88 |
|
|
89 |
Makarius
|
|
90 |
""" + Date.Format.date(Date.now()) + "\n")
|
|
91 |
|
|
92 |
|
|
93 |
/* AUTHORS and COPYING */
|
|
94 |
|
|
95 |
// download "latest" versions as reasonable approximation
|
|
96 |
Isabelle_System.download_file("https://raw.githubusercontent.com/commercialhaskell/stack/master/LICENSE",
|
|
97 |
component_dir.LICENSE)
|
|
98 |
}
|
|
99 |
|
|
100 |
|
|
101 |
/* Isabelle tool wrapper */
|
|
102 |
|
|
103 |
val isabelle_tool =
|
|
104 |
Isabelle_Tool("component_stack", "build component for GHC stack", Scala_Project.here,
|
|
105 |
{ args =>
|
|
106 |
var target_dir = Path.current
|
|
107 |
var base_url = default_url
|
|
108 |
var version = default_version
|
|
109 |
|
|
110 |
val getopts = Getopts("""
|
|
111 |
Usage: isabelle component_stack [OPTIONS]
|
|
112 |
|
|
113 |
Options are:
|
|
114 |
-D DIR target directory (default ".")
|
|
115 |
-U URL download URL (default: """" + default_url + """")
|
|
116 |
-V VERSION version (default: """" + default_version + """")
|
|
117 |
|
|
118 |
Build component for GHC stack.
|
|
119 |
""",
|
|
120 |
"D:" -> (arg => target_dir = Path.explode(arg)),
|
|
121 |
"U:" -> (arg => base_url = arg),
|
|
122 |
"V:" -> (arg => version = arg))
|
|
123 |
|
|
124 |
val more_args = getopts(args)
|
|
125 |
if (more_args.nonEmpty) getopts.usage()
|
|
126 |
|
|
127 |
val progress = new Console_Progress()
|
|
128 |
|
|
129 |
build_stack(base_url = base_url, version = version, target_dir = target_dir,
|
|
130 |
progress = progress)
|
|
131 |
})
|
|
132 |
}
|