src/Pure/System/components.scala
author wenzelm
Wed, 12 Feb 2025 13:32:04 +0100
changeset 82145 5b8639cb0d11
parent 80225 d9ff4296e3b7
permissions -rw-r--r--
tuned: fewer warnings with scalac -Wunused:all;
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
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    10
import scala.jdk.CollectionConverters._
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    11
69401
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
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    36
  /* platforms */
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    37
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    38
  sealed case class Platforms(family_platforms: Map[String, List[Path]]) {
80001
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
    39
    def + (entry: (String, List[Path])): Platforms = Platforms(family_platforms + entry)
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    40
    def defined(family: String): Boolean = family_platforms.isDefinedAt(family)
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    41
    def apply(family: String): List[Path] = family_platforms.getOrElse(family, Nil)
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    42
    def path_iterator: Iterator[Path] = family_platforms.valuesIterator.flatten
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    43
  }
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    44
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    45
  val default_platforms: Platforms = {
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    46
    def paths(args: String*): List[Path] = args.toList.map(Path.explode)
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    47
    Platforms(
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    48
      Map(
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    49
        Platform.Family.linux_arm.toString ->
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    50
          paths("arm64-linux", "arm64_32-linux"),
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    51
        Platform.Family.linux.toString ->
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    52
          paths("x86_64-linux", "x86_64_32-linux"),
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    53
        Platform.Family.macos.toString ->
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    54
          paths("arm64-darwin", "arm64_32-darwin", "x86_64-darwin", "x86_64_32-darwin"),
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
    55
        Platform.Family.windows.toString ->
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    56
          paths("x86_64-cygwin", "x86_64-windows", "x86_64_32-windows", "x86-windows"),
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    57
        "obsolete" -> paths("x86-linux", "x86-cygwin")
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    58
      ))
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
    59
  }
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    60
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    61
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    62
  /* component collections */
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    63
77128
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77098
diff changeset
    64
  def static_component_repository: String =
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
    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
    66
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 70102
diff changeset
    67
  val default_components_base: Path = Path.explode("$ISABELLE_COMPONENTS_BASE")
77128
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77098
diff changeset
    68
  val dynamic_components_base: String = "${ISABELLE_COMPONENTS_BASE:-$USER_HOME/.isabelle/contrib}"
77762
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
    69
  val classic_components_base: Path = Path.explode("$USER_HOME/.isabelle/contrib")
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69430
diff changeset
    70
77055
f56800b8b085 clarified defaults;
wenzelm
parents: 76551
diff changeset
    71
  val default_catalogs: List[String] = List("main")
f56800b8b085 clarified defaults;
wenzelm
parents: 76551
diff changeset
    72
  val optional_catalogs: List[String] = List("main", "optional")
f56800b8b085 clarified defaults;
wenzelm
parents: 76551
diff changeset
    73
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    74
  def admin(dir: Path): Path = dir + Path.explode("Admin/components")
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    75
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    76
  def contrib(dir: Path = Path.current, name: String = ""): Path =
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    77
    dir + Path.explode("contrib") + Path.explode(name)
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
    78
77059
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    79
  def unpack(
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    80
    dir: Path,
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    81
    archive: Path,
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    82
    ssh: SSH.System = SSH.Local,
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    83
    progress: Progress = new Progress
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    84
  ): String = {
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    85
    val name = Archive.get_name(archive.file_name)
77098
9d6118cdc0fd tuned message, following "isabelle components -a";
wenzelm
parents: 77097
diff changeset
    86
    progress.echo("Unpacking " + archive.base)
77059
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
    87
    ssh.execute(
77066
72d87e32b062 proper ssh.bash_path;
wenzelm
parents: 77059
diff changeset
    88
      "tar -C " + ssh.bash_path(dir) + " -x -z -f " + ssh.bash_path(archive),
77509
3bc49507bae5 clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents: 77216
diff changeset
    89
      progress_stdout = progress.echo(_),
3bc49507bae5 clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents: 77216
diff changeset
    90
      progress_stderr = progress.echo(_)).check
69413
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    91
    name
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    92
  }
