author | wenzelm |
Wed, 25 Jan 2023 13:16:43 +0100 | |
changeset 77090 | d3437203c1df |
parent 77088 | 6e2c6ccc5dc0 |
child 77097 | 023273cf2651 |
permissions | -rw-r--r-- |
73815 | 1 |
/* Title: Pure/System/components.scala |
69395 | 2 |
Author: Makarius |
3 |
||
4 |
Isabelle system components. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
69401
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
10 |
import java.io.{File => JFile} |
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
11 |
|
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
12 |
|
75393 | 13 |
object Components { |
69413 | 14 |
/* archive name */ |
15 |
||
75393 | 16 |
object Archive { |
69413 | 17 |
val suffix: String = ".tar.gz" |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
18 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
19 |
def apply(name: String): String = |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
20 |
if (name == "") error("Bad component name: " + quote(name)) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
21 |
else name + suffix |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
22 |
|
75393 | 23 |
def unapply(archive: String): Option[String] = { |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
24 |
for { |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
25 |
name0 <- Library.try_unsuffix(suffix, archive) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
26 |
name <- proper_string(name0) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
27 |
} yield name |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
28 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
29 |
|
69413 | 30 |
def get_name(archive: String): String = |
31 |
unapply(archive) getOrElse |
|
32 |
error("Bad component archive name (expecting .tar.gz): " + quote(archive)) |
|
33 |
} |
|
34 |
||
35 |
||
69395 | 36 |
/* component collections */ |
37 |
||
73240
3e963d68d394
more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents:
73173
diff
changeset
|
38 |
def default_component_repository: String = |
3e963d68d394
more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents:
73173
diff
changeset
|
39 |
Isabelle_System.getenv("ISABELLE_COMPONENT_REPOSITORY") |
3e963d68d394
more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents:
73173
diff
changeset
|
40 |
|
71601 | 41 |
val default_components_base: Path = Path.explode("$ISABELLE_COMPONENTS_BASE") |
77090 | 42 |
val standard_components_base: String = "${ISABELLE_COMPONENTS_BASE:-$USER_HOME/.isabelle/contrib}" |
69434 | 43 |
|
77055 | 44 |
val default_catalogs: List[String] = List("main") |
45 |
val optional_catalogs: List[String] = List("main", "optional") |
|
46 |
||
69395 | 47 |
def admin(dir: Path): Path = dir + Path.explode("Admin/components") |
48 |
||
49 |
def contrib(dir: Path = Path.current, name: String = ""): Path = |
|
50 |
dir + Path.explode("contrib") + Path.explode(name) |
|
51 |
||
77059 | 52 |
def unpack( |
53 |
dir: Path, |
|
54 |
archive: Path, |
|
55 |
ssh: SSH.System = SSH.Local, |
|
56 |
progress: Progress = new Progress |
|
57 |
): String = { |
|
69413 | 58 |
val name = Archive.get_name(archive.file_name) |
59 |
progress.echo("Unpacking " + name) |
|
77059 | 60 |
ssh.execute( |
77066 | 61 |
"tar -C " + ssh.bash_path(dir) + " -x -z -f " + ssh.bash_path(archive), |
77059 | 62 |
progress_stdout = progress.echo, |
63 |
progress_stderr = progress.echo).check |
|
69413 | 64 |
name |
65 |
} |
|
66 |
||
77059 | 67 |
def resolve( |
68 |
base_dir: Path, |
|
77067 | 69 |
name: String, |
69401
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
70 |
target_dir: Option[Path] = None, |
70102 | 71 |
copy_dir: Option[Path] = None, |
77057 | 72 |
component_repository: String = Components.default_component_repository, |
77059 | 73 |
ssh: SSH.System = SSH.Local, |
75393 | 74 |
progress: Progress = new Progress |
75 |
): Unit = { |
|
77059 | 76 |
ssh.make_directory(base_dir) |
77067 | 77 |
val archive_name = Archive(name) |
77068 | 78 |
val archive = base_dir + Path.basic(archive_name) |
77067 | 79 |
if (!ssh.is_file(archive)) { |
80 |
val remote = Url.append_path(component_repository, archive_name) |
|
81 |
ssh.download_file(remote, archive, progress = progress) |
|
69398
0698ded5caf1
Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents:
69395
diff
changeset
|
82 |
} |
77067 | 83 |
for (dir <- copy_dir) { |
84 |
ssh.make_directory(dir) |
|
85 |
ssh.copy_file(archive, dir) |
|
86 |
} |
|
87 |
unpack(target_dir getOrElse base_dir, archive, ssh = ssh, progress = progress) |
|
69398
0698ded5caf1
Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents:
69395
diff
changeset
|
88 |
} |
0698ded5caf1
Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents:
69395
diff
changeset
|
89 |
|
73637 | 90 |
private val platforms_family: Map[Platform.Family.Value, Set[String]] = |
91 |
Map( |
|
92 |
Platform.Family.linux_arm -> Set("arm64-linux", "arm64_32-linux"), |
|
93 |
Platform.Family.linux -> Set("x86_64-linux", "x86_64_32-linux"), |
|
94 |
Platform.Family.macos -> |
|
95 |
Set("arm64-darwin", "arm64_32-darwin", "x86_64-darwin", "x86_64_32-darwin"), |
|
96 |
Platform.Family.windows -> |
|
97 |
Set("x86_64-cygwin", "x86_64-windows", "x86_64_32-windows", "x86-windows")) |
|
98 |
||
99 |
private val platforms_all: Set[String] = |
|
100 |
Set("x86-linux", "x86-cygwin") ++ platforms_family.iterator.flatMap(_._2) |
|
101 |
||
75393 | 102 |
def purge(dir: Path, platform: Platform.Family.Value): Unit = { |
73637 | 103 |
val purge_set = platforms_all -- platforms_family(platform) |
69401
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
104 |
|
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
105 |
File.find_files(dir.file, |
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
106 |
(file: JFile) => file.isDirectory && purge_set(file.getName), |
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
107 |
include_dirs = true).foreach(Isabelle_System.rm_tree) |
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
108 |
} |
7a1b7b737c02
eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents:
69398
diff
changeset
|
109 |
|
69395 | 110 |
|
73815 | 111 |
/* component directories */ |
112 |
||
113 |
def directories(): List[Path] = |
|
114 |
Path.split(Isabelle_System.getenv_strict("ISABELLE_COMPONENTS")) |
|
115 |
||
116 |
||
69395 | 117 |
/* component directory content */ |
118 |
||
76518 | 119 |
object Directory { |
120 |
def apply(path: Path): Directory = new Directory(path.absolute) |
|
121 |
} |
|
122 |
||
123 |
class Directory private(val path: Path) { |
|
124 |
override def toString: String = path.toString |
|
125 |
||
126 |
def etc: Path = path + Path.basic("etc") |
|
127 |
def src: Path = path + Path.basic("src") |
|
128 |
def lib: Path = path + Path.basic("lib") |
|
129 |
def settings: Path = etc + Path.basic("settings") |
|
130 |
def components: Path = etc + Path.basic("components") |
|
131 |
def build_props: Path = etc + Path.basic("build.props") |
|
132 |
def README: Path = path + Path.basic("README") |
|
133 |
def LICENSE: Path = path + Path.basic("LICENSE") |
|
134 |
||
76547 | 135 |
def create(progress: Progress = new Progress): Directory = { |
136 |
progress.echo("Creating component directory " + path) |
|
137 |
Isabelle_System.new_directory(path) |
|
138 |
Isabelle_System.make_directory(etc) |
|
139 |
this |
|
140 |
} |
|
141 |
||
76550 | 142 |
def ok: Boolean = settings.is_file || components.is_file || Sessions.is_session_dir(path) |
143 |
||
144 |
def check: Directory = |
|
145 |
if (!path.is_dir) error("Bad component directory: " + path) |
|
146 |
else if (!ok) { |
|
147 |
error("Malformed component directory: " + path + |
|
148 |
"\n (missing \"etc/settings\" or \"etc/components\" or \"ROOT\" or \"ROOTS\")") |
|
149 |
} |
|
150 |
else this |
|
69395 | 151 |
|
76519 | 152 |
def read_components(): List[String] = |
153 |
split_lines(File.read(components)).filter(_.nonEmpty) |
|
154 |
def write_components(lines: List[String]): Unit = |
|
155 |
File.write(components, terminate_lines(lines)) |
|
76548 | 156 |
|
157 |
def write_settings(text: String): Unit = |
|
158 |
File.write(settings, "# -*- shell-script -*- :mode=shellscript:\n" + text) |
|
76519 | 159 |
} |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
160 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
161 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
162 |
/* component repository content */ |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
163 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
164 |
val components_sha1: Path = Path.explode("~~/Admin/components/components.sha1") |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
165 |
|
75393 | 166 |
sealed case class SHA1_Digest(digest: SHA1.Digest, name: String) { |
75350
93943e7e38a4
prefer Isabelle shasum over the old command-line tool with its extra marker character;
wenzelm
parents:
75349
diff
changeset
|
167 |
override def toString: String = digest.shasum(name) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
168 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
169 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
170 |
def read_components_sha1(lines: List[String] = Nil): List[SHA1_Digest] = |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
171 |
(proper_list(lines) getOrElse split_lines(File.read(components_sha1))).flatMap(line => |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
172 |
Word.explode(line) match { |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
173 |
case Nil => None |
75349 | 174 |
case List(sha1, name) => Some(SHA1_Digest(SHA1.fake_digest(sha1), name)) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
175 |
case _ => error("Bad components.sha1 entry: " + quote(line)) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
176 |
}) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
177 |
|
71601 | 178 |
def write_components_sha1(entries: List[SHA1_Digest]): Unit = |
75349 | 179 |
File.write(components_sha1, entries.sortBy(_.name).mkString("", "\n", "\n")) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
180 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
181 |
|
73172 | 182 |
/** manage user components **/ |
183 |
||
75349 | 184 |
val components_path: Path = Path.explode("$ISABELLE_HOME_USER/etc/components") |
73172 | 185 |
|
186 |
def read_components(): List[String] = |
|
187 |
if (components_path.is_file) Library.trim_split_lines(File.read(components_path)) |
|
188 |
else Nil |
|
189 |
||
75393 | 190 |
def write_components(lines: List[String]): Unit = { |
73172 | 191 |
Isabelle_System.make_directory(components_path.dir) |
192 |
File.write(components_path, Library.terminate_lines(lines)) |
|
193 |
} |
|
194 |
||
75393 | 195 |
def update_components(add: Boolean, path0: Path, progress: Progress = new Progress): Unit = { |
73172 | 196 |
val path = path0.expand.absolute |
76551
c7996b073524
clarified check: allow to remove bad directories;
wenzelm
parents:
76550
diff
changeset
|
197 |
if (add) Directory(path).check |
73172 | 198 |
|
199 |
val lines1 = read_components() |
|
200 |
val lines2 = |
|
201 |
lines1.filter(line => |
|
202 |
line.isEmpty || line.startsWith("#") || !File.eq(Path.explode(line), path)) |
|
203 |
val lines3 = if (add) lines2 ::: List(path.implode) else lines2 |
|
204 |
||
205 |
if (lines1 != lines3) write_components(lines3) |
|
206 |
||
207 |
val prefix = if (lines1 == lines3) "Unchanged" else if (add) "Added" else "Removed" |
|
208 |
progress.echo(prefix + " component " + path) |
|
209 |
} |
|
210 |
||
211 |
||
212 |
/* main entry point */ |
|
213 |
||
75393 | 214 |
def main(args: Array[String]): Unit = { |
73172 | 215 |
Command_Line.tool { |
216 |
for (arg <- args) { |
|
217 |
val add = |
|
218 |
if (arg.startsWith("+")) true |
|
219 |
else if (arg.startsWith("-")) false |
|
220 |
else error("Bad argument: " + quote(arg)) |
|
221 |
val path = Path.explode(arg.substring(1)) |
|
222 |
update_components(add, path, progress = new Console_Progress) |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
||
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
227 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
228 |
/** build and publish components **/ |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
229 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
230 |
def build_components( |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
231 |
options: Options, |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
232 |
components: List[Path], |
71726
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents:
71601
diff
changeset
|
233 |
progress: Progress = new Progress, |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
234 |
publish: Boolean = false, |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
235 |
force: Boolean = false, |
75393 | 236 |
update_components_sha1: Boolean = false |
237 |
): Unit = { |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
238 |
val archives: List[Path] = |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
239 |
for (path <- components) yield { |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
240 |
path.file_name match { |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
241 |
case Archive(_) => path |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
242 |
case name => |
76550 | 243 |
Directory(path).check |
244 |
val component_path = path.expand |
|
245 |
val archive_dir = component_path.dir |
|
246 |
val archive_name = Archive(name) |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
247 |
|
76550 | 248 |
val archive = archive_dir + Path.explode(archive_name) |
249 |
if (archive.is_file && !force) { |
|
250 |
error("Component archive already exists: " + archive) |
|
251 |
} |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
252 |
|
76550 | 253 |
progress.echo("Packaging " + archive_name) |
254 |
Isabelle_System.gnutar("-czf " + File.bash_path(archive) + " " + Bash.string(name), |
|
255 |
dir = archive_dir).check |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
256 |
|
76550 | 257 |
archive |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
258 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
259 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
260 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
261 |
if ((publish && archives.nonEmpty) || update_components_sha1) { |
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
262 |
val server = options.string("isabelle_components_server") |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
263 |
if (server.isEmpty) error("Undefined option isabelle_components_server") |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
264 |
|
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
265 |
using(SSH.open_session(options, server)) { ssh => |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
266 |
val components_dir = Path.explode(options.string("isabelle_components_dir")) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
267 |
val contrib_dir = Path.explode(options.string("isabelle_components_contrib_dir")) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
268 |
|
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
269 |
for (dir <- List(components_dir, contrib_dir) if !ssh.is_dir(dir)) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
270 |
error("Bad remote directory: " + dir) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
271 |
} |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
272 |
|
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
273 |
if (publish) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
274 |
for (archive <- archives) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
275 |
val archive_name = archive.file_name |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
276 |
val name = Archive.get_name(archive_name) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
277 |
val remote_component = components_dir + archive.base |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
278 |
val remote_contrib = contrib_dir + Path.explode(name) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
279 |
|
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
280 |
// component archive |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
281 |
if (ssh.is_file(remote_component) && !force) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
282 |
error("Remote component archive already exists: " + remote_component) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
283 |
} |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
284 |
progress.echo("Uploading " + archive_name) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
285 |
ssh.write_file(remote_component, archive) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
286 |
|
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
287 |
// contrib directory |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
288 |
val is_standard_component = |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
289 |
Isabelle_System.with_tmp_dir("component") { tmp_dir => |
76540
83de6e9ae983
clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents:
76519
diff
changeset
|
290 |
Isabelle_System.extract(archive, tmp_dir) |
76550 | 291 |
Directory(tmp_dir + Path.explode(name)).ok |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
292 |
} |
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
293 |
if (is_standard_component) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
294 |
if (ssh.is_dir(remote_contrib)) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
295 |
if (force) ssh.rm_tree(remote_contrib) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
296 |
else error("Remote component directory already exists: " + remote_contrib) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
297 |
} |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
298 |
progress.echo("Unpacking remote " + archive_name) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
299 |
ssh.execute("tar -C " + ssh.bash_path(contrib_dir) + " -xzf " + |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
300 |
ssh.bash_path(remote_component)).check |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
301 |
} |
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
302 |
else { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
303 |
progress.echo_warning("No unpacking of non-standard component: " + archive_name) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
304 |
} |
75394 | 305 |
} |
76169
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
306 |
} |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
307 |
|
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
308 |
// remote SHA1 digests |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
309 |
if (update_components_sha1) { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
310 |
val lines = |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
311 |
for { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
312 |
entry <- ssh.read_dir(components_dir) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
313 |
if ssh.is_file(components_dir + Path.basic(entry)) && |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
314 |
entry.endsWith(Archive.suffix) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
315 |
} |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
316 |
yield { |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
317 |
progress.echo("Digesting remote " + entry) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
318 |
ssh.execute("cd " + ssh.bash_path(components_dir) + |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
319 |
"; sha1sum " + Bash.string(entry)).check.out |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
320 |
} |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
321 |
write_components_sha1(read_components_sha1(lines)) |
a3c694039fd6
discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents:
76122
diff
changeset
|
322 |
} |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
323 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
324 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
325 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
326 |
// local SHA1 digests |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
327 |
{ |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
328 |
val new_entries = |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
329 |
for (archive <- archives) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
330 |
yield { |
75349 | 331 |
val name = archive.file_name |
332 |
progress.echo("Digesting local " + name) |
|
333 |
SHA1_Digest(SHA1.digest(archive), name) |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
334 |
} |
75349 | 335 |
val new_names = new_entries.map(_.name).toSet |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
336 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
337 |
write_components_sha1( |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
338 |
new_entries ::: |
75349 | 339 |
read_components_sha1().filterNot(entry => new_names.contains(entry.name))) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
340 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
341 |
} |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
342 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
343 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
344 |
/* Isabelle tool wrapper */ |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
345 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
346 |
private val relevant_options = |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
347 |
List("isabelle_components_server", "isabelle_components_dir", "isabelle_components_contrib_dir") |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
348 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
349 |
val isabelle_tool = |
72763 | 350 |
Isabelle_Tool("build_components", "build and publish Isabelle components", |
75394 | 351 |
Scala_Project.here, |
352 |
{ args => |
|
353 |
var publish = false |
|
354 |
var update_components_sha1 = false |
|
355 |
var force = false |
|
356 |
var options = Options.init() |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
357 |
|
75394 | 358 |
def show_options: String = |
75844
7d27944d7141
clarified signature: avoid public representation;
wenzelm
parents:
75394
diff
changeset
|
359 |
cat_lines(relevant_options.flatMap(options.get).map(_.print)) |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
360 |
|
75394 | 361 |
val getopts = Getopts(""" |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
362 |
Usage: isabelle build_components [OPTIONS] ARCHIVES... DIRS... |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
363 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
364 |
Options are: |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
365 |
-P publish on SSH server (see options below) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
366 |
-f force: overwrite existing component archives and directories |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
367 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
368 |
-u update all SHA1 keys in Isabelle repository Admin/components |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
369 |
|
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
370 |
Build and publish Isabelle components as .tar.gz archives on SSH server, |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
371 |
depending on system options: |
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
372 |
|
73736 | 373 |
""" + Library.indent_lines(2, show_options) + "\n", |
75394 | 374 |
"P" -> (_ => publish = true), |
375 |
"f" -> (_ => force = true), |
|
376 |
"o:" -> (arg => options = options + arg), |
|
377 |
"u" -> (_ => update_components_sha1 = true)) |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
378 |
|
75394 | 379 |
val more_args = getopts(args) |
380 |
if (more_args.isEmpty && !update_components_sha1) getopts.usage() |
|
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
381 |
|
75394 | 382 |
val progress = new Console_Progress |
69429
dc5fbcb07c7b
replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents:
69426
diff
changeset
|
383 |
|
75394 | 384 |
build_components(options, more_args.map(Path.explode), progress = progress, |
385 |
publish = publish, force = force, update_components_sha1 = update_components_sha1) |
|
386 |
}) |
|
69395 | 387 |
} |