author | wenzelm |
Mon, 25 Mar 2024 20:22:05 +0100 | |
changeset 79991 | 99511fa536a1 |
parent 79740 | ea1913c953ef |
child 80075 | 09e9819beef6 |
permissions | -rw-r--r-- |
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( |
|
78780
a611bbfeb9cd
updated to stack-2.13.1: include arm64-darwin, although it does not quite work yet (e.g. session "Haskell");
wenzelm
parents:
78301
diff
changeset
|
22 |
Download_Platform("arm64-darwin", "osx-aarch64"), |
78301 | 23 |
Download_Platform("arm64-linux", "linux-aarch64"), |
24 |
Download_Platform("x86_64-darwin", "osx-x86_64"), |
|
25 |
Download_Platform("x86_64-linux", "linux-x86_64"), |
|
26 |
Download_Platform("x86_64-windows", "windows-x86_64")) |
|
27 |
||
28 |
||
29 |
/* build stack */ |
|
30 |
||
31 |
val default_url = "https://github.com/commercialhaskell/stack/releases/download" |
|
79991
99511fa536a1
update to stack-2.15.3, stackage-lts-22.6, ghc-9.6.4;
wenzelm
parents:
79740
diff
changeset
|
32 |
val default_version = "2.15.3" |
78301 | 33 |
|
34 |
def build_stack( |
|
35 |
base_url: String = default_url, |
|
36 |
version: String = default_version, |
|
37 |
target_dir: Path = Path.current, |
|
38 |
progress: Progress = new Progress |
|
39 |
): Unit = { |
|
40 |
/* component name */ |
|
41 |
||
42 |
val component = "stack-" + version |
|
43 |
val component_dir = |
|
44 |
Components.Directory(target_dir + Path.basic(component)).create(progress = progress) |
|
45 |
||
46 |
||
47 |
/* download executables */ |
|
48 |
||
49 |
for (platform <- platforms) { |
|
50 |
val platform_dir = |
|
51 |
Isabelle_System.make_directory(component_dir.path + Path.explode(platform.platform_name)) |
|
52 |
||
53 |
val url = |
|
54 |
Url.append_path(base_url, |
|
55 |
"v" + version + "/stack-" + version + "-" + platform.download_name + ".tar.gz") |
|
56 |
||
57 |
val exe = Path.explode("stack").exe_if(platform.is_windows) |
|
58 |
||
59 |
Isabelle_System.with_tmp_file("archive", ext = "tar.gz") { archive_file => |
|
60 |
Isabelle_System.with_tmp_dir("tmp") { tmp_dir => |
|
61 |
Isabelle_System.download_file(url, archive_file, progress = progress) |
|
62 |
Isabelle_System.extract(archive_file, tmp_dir, strip = true) |
|
63 |
Isabelle_System.move_file(tmp_dir + exe, platform_dir) |
|
64 |
File.set_executable(platform_dir + exe) |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
||
70 |
/* settings */ |
|
71 |
||
72 |
component_dir.write_settings(""" |
|
78780
a611bbfeb9cd
updated to stack-2.13.1: include arm64-darwin, although it does not quite work yet (e.g. session "Haskell");
wenzelm
parents:
78301
diff
changeset
|
73 |
ISABELLE_STACK="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}/stack" |
78301 | 74 |
""") |
75 |
||
76 |
||
77 |
/* README */ |
|
78 |
||
79 |
File.write(component_dir.README, |
|
80 |
"""This is stack """ + version + """ -- the Haskell Tool Stack. |
|
81 |
||
82 |
See also https://www.haskellstack.org and executables from |
|
83 |
""" + base_url + """ |
|
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 |
Isabelle_System.download_file("https://raw.githubusercontent.com/commercialhaskell/stack/master/LICENSE", |
|
96 |
component_dir.LICENSE) |
|
97 |
} |
|
98 |
||
99 |
||
100 |
/* Isabelle tool wrapper */ |
|
101 |
||
102 |
val isabelle_tool = |
|
103 |
Isabelle_Tool("component_stack", "build component for GHC stack", Scala_Project.here, |
|
104 |
{ args => |
|
105 |
var target_dir = Path.current |
|
106 |
var base_url = default_url |
|
107 |
var version = default_version |
|
108 |
||
109 |
val getopts = Getopts(""" |
|
110 |
Usage: isabelle component_stack [OPTIONS] |
|
111 |
||
112 |
Options are: |
|
113 |
-D DIR target directory (default ".") |
|
114 |
-U URL download URL (default: """" + default_url + """") |
|
115 |
-V VERSION version (default: """" + default_version + """") |
|
116 |
||
117 |
Build component for GHC stack. |
|
118 |
""", |
|
119 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
120 |
"U:" -> (arg => base_url = arg), |
|
121 |
"V:" -> (arg => version = arg)) |
|
122 |
||
123 |
val more_args = getopts(args) |
|
124 |
if (more_args.nonEmpty) getopts.usage() |
|
125 |
||
126 |
val progress = new Console_Progress() |
|
127 |
||
128 |
build_stack(base_url = base_url, version = version, target_dir = target_dir, |
|
129 |
progress = progress) |
|
130 |
}) |
|
131 |
} |