52727566c1ba more explicit Components.Archive;
wenzelm
parents: 69410
diff changeset
    93
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    94
  def clean_base(
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    95
    base_dir: Path,
78610
fd1fec53665b clarified signature: prefer enum types;
wenzelm
parents: 77789
diff changeset
    96
    platforms: List[Platform.Family] = Platform.Family.list,
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    97
    ssh: SSH.System = SSH.Local,
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    98
    progress: Progress = new Progress
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
    99
  ): Unit = {
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   100
    for {
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   101
      name <- ssh.read_dir(base_dir)
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   102
      dir = base_dir + Path.basic(name)
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   103
      if is_component_dir(dir)
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
   104
    } Directory(dir, ssh = ssh).clean(preserve = platforms, progress = progress)
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   105
  }
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   106
77059
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
   107
  def resolve(
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
   108
    base_dir: Path,
77067
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   109
    name: String,
69401
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
   110
    target_dir: Option[Path] = None,
70102
e48ffba6b557 retain copy of required components;
wenzelm
parents: 69703
diff changeset
   111
    copy_dir: Option[Path] = None,
78610
fd1fec53665b clarified signature: prefer enum types;
wenzelm
parents: 77789
diff changeset
   112
    clean_platforms: Option[List[Platform.Family]] = None,
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   113
    clean_archives: Boolean = false,
77128
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77098
diff changeset
   114
    component_repository: String = Components.static_component_repository,
77059
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
   115
    ssh: SSH.System = SSH.Local,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   116
    progress: Progress = new Progress
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   117
  ): Unit = {
77059
422c57b75b17 support remote operations;
wenzelm
parents: 77058
diff changeset
   118
    ssh.make_directory(base_dir)
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   119
77067
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   120
    val archive_name = Archive(name)
77068
ef1831744f00 more strict;
wenzelm
parents: 77067
diff changeset
   121
    val archive = base_dir + Path.basic(archive_name)
77067
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   122
    if (!ssh.is_file(archive)) {
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   123
      val remote = Url.append_path(component_repository, archive_name)
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   124
      ssh.download_file(remote, archive, progress = progress)
69398
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
   125
    }
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   126
77067
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   127
    for (dir <- copy_dir) {
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   128
      ssh.make_directory(dir)
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   129
      ssh.copy_file(archive, dir)
9ca1e7fc2663 tuned signature;
wenzelm
parents: 77066
diff changeset
   130
    }
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   131
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   132
    val unpack_dir = target_dir getOrElse base_dir
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   133
    unpack(unpack_dir, archive, ssh = ssh, progress = progress)
69398
0698ded5caf1 Components.download similar to "isabelle components", but without unpacking;
wenzelm
parents: 69395
diff changeset
   134
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   135
    if (clean_platforms.isDefined) {
79977
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   136
      Directory(unpack_dir + Path.basic(name), ssh = ssh).
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
   137
        clean(preserve = clean_platforms.get, progress = progress)
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   138
    }
73637
f3a356c64193 support for platform family "linux_arm";
wenzelm
parents: 73636
diff changeset
   139
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   140
    if (clean_archives) {
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   141
      progress.echo("Removing " + quote(archive_name))
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   142
      ssh.delete(archive)
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   143
    }
69401
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
   144
  }
7a1b7b737c02 eliminated old makedist_bundle and remote_dmg: build_release does everything in Scala;
wenzelm
parents: 69398
diff changeset
   145
