81784
|
1 |
/* Title: Pure/Admin/component_elm.scala
|
|
2 |
Author: Fabian Huch, TU Muenchen
|
81764
|
3 |
|
|
4 |
Build Isabelle Elm component from official downloads. See also: https://elm-lang.org/
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object Component_Elm {
|
|
11 |
/* platform information */
|
|
12 |
|
|
13 |
sealed case class Download_Platform(platform_name: String, file_name: String) {
|
|
14 |
override def toString: String = platform_name
|
|
15 |
|
81777
|
16 |
def archive_name: String = file_name + ".gz"
|
81764
|
17 |
def download(base_url: String, version: String): String =
|
|
18 |
base_url + "/" + version + "/" + archive_name
|
81766
|
19 |
|
|
20 |
val exe: Path = Path.basic("elm").exe_if(platform_name.endsWith("-windows"))
|
81764
|
21 |
}
|
|
22 |
|
|
23 |
val platforms: List[Download_Platform] =
|
|
24 |
List(
|
|
25 |
Download_Platform("arm64-darwin", "binary-for-mac-64-bit-ARM"),
|
|
26 |
Download_Platform("x86_64-darwin", "binary-for-mac-64-bit"),
|
|
27 |
Download_Platform("x86_64-linux", "binary-for-linux-64-bit"),
|
|
28 |
Download_Platform("x86_64-windows", "binary-for-windows-64-bit"))
|
|
29 |
|
|
30 |
|
|
31 |
/* build elm */
|
|
32 |
|
|
33 |
val default_url = "https://github.com/elm/compiler/releases/download"
|
|
34 |
val default_version = "0.19.1"
|
|
35 |
|
|
36 |
def build_elm(
|
|
37 |
base_url: String = default_url,
|
|
38 |
version: String = default_version,
|
|
39 |
target_dir: Path = Path.current,
|
|
40 |
progress: Progress = new Progress
|
|
41 |
): Unit = {
|
|
42 |
Isabelle_System.require_command("gunzip")
|
|
43 |
|
|
44 |
|
|
45 |
/* component */
|
|
46 |
|
|
47 |
val component = "elm-" + version
|
|
48 |
val component_dir =
|
|
49 |
Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
|
|
50 |
|
|
51 |
|
|
52 |
/* download */
|
|
53 |
|
|
54 |
for (platform <- platforms) {
|
|
55 |
val platform_dir =
|
|
56 |
Isabelle_System.make_directory(component_dir.path + Path.basic(platform.platform_name))
|
|
57 |
|
|
58 |
val download = platform.download(base_url, version)
|
|
59 |
|
|
60 |
Isabelle_System.with_tmp_dir("download", component_dir.path.file) { download_dir =>
|
|
61 |
Isabelle_System.with_tmp_dir("tmp", component_dir.path.file) { tmp_dir =>
|
|
62 |
val archive_file = download_dir + Path.basic(platform.archive_name)
|
|
63 |
|
|
64 |
Isabelle_System.download_file(download, archive_file, progress = progress)
|
|
65 |
Isabelle_System.bash("gunzip " + File.bash_path(archive_file))
|
81766
|
66 |
Isabelle_System.copy_file(archive_file.drop_ext, platform_dir + platform.exe)
|
|
67 |
File.set_executable(platform_dir + platform.exe)
|
81764
|
68 |
}
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
|
72 |
/* license */
|
|
73 |
|
|
74 |
File.write(
|
|
75 |
component_dir.LICENSE,
|
|
76 |
Url.read("https://raw.githubusercontent.com/elm/compiler/master/LICENSE"))
|
|
77 |
|
|
78 |
|
|
79 |
/* settings */
|
|
80 |
|
|
81 |
component_dir.write_settings("""
|
81765
|
82 |
ISABELLE_ELM_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-${ISABELLE_APPLE_PLATFORM64:-$ISABELLE_PLATFORM64}}"
|
81764
|
83 |
""")
|
|
84 |
|
|
85 |
|
|
86 |
/* README */
|
|
87 |
|
|
88 |
File.write(component_dir.README,
|
|
89 |
"""This Isabelle component provides elm """ + version + """.
|
|
90 |
|
|
91 |
See also https://elm-lang.org and executables from """ + base_url + """
|
|
92 |
|
|
93 |
Fabian Huch
|
|
94 |
""" + Date.Format.date(Date.now()) + "\n")
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
/* Isabelle tool wrapper */
|
|
99 |
|
|
100 |
val isabelle_tool =
|
|
101 |
Isabelle_Tool("component_elm", "build elm component", Scala_Project.here,
|
|
102 |
{ args =>
|
|
103 |
var target_dir = Path.current
|
|
104 |
var base_url = default_url
|
|
105 |
var version = default_version
|
|
106 |
|
|
107 |
val getopts = Getopts("""
|
|
108 |
Usage: isabelle component_elm [OPTIONS]
|
|
109 |
|
|
110 |
Options are:
|
|
111 |
-D DIR target directory (default ".")
|
|
112 |
-U URL download URL (default: """" + default_url + """")
|
|
113 |
-V VERSION version (default: """" + default_version + """")
|
|
114 |
|
|
115 |
Build elm component.
|
|
116 |
""",
|
|
117 |
"D:" -> (arg => target_dir = Path.explode(arg)),
|
|
118 |
"U:" -> (arg => base_url = arg),
|
|
119 |
"V:" -> (arg => version = arg))
|
|
120 |
|
|
121 |
val more_args = getopts(args)
|
|
122 |
if (more_args.nonEmpty) getopts.usage()
|
|
123 |
|
|
124 |
val progress = new Console_Progress()
|
|
125 |
|
|
126 |
build_elm(base_url = base_url, version = version, target_dir = target_dir,
|
|
127 |
progress = progress)
|
|
128 |
})
|
|
129 |
} |