src/Pure/System/components.scala
author wenzelm
Sun, 20 Nov 2022 23:53:39 +0100
changeset 76519 137cec33346f
parent 76518 b30b8e23383c
child 76540 83de6e9ae983
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73815
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
     1
/*  Title:      Pure/System/components.scala
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     3
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     4
Isabelle system components.
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     5
*/
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     6
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     7
package isabelle
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     8
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
     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
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    13
object Components {
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    14
  /* archive name */
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    15
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    16
  object Archive {
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    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
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    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
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    30
    def get_name(archive: String): String =
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    31
      unapply(archive) getOrElse
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    32
        error("Bad component archive name (expecting .tar.gz): " + quote(archive))
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    33
  }
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    34
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    35
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    36
  /* component collections */
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    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
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 70102
diff changeset
    41
  val default_components_base: Path = Path.explode("$ISABELLE_COMPONENTS_BASE")
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69430
diff changeset
    42
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    43
  def admin(dir: Path): Path = dir + Path.explode("Admin/components")
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    44
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    45
  def contrib(dir: Path = Path.current, name: String = ""): Path =
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    46
    dir + Path.explode("contrib") + Path.explode(name)
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    47
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    48
  def unpack(dir: Path, archive: Path, progress: Progress = new Progress): String = {
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    49
    val name = Archive.get_name(archive.file_name)
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    50
    progress.echo("Unpacking " + name)
69425
94f6ca69d983 clarified gnutar options: more uniform owner;
wenzelm
parents: 69418
diff changeset
    51
    Isabelle_System.gnutar("-xzf " + File.bash_path(archive), dir = dir).check
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    52
    name
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    53
  }
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    54
69401
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    55
  def resolve(base_dir: Path, names: List[String],
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    56
    target_dir: Option[Path] = None,
70102
e48ffba6b557 retain copy of required components;
wenzelm
parents: 69703
diff changeset
    57
    copy_dir: Option[Path] = None,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    58
    progress: Progress = new Progress
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    59
  ): Unit = {
72375
e48d93811ed7 clarified signature;
wenzelm
parents: 72353
diff changeset
    60
    Isabelle_System.make_directory(base_dir)
69398
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
    61
    for (name <- names) {
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    62
      val archive_name = Archive(name)
69401
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    63
      val archive = base_dir + Path.explode(archive_name)
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    64
      if (!archive.is_file) {
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
    65
        val remote = Components.default_component_repository + "/" + archive_name
73566
4e6b31ed7197 clarified signature: avoid tmp file;
wenzelm
parents: 73415
diff changeset
    66
        Isabelle_System.download_file(remote, archive, progress = progress)
69398
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
    67
      }
70102
e48ffba6b557 retain copy of required components;
wenzelm
parents: 69703
diff changeset
    68
      for (dir <- copy_dir) {
72375
e48d93811ed7 clarified signature;
wenzelm
parents: 72353
diff changeset
    69
        Isabelle_System.make_directory(dir)
73317
df49ca5da9d0 clarified modules: more like ML;
wenzelm
parents: 73277
diff changeset
    70
        Isabelle_System.copy_file(archive, dir)
70102
e48ffba6b557 retain copy of required components;
wenzelm
parents: 69703
diff changeset
    71
      }
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    72
      unpack(target_dir getOrElse base_dir, archive, progress = progress)
69398
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
    73
    }
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
    74
  }
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
    75
73637
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    76
  private val platforms_family: Map[Platform.Family.Value, Set[String]] =
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    77
    Map(
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    78
      Platform.Family.linux_arm -> Set("arm64-linux", "arm64_32-linux"),
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    79
      Platform.Family.linux -> Set("x86_64-linux", "x86_64_32-linux"),
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    80
      Platform.Family.macos ->
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    81
        Set("arm64-darwin", "arm64_32-darwin", "x86_64-darwin", "x86_64_32-darwin"),
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    82
      Platform.Family.windows ->
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    83
        Set("x86_64-cygwin", "x86_64-windows", "x86_64_32-windows", "x86-windows"))
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    84
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    85
  private val platforms_all: Set[String] =
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    86
    Set("x86-linux", "x86-cygwin") ++ platforms_family.iterator.flatMap(_._2)
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    87
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
    88
  def purge(dir: Path, platform: Platform.Family.Value): Unit = {
73637
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
    89
    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
    90
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    91
    File.find_files(dir.file,
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    92
      (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
    93
      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
    94
  }
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
    95
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    96
73815
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
    97
  /* component directories */
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
    98
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
    99
  def directories(): List[Path] =
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   100
    Path.split(Isabelle_System.getenv_strict("ISABELLE_COMPONENTS"))
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   101
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   102
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   103
  /* component directory content */
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   104
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   105
  object Directory {
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   106
    def apply(path: Path): Directory = new Directory(path.absolute)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   107
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   108
    def create(path: Path, progress: Progress = new Progress): Directory = {
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   109
      val component_dir = new Directory(path.absolute)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   110
      progress.echo("Creating component directory " + component_dir.path)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   111
      Isabelle_System.new_directory(component_dir.path)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   112
      Isabelle_System.make_directory(component_dir.etc)
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   113
      component_dir
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   114
    }
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   115
  }
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   116
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   117
  class Directory private(val path: Path) {
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   118
    override def toString: String = path.toString
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   119
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   120
    def etc: Path = path + Path.basic("etc")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   121
    def src: Path = path + Path.basic("src")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   122
    def lib: Path = path + Path.basic("lib")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   123
    def settings: Path = etc + Path.basic("settings")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   124
    def components: Path = etc + Path.basic("components")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   125
    def build_props: Path = etc + Path.basic("build.props")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   126
    def README: Path = path + Path.basic("README")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   127
    def LICENSE: Path = path + Path.basic("LICENSE")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   128
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   129
    def check: Boolean = settings.is_file || components.is_file
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   130
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   131
    def read_components(): List[String] =
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   132
      split_lines(File.read(components)).filter(_.nonEmpty)
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   133
    def write_components(lines: List[String]): Unit =
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   134
      File.write(components, terminate_lines(lines))
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   135
  }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   136
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   137
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   138
  /* component repository content */
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   139
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   140
  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
   141
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   142
  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
   143
    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
   144
  }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   145
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   146
  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
   147
    (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
   148
      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
   149
        case Nil => None
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   150
        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
   151
        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
   152
      })
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   153
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 70102
diff changeset
   154
  def write_components_sha1(entries: List[SHA1_Digest]): Unit =
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   155
    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
   156
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   157
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   158
  /** manage user components **/
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   159
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   160
  val components_path: Path = Path.explode("$ISABELLE_HOME_USER/etc/components")
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   161
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   162
  def read_components(): List[String] =
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   163
    if (components_path.is_file) Library.trim_split_lines(File.read(components_path))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   164
    else Nil
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   165
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   166
  def write_components(lines: List[String]): Unit = {
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   167
    Isabelle_System.make_directory(components_path.dir)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   168
    File.write(components_path, Library.terminate_lines(lines))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   169
  }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   170
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   171
  def update_components(add: Boolean, path0: Path, progress: Progress = new Progress): Unit = {
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   172
    val path = path0.expand.absolute
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   173
    if (!Directory(path).check && !Sessions.is_session_dir(path)) {
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   174
      error("Bad component directory: " + path)
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   175
    }
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   176
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   177
    val lines1 = read_components()
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   178
    val lines2 =
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   179
      lines1.filter(line =>
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   180
        line.isEmpty || line.startsWith("#") || !File.eq(Path.explode(line), path))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   181
    val lines3 = if (add) lines2 ::: List(path.implode) else lines2
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   182
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   183
    if (lines1 != lines3) write_components(lines3)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   184
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   185
    val prefix = if (lines1 == lines3) "Unchanged" else if (add) "Added" else "Removed"
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   186
    progress.echo(prefix + " component " + path)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   187
  }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   188
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   189
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   190
  /* main entry point */
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   191
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   192
  def main(args: Array[String]): Unit = {
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   193
    Command_Line.tool {
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   194
      for (arg <- args) {
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   195
        val add =
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   196
          if (arg.startsWith("+")) true
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   197
          else if (arg.startsWith("-")) false
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   198
          else error("Bad argument: " + quote(arg))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   199
        val path = Path.explode(arg.substring(1))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   200
        update_components(add, path, progress = new Console_Progress)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   201
      }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   202
    }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   203
  }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   204
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   205
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   206
  /** 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
   207
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   208
  def build_components(
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   209
    options: Options,
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   210
    components: List[Path],
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71601
diff changeset
   211
    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
   212
    publish: Boolean = false,
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   213
    force: Boolean = false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   214
    update_components_sha1: Boolean = false
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   215
  ): Unit = {
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   216
    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
   217
      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
   218
        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
   219
          case Archive(_) => path
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   220
          case name =>
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   221
            if (!path.is_dir) error("Bad component directory: " + path)
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   222
            else if (!Directory(path).check) {
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   223
              error("Malformed component directory: " + path +
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   224
                "\n  (requires etc/settings or etc/components)")
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   225
            }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   226
            else {
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   227
              val component_path = path.expand
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   228
              val archive_dir = component_path.dir
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   229
              val archive_name = Archive(name)
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   230
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   231
              val archive = archive_dir + Path.explode(archive_name)
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   232
              if (archive.is_file && !force) {
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   233
                error("Component archive already exists: " + archive)
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   234
              }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   235
69439
22d4cb91ea6d tuned message;
wenzelm
parents: 69434
diff changeset
   236
              progress.echo("Packaging " + archive_name)
69430
684935cbc8e1 proper path before tar -C context switch;
wenzelm
parents: 69429
diff changeset
   237
              Isabelle_System.gnutar("-czf " + File.bash_path(archive) + " " + Bash.string(name),
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   238
                dir = archive_dir).check
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   239
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   240
              archive
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   241
            }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   242
        }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   243
      }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   244
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   245
    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
   246
      val server = options.string("isabelle_components_server")
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   247
      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
   248
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   249
      using(SSH.open_session(options, server)) { ssh =>
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   250
        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
   251
        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
   252
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   253
        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
   254
          error("Bad remote directory: " + dir)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   255
        }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   256
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   257
        if (publish) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   258
          for (archive <- archives) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   259
            val archive_name = archive.file_name
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   260
            val name = Archive.get_name(archive_name)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   261
            val remote_component = components_dir + archive.base
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   262
            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
   263
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   264
            // component archive
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   265
            if (ssh.is_file(remote_component) && !force) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   266
              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
   267
            }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   268
            progress.echo("Uploading " + archive_name)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   269
            ssh.write_file(remote_component, archive)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   270
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   271
            // contrib directory
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   272
            val is_standard_component =
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   273
              Isabelle_System.with_tmp_dir("component") { tmp_dir =>
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   274
                Isabelle_System.gnutar("-xzf " + File.bash_path(archive), dir = tmp_dir).check
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   275
                Directory(tmp_dir + Path.explode(name)).check
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   276
              }
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   277
            if (is_standard_component) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   278
              if (ssh.is_dir(remote_contrib)) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   279
                if (force) ssh.rm_tree(remote_contrib)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   280
                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
   281
              }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   282
              progress.echo("Unpacking remote " + archive_name)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   283
              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
   284
                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
   285
            }
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   286
            else {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   287
              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
   288
            }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   289
          }
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   290
        }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   291
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   292
        // remote SHA1 digests
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   293
        if (update_components_sha1) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   294
          val lines =
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   295
            for {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   296
              entry <- ssh.read_dir(components_dir)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   297
              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
   298
                entry.endsWith(Archive.suffix)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   299
            }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   300
            yield {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   301
              progress.echo("Digesting remote " + entry)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   302
              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
   303
                "; sha1sum " + Bash.string(entry)).check.out
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   304
            }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   305
          write_components_sha1(read_components_sha1(lines))
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   306
        }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   307
      }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   308
    }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   309
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   310
    // local SHA1 digests
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   311
    {
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   312
      val new_entries =
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   313
        for (archive <- archives)
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   314
        yield {
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   315
          val name = archive.file_name
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   316
          progress.echo("Digesting local " + name)
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   317
          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
   318
        }
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   319
      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
   320
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   321
      write_components_sha1(
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   322
        new_entries :::
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   323
        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
   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
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
  /* Isabelle tool wrapper */
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   329
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   330
  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
   331
    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
   332
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   333
  val isabelle_tool =
72763
3cc73d00553c added document antiquotation @{tool};
wenzelm
parents: 72375
diff changeset
   334
    Isabelle_Tool("build_components", "build and publish Isabelle components",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   335
      Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   336
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   337
        var publish = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   338
        var update_components_sha1 = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   339
        var force = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   340
        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
   341
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   342
        def show_options: String =
75844
7d27944d7141 clarified signature: avoid public representation;
wenzelm
parents: 75394
diff changeset
   343
          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
   344
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   345
        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
   346
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
   347
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   348
  Options are:
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   349
    -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
   350
    -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
   351
    -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
   352
    -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
   353
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   354
  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
   355
  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
   356
73736
a8ff6e4ee661 tuned signature;
wenzelm
parents: 73637
diff changeset
   357
""" + Library.indent_lines(2, show_options) + "\n",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   358
          "P" -> (_ => publish = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   359
          "f" -> (_ => force = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   360
          "o:" -> (arg => options = options + arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   361
          "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
   362
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   363
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   364
        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
   365
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   366
        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
   367
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   368
        build_components(options, more_args.map(Path.explode), progress = progress,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   369
          publish = publish, force = force, update_components_sha1 = update_components_sha1)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   370
      })
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   371
}