77762
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   146
  def provide(local_dir: Path,
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   147
    base_dir: Path = classic_components_base,
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   148
    ssh: SSH.System = SSH.Local,
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   149
    progress: Progress = new Progress
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   150
  ): Directory = {
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   151
    val base_name = local_dir.expand.base
82145
5b8639cb0d11 tuned: fewer warnings with scalac -Wunused:all;
wenzelm
parents: 80225
diff changeset
   152
    Directory(local_dir).check
77762
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   153
    val remote_directory = Directory(base_dir + base_name, ssh = ssh)
80219
840ca997deac minor performance tuning: save approx. 70ms per SSH test command;
wenzelm
parents: 80050
diff changeset
   154
    if (remote_directory.ok) remote_directory
840ca997deac minor performance tuning: save approx. 70ms per SSH test command;
wenzelm
parents: 80050
diff changeset
   155
    else {
77762
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   156
      progress.echo("Providing " + base_name + ssh.print)
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   157
      Isabelle_System.with_tmp_file("tmp", ext = "tar") { local_tmp_tar =>
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   158
        ssh.with_tmp_dir { remote_tmp_dir =>
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   159
          val remote_tmp_tar = remote_tmp_dir + Path.basic("tmp.tar")
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   160
          val remote_dir = ssh.make_directory(remote_directory.path)
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   161
          Isabelle_System.gnutar(
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   162
            "-cf " + File.bash_path(local_tmp_tar) + " .", dir = local_dir).check
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   163
          ssh.write_file(remote_tmp_tar, local_tmp_tar)
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   164
          ssh.execute(
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   165
            "tar -C " + ssh.bash_path(remote_dir) + " -xf " + ssh.bash_path(remote_tmp_tar)).check
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   166
        }
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   167
      }
80219
840ca997deac minor performance tuning: save approx. 70ms per SSH test command;
wenzelm
parents: 80050
diff changeset
   168
      remote_directory.check
77762
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   169
    }
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   170
  }
f73400337c5c provide local component to remote directory;
wenzelm
parents: 77760
diff changeset
   171
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   172
73815
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   173
  /* component directories */
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   174
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   175
  def directories(): List[Path] =
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   176
    Path.split(Isabelle_System.getenv_strict("ISABELLE_COMPONENTS"))
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   177
77097
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   178
  def is_component_dir(dir: Path, ssh: SSH.System = SSH.Local): Boolean =
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   179
    ssh.is_file(dir + Path.explode("etc/settings")) ||
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   180
    ssh.is_file(dir + Path.explode("etc/components"))
023273cf2651 clean components more accurately: purge other platforms or archives;
wenzelm
parents: 77090
diff changeset
   181
73815
43882e34c038 clarified modules;
wenzelm
parents: 73814
diff changeset
   182
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   183
  /* component directory content */
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   184
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   185
  object Directory {
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   186
    def apply(path: Path, ssh: SSH.System = SSH.Local): Directory =
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   187
      new Directory(ssh.absolute_path(path), ssh)
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   188
  }
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   189
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   190
  class Directory private(val path: Path, val ssh: SSH.System = SSH.Local) {
77789
59ab77f7d021 clarified output;
wenzelm
parents: 77762
diff changeset
   191
    override def toString: String = path.toString + ssh.print
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   192
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   193
    def etc: Path = path + Path.basic("etc")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   194
    def src: Path = path + Path.basic("src")
79976
c7e6a508a65b build Isabelle component for Go: all platforms;
wenzelm
parents: 78610
diff changeset
   195
    def bin: Path = path + Path.basic("bin")
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   196
    def lib: Path = path + Path.basic("lib")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   197
    def settings: Path = etc + Path.basic("settings")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   198
    def components: Path = etc + Path.basic("components")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   199
    def build_props: Path = etc + Path.basic("build.props")
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   200
    def platform_props: Path = etc + Path.basic("platform.props")
76518
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   201
    def README: Path = path + Path.basic("README")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   202
    def LICENSE: Path = path + Path.basic("LICENSE")
b30b8e23383c clarified signature: more explicit types;
wenzelm
parents: 76169
diff changeset
   203
80011
b082476a8036 dynamic setup of Go component, similar to Dotnet;
wenzelm
parents: 80001
diff changeset
   204
    def create(progress: Progress = new Progress, permissive: Boolean = false): Directory = {
b082476a8036 dynamic setup of Go component, similar to Dotnet;
wenzelm
parents: 80001
diff changeset
   205
      if (!permissive || !ssh.is_dir(path)) {
b082476a8036 dynamic setup of Go component, similar to Dotnet;
wenzelm
parents: 80001
diff changeset
   206
        progress.echo("Creating component directory " + toString)
b082476a8036 dynamic setup of Go component, similar to Dotnet;
wenzelm
parents: 80001
diff changeset
   207
        ssh.new_directory(path)
b082476a8036 dynamic setup of Go component, similar to Dotnet;
wenzelm
parents: 80001
diff changeset
   208
      }
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   209
      ssh.make_directory(etc)
76547
9fe5d8c70352 tuned signature;
wenzelm
parents: 76540
diff changeset
   210
      this
9fe5d8c70352 tuned signature;
wenzelm
parents: 76540
diff changeset
   211
    }
9fe5d8c70352 tuned signature;
wenzelm
parents: 76540
diff changeset
   212
80048
a213dd3c0b29 tuned signature;
wenzelm
parents: 80011
diff changeset
   213
    def write_platforms(
a213dd3c0b29 tuned signature;
wenzelm
parents: 80011
diff changeset
   214
      lines: List[String] = Platform.Family.list.map(family => family.toString + " = ")
80050
7d8a24c5559d tuned signature;
wenzelm
parents: 80048
diff changeset
   215
    ): Directory = {
7d8a24c5559d tuned signature;
wenzelm
parents: 80048
diff changeset
   216
      File.write(platform_props, terminate_lines(lines))
7d8a24c5559d tuned signature;
wenzelm
parents: 80048
diff changeset
   217
      this
7d8a24c5559d tuned signature;
wenzelm
parents: 80048
diff changeset
   218
    }
80048
a213dd3c0b29 tuned signature;
wenzelm
parents: 80011
diff changeset
   219
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   220
    def get_platforms(): Platforms = {
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   221
      val props_path = platform_props.expand
80001
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   222
      val props =
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   223
        if (props_path.is_file) {
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   224
          try {
80001
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   225
            for (case (a, b) <- File.read_props(props_path).asScala.toList)
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   226
              yield {
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   227
                if (!default_platforms.defined(a)) error("Bad platform family " + quote(a))
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   228
                val ps = List.from(b.split("\\s+").iterator.filter(_.nonEmpty)).map(Path.explode)
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   229
                for (p <- ps if !p.all_basic) error("Bad path outside component " + p)
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   230
                a -> ps
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   231
              }
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   232
          }
80001
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   233
          catch { case ERROR(msg) => error(msg + Position.here(Position.File(props_path.implode))) }
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   234
        }
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   235
        else Nil
98384596b54b clarified meaning of platform.props: update on default;
wenzelm
parents: 79981
diff changeset
   236
      props.foldLeft(default_platforms)(_ + _)
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   237
    }
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   238
79977
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   239
    def clean(
79978
2cc5182cbb08 clarified modules;
wenzelm
parents: 79977
diff changeset
   240
      preserve: List[Platform.Family] = Platform.Family.list,
79977
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   241
      progress: Progress = new Progress
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   242
    ): Unit = {
79981
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   243
      val platforms = get_platforms()
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   244
      val preserve_path = Set.from(for (a <- preserve; p <- platforms(a.toString)) yield p)
bdea4eccd8d5 support for etc/platform.props, to specify multi-platform directory structure more accurately;
wenzelm
parents: 79978
diff changeset
   245
      for (dir <- platforms.path_iterator if !preserve_path(dir) && ssh.is_dir(path + dir)) {
79977
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   246
        progress.echo("Removing " + (path.base + dir))
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   247
        ssh.rm_tree(path + dir)
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   248
      }
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   249
    }
612f0bb14124 clarified modules;
wenzelm
parents: 79976
diff changeset
   250
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   251
    def ok: Boolean =
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   252
      ssh.is_file(settings) || ssh.is_file(components) || Sessions.is_session_dir(path, ssh = ssh)
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   253
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   254
    def check: Directory =
80219
840ca997deac minor performance tuning: save approx. 70ms per SSH test command;
wenzelm
parents: 80050
diff changeset
   255
      if (ok) this
840ca997deac minor performance tuning: save approx. 70ms per SSH test command;
wenzelm
parents: 80050
diff changeset
   256
      else if (!ssh.is_dir(path)) error("Bad component directory: " + toString)
840ca997deac minor performance tuning: save approx. 70ms per SSH test command;
wenzelm
parents: 80050
diff changeset
   257
      else {
77789
59ab77f7d021 clarified output;
wenzelm
parents: 77762
diff changeset
   258
        error("Malformed component directory: " + toString +
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   259
          "\n  (missing \"etc/settings\" or \"etc/components\" or \"ROOT\" or \"ROOTS\")")
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   260
      }
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   261
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   262
    def read_components(): List[String] =
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   263
      split_lines(ssh.read(components)).filter(_.nonEmpty)
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   264
    def write_components(lines: List[String]): Unit =
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   265
      ssh.write(components, terminate_lines(lines))
76548
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
   266
0af64cc2eee9 tuned signature;
wenzelm
parents: 76547
diff changeset
   267
    def write_settings(text: String): Unit =
77760
34178d26a360 more SSH operations;
wenzelm
parents: 77592
diff changeset
   268
      ssh.write(settings, "# -*- shell-script -*- :mode=shellscript:\n" + text)
76519
137cec33346f clarified signature;
wenzelm
parents: 76518
diff changeset
   269
  }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   270
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   271
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   272
  /* component repository content */
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   273
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   274
  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
   275
77209
3070001c9d1f tuned signature;
wenzelm
parents: 77128
diff changeset
   276
  sealed case class SHA1_Entry(digest: SHA1.Digest, name: String) {
3070001c9d1f tuned signature;
wenzelm
parents: 77128
diff changeset
   277
    override def toString: String = SHA1.shasum(digest, name).toString
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   278
  }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   279
77209
3070001c9d1f tuned signature;
wenzelm
parents: 77128
diff changeset
   280
  def read_components_sha1(lines: List[String] = Nil): List[SHA1_Entry] =
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   281
    (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
   282
      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
   283
        case Nil => None
77209
3070001c9d1f tuned signature;
wenzelm
parents: 77128
diff changeset
   284
        case List(sha1, name) => Some(SHA1_Entry(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
   285
        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
   286
      })
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   287
77209
3070001c9d1f tuned signature;
wenzelm
parents: 77128
diff changeset
   288
  def write_components_sha1(entries: List[SHA1_Entry]): Unit =
77592
832139c1b268 proper shasum lines (amending 3070001c9d1f);
wenzelm
parents: 77565
diff changeset
   289
    File.write(components_sha1, entries.sortBy(_.name).mkString)
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   290
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   291
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   292
  /** manage user components **/
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   293
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   294
  val components_path: Path = Path.explode("$ISABELLE_HOME_USER/etc/components")
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   295
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   296
  def read_components(): List[String] =
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   297
    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
   298
    else Nil
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   299
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   300
  def write_components(lines: List[String]): Unit = {
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   301
    Isabelle_System.make_directory(components_path.dir)
77216
ee7dc5151db5 tuned signature;
wenzelm
parents: 77209
diff changeset
   302
    File.write(components_path, terminate_lines(lines))
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   303
  }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   304
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   305
  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
   306
    val path = path0.expand.absolute
76551
c7996b073524 clarified check: allow to remove bad directories;
wenzelm
parents: 76550
diff changeset
   307
    if (add) Directory(path).check
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   308
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   309
    val lines1 = read_components()
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   310
    val lines2 =
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   311
      lines1.filter(line =>
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   312
        line.isEmpty || line.startsWith("#") || !File.eq(Path.explode(line), path))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   313
    val lines3 = if (add) lines2 ::: List(path.implode) else lines2
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   314
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   315
    if (lines1 != lines3) write_components(lines3)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   316
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   317
    val prefix = if (lines1 == lines3) "Unchanged" else if (add) "Added" else "Removed"
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   318
    progress.echo(prefix + " component " + path)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   319
  }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   320
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   321
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   322
  /* main entry point */
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   323
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   324
  def main(args: Array[String]): Unit = {
73172
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   325
    Command_Line.tool {
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   326
      for (arg <- args) {
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   327
        val add =
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   328
          if (arg.startsWith("+")) true
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   329
          else if (arg.startsWith("-")) false
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   330
          else error("Bad argument: " + quote(arg))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   331
        val path = Path.explode(arg.substring(1))
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   332
        update_components(add, path, progress = new Console_Progress)
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   333
      }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   334
    }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   335
  }
fc828f64da5b support isabelle components -u and -x;
wenzelm
parents: 73090
diff changeset
   336
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   337
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   338
  /** 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
   339
77565
fd87490429aa renamed "isabelle build_components" to "isabelle components_build" (unrelated to "isabelle build");
wenzelm
parents: 77509
diff changeset
   340
  def components_build(
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   341
    options: Options,
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   342
    components: List[Path],
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71601
diff changeset
   343
    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
   344
    publish: Boolean = false,
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   345
    force: Boolean = false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   346
    update_components_sha1: Boolean = false
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 75350
diff changeset
   347
  ): Unit = {
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   348
    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
   349
      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
   350
        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
   351
          case Archive(_) => path
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   352
          case name =>
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   353
            Directory(path).check
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   354
            val component_path = path.expand
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   355
            val archive_dir = component_path.dir
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   356
            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
   357
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   358
            val archive = archive_dir + Path.explode(archive_name)
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   359
            if (archive.is_file && !force) {
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   360
              error("Component archive already exists: " + archive)
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   361
            }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   362
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   363
            progress.echo("Packaging " + archive_name)
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   364
            Isabelle_System.gnutar("-czf " + File.bash_path(archive) + " " + Bash.string(name),
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   365
              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
   366
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   367
            archive
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   368
        }
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
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   371
    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
   372
      val server = options.string("isabelle_components_server")
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   373
      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
   374
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   375
      using(SSH.open_session(options, server)) { ssh =>
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   376
        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
   377
        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
   378
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   379
        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
   380
          error("Bad remote directory: " + dir)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   381
        }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   382
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   383
        if (publish) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   384
          for (archive <- archives) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   385
            val archive_name = archive.file_name
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   386
            val name = Archive.get_name(archive_name)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   387
            val remote_component = components_dir + archive.base
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   388
            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
   389
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   390
            // component archive
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   391
            if (ssh.is_file(remote_component) && !force) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   392
              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
   393
            }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   394
            progress.echo("Uploading " + archive_name)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   395
            ssh.write_file(remote_component, archive)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   396
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   397
            // contrib directory
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   398
            val is_standard_component =
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   399
              Isabelle_System.with_tmp_dir("component") { tmp_dir =>
76540
83de6e9ae983 clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents: 76519
diff changeset
   400
                Isabelle_System.extract(archive, tmp_dir)
76550
a82fc7755ba5 clarified check;
wenzelm
parents: 76548
diff changeset
   401
                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
   402
              }
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   403
            if (is_standard_component) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   404
              if (ssh.is_dir(remote_contrib)) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   405
                if (force) ssh.rm_tree(remote_contrib)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   406
                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
   407
              }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   408
              progress.echo("Unpacking remote " + archive_name)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   409
              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
   410
                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
   411
            }
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   412
            else {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   413
              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
   414
            }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   415
          }
76169
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   416
        }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   417
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   418
        // remote SHA1 digests
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   419
        if (update_components_sha1) {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   420
          val lines =
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   421
            for {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   422
              entry <- ssh.read_dir(components_dir)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   423
              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
   424
                entry.endsWith(Archive.suffix)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   425
            }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   426
            yield {
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   427
              progress.echo("Digesting remote " + entry)
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   428
              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
   429
                "; sha1sum " + Bash.string(entry)).check.out
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   430
            }
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   431
          write_components_sha1(read_components_sha1(lines))
a3c694039fd6 discontinued pointless SSH.Target: OpenSSH client can handle user@host directly;
wenzelm
parents: 76122
diff changeset
   432
        }
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   433
      }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   434
    }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   435
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   436
    // local SHA1 digests
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   437
    {
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   438
      val new_entries =
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   439
        for (archive <- archives)
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   440
        yield {
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   441
          val name = archive.file_name
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   442
          progress.echo("Digesting local " + name)
77209
3070001c9d1f tuned signature;
wenzelm
parents: 77128
diff changeset
   443
          SHA1_Entry(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
   444
        }
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   445
      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
   446
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   447
      write_components_sha1(
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   448
        new_entries :::
75349
8cbb1bc07da9 tuned signature;
wenzelm
parents: 75310
diff changeset
   449
        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
   450
    }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   451
  }
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   452
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   453
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   454
  /* Isabelle tool wrapper */
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   455
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   456
  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
   457
    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
   458
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   459
  val isabelle_tool =
77565
fd87490429aa renamed "isabelle build_components" to "isabelle components_build" (unrelated to "isabelle build");
wenzelm
parents: 77509
diff changeset
   460
    Isabelle_Tool("components_build", "build and publish Isabelle components",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   461
      Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   462
      { args =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   463
        var publish = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   464
        var update_components_sha1 = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   465
        var force = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   466
        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
   467
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   468
        def show_options: String =
75844
7d27944d7141 clarified signature: avoid public representation;
wenzelm
parents: 75394
diff changeset
   469
          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
   470
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   471
        val getopts = Getopts("""
77565
fd87490429aa renamed "isabelle build_components" to "isabelle components_build" (unrelated to "isabelle build");
wenzelm
parents: 77509
diff changeset
   472
Usage: isabelle components_build [OPTIONS] ARCHIVES... DIRS...
69429
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   473
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   474
  Options are:
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   475
    -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
   476
    -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
   477
    -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
   478
    -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
   479
dc5fbcb07c7b replaced "isabelle components_checksum" shell script by "isabelle build_components" in Scala, with more functionality;
wenzelm
parents: 69426
diff changeset
   480
  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
   481
  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
   482
73736
a8ff6e4ee661 tuned signature;
wenzelm
parents: 73637
diff changeset
   483
""" + Library.indent_lines(2, show_options) + "\n",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   484
          "P" -> (_ => publish = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   485
          "f" -> (_ => force = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   486
          "o:" -> (arg => options = options + arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   487
          "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
   488
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   489
        val more_args = getopts(args)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   490
        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
   491
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   492
        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
   493
77565
fd87490429aa renamed "isabelle build_components" to "isabelle components_build" (unrelated to "isabelle build");
wenzelm
parents: 77509
diff changeset
   494
        components_build(options, more_args.map(Path.explode), progress = progress,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   495
          publish = publish, force = force, update_components_sha1 = update_components_sha1)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   496
      })
69395
d1c4a1dee9e7 more explicit support for Isabelle system components;
wenzelm
parents:
diff changeset
   497
}