diff --git a/src/Pure/Admin/build_easychair.scala b/src/Pure/Admin/build_easychair.scala --- a/src/Pure/Admin/build_easychair.scala +++ b/src/Pure/Admin/build_easychair.scala @@ -1,99 +1,97 @@ /* Title: Pure/Admin/build_easychair.scala Author: Makarius Build Isabelle component for Easychair LaTeX style. See also https://easychair.org/publications/for_authors */ package isabelle object Build_Easychair { /* build easychair component */ val default_url = "https://easychair.org/publications/easychair.zip" def build_easychair( download_url: String = default_url, target_dir: Path = Path.current, progress: Progress = new Progress ): Unit = { Isabelle_System.with_tmp_file("download", ext = "zip") { download_file => Isabelle_System.with_tmp_dir("download") { download_dir => /* download */ Isabelle_System.download_file(download_url, download_file, progress = progress) Isabelle_System.extract(download_file, download_dir) val easychair_dir = File.get_dir(download_dir, title = download_url) /* component */ val version = Library.try_unprefix("EasyChair", easychair_dir.file_name) .getOrElse("Failed to detect version from " + quote(easychair_dir.file_name)) val component = "easychair-" + version val component_dir = Components.Directory.create(target_dir + Path.basic(component), progress = progress) - Isabelle_System.rm_tree(component_dir.path) - Isabelle_System.copy_dir(easychair_dir, component_dir.path) - Isabelle_System.make_directory(component_dir.etc) + Isabelle_System.extract(download_file, component_dir.path, strip = true) /* settings */ File.write(component_dir.settings, """# -*- shell-script -*- :mode=shellscript: ISABELLE_EASYCHAIR_HOME="$COMPONENT" """) /* README */ File.write(component_dir.README, """This is the Easychair style for authors from """ + download_url + """ Makarius """ + Date.Format.date(Date.now()) + "\n") } } } /* Isabelle tool wrapper */ val isabelle_tool = Isabelle_Tool("build_easychair", "build component for Easychair LaTeX style", Scala_Project.here, { args => var target_dir = Path.current var download_url = default_url val getopts = Getopts(""" Usage: isabelle build_easychair [OPTIONS] Options are: -D DIR target directory (default ".") -U URL download URL (default: """" + default_url + """") Build component for Easychair LaTeX style. """, "D:" -> (arg => target_dir = Path.explode(arg)), "U:" -> (arg => download_url = arg)) val more_args = getopts(args) if (more_args.nonEmpty) getopts.usage() val progress = new Console_Progress() build_easychair(download_url = download_url, target_dir = target_dir, progress = progress) }) } diff --git a/src/Pure/Admin/build_foiltex.scala b/src/Pure/Admin/build_foiltex.scala --- a/src/Pure/Admin/build_foiltex.scala +++ b/src/Pure/Admin/build_foiltex.scala @@ -1,108 +1,107 @@ /* Title: Pure/Admin/build_foiltex.scala Author: Makarius Build Isabelle component for FoilTeX. See also https://ctan.org/pkg/foiltex */ package isabelle object Build_Foiltex { /* build FoilTeX component */ val default_url = "https://mirrors.ctan.org/macros/latex/contrib/foiltex.zip" def build_foiltex( download_url: String = default_url, target_dir: Path = Path.current, progress: Progress = new Progress ): Unit = { Isabelle_System.with_tmp_file("download", ext = "zip") { download_file => Isabelle_System.with_tmp_dir("download") { download_dir => /* download */ Isabelle_System.download_file(download_url, download_file, progress = progress) Isabelle_System.extract(download_file, download_dir) val foiltex_dir = File.get_dir(download_dir, title = download_url) - val README = Path.explode("README") - val README_flt = Path.explode("README.flt") - Isabelle_System.move_file(foiltex_dir + README, foiltex_dir + README_flt) - - Isabelle_System.bash("pdflatex foiltex.ins", cwd = foiltex_dir.file).check - /* component */ + val README = Path.explode("README") val version = { val Version = """^.*Instructions for FoilTeX Version\s*(.*)$""".r - split_lines(File.read(foiltex_dir + README_flt)) + split_lines(File.read(foiltex_dir + README)) .collectFirst({ case Version(v) => v }) - .getOrElse(error("Failed to detect version in " + README_flt)) + .getOrElse(error("Failed to detect version in " + README)) } val component = "foiltex-" + version val component_dir = Components.Directory.create(target_dir + Path.basic(component), progress = progress) - Isabelle_System.rm_tree(component_dir.path) - Isabelle_System.copy_dir(foiltex_dir, component_dir.path) - Isabelle_System.make_directory(component_dir.etc) + Isabelle_System.extract(download_file, component_dir.path, strip = true) + + Isabelle_System.bash("pdflatex foiltex.ins", cwd = component_dir.path.file).check + (component_dir.path + Path.basic("foiltex.log")).file.delete() /* settings */ File.write(component_dir.settings, """# -*- shell-script -*- :mode=shellscript: ISABELLE_FOILTEX_HOME="$COMPONENT" """) /* README */ + Isabelle_System.move_file(component_dir.README, + component_dir.path + Path.basic("README.flt")) + File.write(component_dir.README, """This is FoilTeX from """ + download_url + """ Makarius """ + Date.Format.date(Date.now()) + "\n") } } } /* Isabelle tool wrapper */ val isabelle_tool = Isabelle_Tool("build_foiltex", "build component for FoilTeX", Scala_Project.here, { args => var target_dir = Path.current var download_url = default_url val getopts = Getopts(""" Usage: isabelle build_foiltex [OPTIONS] Options are: -D DIR target directory (default ".") -U URL download URL (default: """" + default_url + """") Build component for FoilTeX: slides in LaTeX. """, "D:" -> (arg => target_dir = Path.explode(arg)), "U:" -> (arg => download_url = arg)) val more_args = getopts(args) if (more_args.nonEmpty) getopts.usage() val progress = new Console_Progress() build_foiltex(download_url = download_url, target_dir = target_dir, progress = progress) }) } diff --git a/src/Pure/Admin/build_llncs.scala b/src/Pure/Admin/build_llncs.scala --- a/src/Pure/Admin/build_llncs.scala +++ b/src/Pure/Admin/build_llncs.scala @@ -1,108 +1,106 @@ /* Title: Pure/Admin/build_llncs.scala Author: Makarius Build Isabelle component for Springer LaTeX LNCS style. See also: - https://ctan.org/pkg/llncs?lang=en - https://www.springer.com/gp/computer-science/lncs/conference-proceedings-guidelines */ package isabelle object Build_LLNCS { /* build llncs component */ val default_url = "https://mirrors.ctan.org/macros/latex/contrib/llncs.zip" def build_llncs( download_url: String = default_url, target_dir: Path = Path.current, progress: Progress = new Progress ): Unit = { Isabelle_System.with_tmp_file("download", ext = "zip") { download_file => Isabelle_System.with_tmp_dir("download") { download_dir => /* download */ Isabelle_System.download_file(download_url, download_file, progress = progress) Isabelle_System.extract(download_file, download_dir) val llncs_dir = File.get_dir(download_dir, title = download_url) - val readme = Path.explode("README.md") - File.change(llncs_dir + readme)(_.replace(" ", "\u00a0")) - /* component */ + val README_md = Path.explode("README.md") val version = { val Version = """^_.* v(.*)_$""".r - split_lines(File.read(llncs_dir + readme)) + split_lines(File.read(llncs_dir + README_md)) .collectFirst({ case Version(v) => v }) - .getOrElse(error("Failed to detect version in " + readme)) + .getOrElse(error("Failed to detect version in " + README_md)) } val component = "llncs-" + version val component_dir = Components.Directory.create(target_dir + Path.basic(component), progress = progress) - Isabelle_System.rm_tree(component_dir.path) - Isabelle_System.copy_dir(llncs_dir, component_dir.path) - Isabelle_System.make_directory(component_dir.etc) + Isabelle_System.extract(download_file, component_dir.path, strip = true) /* settings */ File.write(component_dir.settings, """# -*- shell-script -*- :mode=shellscript: ISABELLE_LLNCS_HOME="$COMPONENT" """) /* README */ + File.change(component_dir.path + README_md)(_.replace(" ", "\u00a0")) + File.write(component_dir.README, """This is the Springer LaTeX LNCS style for authors from """ + download_url + """ Makarius """ + Date.Format.date(Date.now()) + "\n") } } } /* Isabelle tool wrapper */ val isabelle_tool = Isabelle_Tool("build_llncs", "build component for Springer LaTeX LNCS style", Scala_Project.here, { args => var target_dir = Path.current var download_url = default_url val getopts = Getopts(""" Usage: isabelle build_llncs [OPTIONS] Options are: -D DIR target directory (default ".") -U URL download URL (default: """" + default_url + """") Build component for Springer LaTeX LNCS style. """, "D:" -> (arg => target_dir = Path.explode(arg)), "U:" -> (arg => download_url = arg)) val more_args = getopts(args) if (more_args.nonEmpty) getopts.usage() val progress = new Console_Progress() build_llncs(download_url = download_url, target_dir = target_dir, progress = progress) }) } diff --git a/src/Pure/General/file.scala b/src/Pure/General/file.scala --- a/src/Pure/General/file.scala +++ b/src/Pure/General/file.scala @@ -1,380 +1,382 @@ /* Title: Pure/General/file.scala Author: Makarius File-system operations. */ package isabelle import java.io.{BufferedWriter, OutputStreamWriter, FileOutputStream, BufferedOutputStream, OutputStream, InputStream, FileInputStream, BufferedInputStream, BufferedReader, InputStreamReader, File => JFile, IOException} import java.nio.file.{StandardOpenOption, Path => JPath, Files, SimpleFileVisitor, FileVisitOption, FileVisitResult} import java.nio.file.attribute.BasicFileAttributes import java.net.{URI, URL, MalformedURLException} import java.util.zip.{GZIPInputStream, GZIPOutputStream} import java.util.EnumSet import org.tukaani.xz import com.github.luben.zstd import scala.collection.mutable object File { /* standard path (Cygwin or Posix) */ def standard_path(path: Path): String = path.expand.implode def standard_path(platform_path: String): String = isabelle.setup.Environment.standard_path(platform_path) def standard_path(file: JFile): String = standard_path(file.getPath) def standard_url(name: String): String = try { val url = new URL(name) if (url.getProtocol == "file" && Url.is_wellformed_file(name)) standard_path(Url.parse_file(name)) else name } catch { case _: MalformedURLException => standard_path(name) } /* platform path (Windows or Posix) */ def platform_path(standard_path: String): String = isabelle.setup.Environment.platform_path(standard_path) def platform_path(path: Path): String = platform_path(standard_path(path)) def platform_file(path: Path): JFile = new JFile(platform_path(path)) /* platform files */ def absolute(file: JFile): JFile = file.toPath.toAbsolutePath.normalize.toFile def absolute_name(file: JFile): String = absolute(file).getPath def canonical(file: JFile): JFile = file.getCanonicalFile def canonical_name(file: JFile): String = canonical(file).getPath def path(file: JFile): Path = Path.explode(standard_path(file)) + def path(java_path: JPath): Path = path(java_path.toFile) + def pwd(): Path = path(Path.current.absolute_file) def uri(file: JFile): URI = file.toURI def uri(path: Path): URI = path.file.toURI def url(file: JFile): URL = uri(file).toURL def url(path: Path): URL = url(path.file) /* adhoc file types */ def is_ML(s: String): Boolean = s.endsWith(".ML") def is_bib(s: String): Boolean = s.endsWith(".bib") def is_dll(s: String): Boolean = s.endsWith(".dll") def is_exe(s: String): Boolean = s.endsWith(".exe") def is_gz(s: String): Boolean = s.endsWith(".gz") def is_html(s: String): Boolean = s.endsWith(".html") def is_jar(s: String): Boolean = s.endsWith(".jar") def is_java(s: String): Boolean = s.endsWith(".java") def is_node(s: String): Boolean = s.endsWith(".node") def is_pdf(s: String): Boolean = s.endsWith(".pdf") def is_png(s: String): Boolean = s.endsWith(".png") def is_tar_bz2(s: String): Boolean = s.endsWith(".tar.bz2") def is_tar_gz(s: String): Boolean = s.endsWith(".tar.gz") def is_tgz(s: String): Boolean = s.endsWith(".tgz") def is_thy(s: String): Boolean = s.endsWith(".thy") def is_xz(s: String): Boolean = s.endsWith(".xz") def is_zip(s: String): Boolean = s.endsWith(".zip") def is_zst(s: String): Boolean = s.endsWith(".zst") def is_backup(s: String): Boolean = s.endsWith("~") || s.endsWith(".orig") /* relative paths */ def relative_path(base: Path, other: Path): Option[Path] = { val base_path = base.java_path val other_path = other.java_path if (other_path.startsWith(base_path)) Some(path(base_path.relativize(other_path).toFile)) else None } /* bash path */ def bash_path(path: Path): String = Bash.string(standard_path(path)) def bash_path(file: JFile): String = Bash.string(standard_path(file)) def bash_platform_path(path: Path): String = Bash.string(platform_path(path)) /* directory entries */ def check_dir(path: Path): Path = if (path.is_dir) path else error("No such directory: " + path) def check_file(path: Path): Path = if (path.is_file) path else error("No such file: " + path) /* directory content */ def read_dir(dir: Path): List[String] = { if (!dir.is_dir) error("No such directory: " + dir.toString) val files = dir.file.listFiles if (files == null) Nil else files.toList.map(_.getName).sorted } def get_entry( dir: Path, pred: Path => Boolean = _ => true, title: String = "" ): Path = read_dir(dir).filter(name => pred(dir + Path.basic(name))) match { case List(entry) => dir + Path.basic(entry) case bad => error("Bad directory content in " + (if (title.nonEmpty) title else dir.toString) + "\nexpected a single entry, but found" + (if (bad.isEmpty) " nothing" else bad.sorted.map(quote).mkString(":\n ", "\n ", ""))) } def get_file(dir: Path, title: String = ""): Path = get_entry(dir, pred = _.is_file, title = title) def get_dir(dir: Path, title: String = ""): Path = get_entry(dir, pred = _.is_dir, title = title) def find_files( start: JFile, pred: JFile => Boolean = _ => true, include_dirs: Boolean = false, follow_links: Boolean = false ): List[JFile] = { val result = new mutable.ListBuffer[JFile] def check(file: JFile): Unit = if (pred(file)) result += file if (start.isFile) check(start) else if (start.isDirectory) { val options = if (follow_links) EnumSet.of(FileVisitOption.FOLLOW_LINKS) else EnumSet.noneOf(classOf[FileVisitOption]) Files.walkFileTree(start.toPath, options, Integer.MAX_VALUE, new SimpleFileVisitor[JPath] { override def preVisitDirectory( path: JPath, attrs: BasicFileAttributes ): FileVisitResult = { if (include_dirs) check(path.toFile) FileVisitResult.CONTINUE } override def visitFile( path: JPath, attrs: BasicFileAttributes ): FileVisitResult = { val file = path.toFile if (include_dirs || !file.isDirectory) check(file) FileVisitResult.CONTINUE } } ) } result.toList } /* read */ def read(file: JFile): String = Bytes.read(file).text def read(path: Path): String = read(path.file) def read_stream(reader: BufferedReader): String = { val output = new StringBuilder(100) var c = -1 while ({ c = reader.read; c != -1 }) output += c.toChar reader.close() output.toString } def read_stream(stream: InputStream): String = read_stream(new BufferedReader(new InputStreamReader(stream, UTF8.charset))) def read_gzip(file: JFile): String = read_stream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(file)))) def read_gzip(path: Path): String = read_gzip(path.file) def read_xz(file: JFile): String = read_stream(new xz.XZInputStream(new BufferedInputStream(new FileInputStream(file)))) def read_xz(path: Path): String = read_xz(path.file) def read_zstd(file: JFile): String = { Zstd.init() read_stream(new zstd.ZstdInputStream(new BufferedInputStream(new FileInputStream(file)))) } def read_zstd(path: Path): String = read_zstd(path.file) /* read lines */ def read_line(reader: BufferedReader): Option[String] = { val line = try { reader.readLine} catch { case _: IOException => null } Option(line).map(Library.trim_line) } def read_lines(reader: BufferedReader, progress: String => Unit): List[String] = { val result = new mutable.ListBuffer[String] var line: Option[String] = None while ({ line = read_line(reader); line.isDefined }) { progress(line.get) result += line.get } reader.close() result.toList } /* write */ def writer(file: JFile): BufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), UTF8.charset)) def write_file( file: JFile, text: String, make_stream: OutputStream => OutputStream ): Unit = { val stream = make_stream(new FileOutputStream(file)) using(new BufferedWriter(new OutputStreamWriter(stream, UTF8.charset)))(_.append(text)) } def write(file: JFile, text: String): Unit = write_file(file, text, s => s) def write(path: Path, text: String): Unit = write(path.file, text) def write_gzip(file: JFile, text: String): Unit = write_file(file, text, (s: OutputStream) => new GZIPOutputStream(new BufferedOutputStream(s))) def write_gzip(path: Path, text: String): Unit = write_gzip(path.file, text) def write_xz(file: JFile, text: String, options: Compress.Options_XZ): Unit = File.write_file(file, text, s => new xz.XZOutputStream(new BufferedOutputStream(s), options.make)) def write_xz(file: JFile, text: String): Unit = write_xz(file, text, Compress.Options_XZ()) def write_xz(path: Path, text: String, options: Compress.Options_XZ): Unit = write_xz(path.file, text, options) def write_xz(path: Path, text: String): Unit = write_xz(path, text, Compress.Options_XZ()) def write_zstd(file: JFile, text: String, options: Compress.Options_Zstd): Unit = { Zstd.init() File.write_file(file, text, s => new zstd.ZstdOutputStream(new BufferedOutputStream(s), options.level)) } def write_zstd(file: JFile, text: String): Unit = write_zstd(file, text, Compress.Options_Zstd()) def write_zstd(path: Path, text: String, options: Compress.Options_Zstd): Unit = write_zstd(path.file, text, options) def write_zstd(path: Path, text: String): Unit = write_zstd(path, text, Compress.Options_Zstd()) def write_backup(path: Path, text: String): Unit = { if (path.is_file) Isabelle_System.move_file(path, path.backup) write(path, text) } def write_backup2(path: Path, text: String): Unit = { if (path.is_file) Isabelle_System.move_file(path, path.backup2) write(path, text) } /* append */ def append(file: JFile, text: String): Unit = Files.write(file.toPath, UTF8.bytes(text), StandardOpenOption.APPEND, StandardOpenOption.CREATE) def append(path: Path, text: String): Unit = append(path.file, text) /* change */ def change( path: Path, init: Boolean = false, strict: Boolean = false )(f: String => String): Unit = { if (!path.is_file && init) write(path, "") val x = read(path) val y = f(x) if (x != y) write(path, y) else if (strict) error("Unchanged file: " + path) } def change_lines(path: Path, init: Boolean = false, strict: Boolean = false)( f: List[String] => List[String]): Unit = change(path, init = init, strict = strict)(text => cat_lines(f(split_lines(text)))) /* eq */ def eq(file1: JFile, file2: JFile): Boolean = try { Files.isSameFile(file1.toPath, file2.toPath) } catch { case ERROR(_) => false } def eq(path1: Path, path2: Path): Boolean = eq(path1.file, path2.file) /* eq_content */ def eq_content(file1: JFile, file2: JFile): Boolean = if (eq(file1, file2)) true else if (file1.length != file2.length) false else Bytes.read(file1) == Bytes.read(file2) def eq_content(path1: Path, path2: Path): Boolean = eq_content(path1.file, path2.file) /* permissions */ def is_executable(path: Path): Boolean = { if (Platform.is_windows) Isabelle_System.bash("test -x " + bash_path(path)).check.ok else path.file.canExecute } def set_executable(path: Path, flag: Boolean): Unit = { if (Platform.is_windows && flag) Isabelle_System.chmod("a+x", path) else if (Platform.is_windows) Isabelle_System.chmod("a-x", path) else path.file.setExecutable(flag, false) } /* content */ def content(path: Path, content: Bytes): Content = new Content(path, content) def content(path: Path, content: String): Content = new Content(path, Bytes(content)) def content(path: Path, content: XML.Body): Content_XML = new Content_XML(path, content) final class Content private[File](val path: Path, val content: Bytes) { override def toString: String = path.toString def write(dir: Path): Unit = { val full_path = dir + path Isabelle_System.make_directory(full_path.expand.dir) Bytes.write(full_path, content) } } final class Content_XML private[File](val path: Path, val content: XML.Body) { override def toString: String = path.toString def output(out: XML.Body => String): Content = new Content(path, Bytes(out(content))) } } diff --git a/src/Pure/System/isabelle_system.scala b/src/Pure/System/isabelle_system.scala --- a/src/Pure/System/isabelle_system.scala +++ b/src/Pure/System/isabelle_system.scala @@ -1,534 +1,557 @@ /* Title: Pure/System/isabelle_system.scala Author: Makarius Miscellaneous Isabelle system operations. */ package isabelle import java.util.{Map => JMap, HashMap} +import java.util.zip.ZipFile import java.io.{File => JFile, IOException} import java.net.ServerSocket import java.nio.file.{Path => JPath, Files, SimpleFileVisitor, FileVisitResult, StandardCopyOption, FileSystemException} import java.nio.file.attribute.BasicFileAttributes +import scala.jdk.CollectionConverters._ + object Isabelle_System { /* settings environment */ def settings(putenv: List[(String, String)] = Nil): JMap[String, String] = { val env0 = isabelle.setup.Environment.settings() if (putenv.isEmpty) env0 else { val env = new HashMap(env0) for ((a, b) <- putenv) env.put(a, b) env } } def getenv(name: String, env: JMap[String, String] = settings()): String = Option(env.get(name)).getOrElse("") def getenv_strict(name: String, env: JMap[String, String] = settings()): String = proper_string(getenv(name, env)) getOrElse error("Undefined Isabelle environment variable: " + quote(name)) /* services */ type Service = Classpath.Service @volatile private var _classpath: Option[Classpath] = None def classpath(): Classpath = { if (_classpath.isEmpty) init() // unsynchronized check _classpath.get } def make_services[C](c: Class[C]): List[C] = classpath().make_services(c) /* init settings + classpath */ def init(isabelle_root: String = "", cygwin_root: String = ""): Unit = { isabelle.setup.Environment.init(isabelle_root, cygwin_root) synchronized { if (_classpath.isEmpty) _classpath = Some(Classpath()) } } /* getetc -- static distribution parameters */ def getetc(name: String, root: Path = Path.ISABELLE_HOME): Option[String] = { val path = root + Path.basic("etc") + Path.basic(name) if (path.is_file) { Library.trim_split_lines(File.read(path)) match { case Nil => None case List(s) => Some(s) case _ => error("Single line expected in " + path.absolute) } } else None } /* Isabelle distribution identification */ def isabelle_id(root: Path = Path.ISABELLE_HOME): String = getetc("ISABELLE_ID", root = root) orElse Mercurial.archive_id(root) orElse Mercurial.id_repository(root, rev = "") getOrElse error("Failed to identify Isabelle distribution " + root.expand) object Isabelle_Id extends Scala.Fun_String("isabelle_id") { val here = Scala_Project.here def apply(arg: String): String = isabelle_id() } def isabelle_tags(root: Path = Path.ISABELLE_HOME): String = getetc("ISABELLE_TAGS", root = root) orElse Mercurial.archive_tags(root) getOrElse { if (Mercurial.is_repository(root)) { val hg = Mercurial.repository(root) hg.tags(rev = hg.parent()) } else "" } def export_isabelle_identifier(isabelle_identifier: String): String = "export ISABELLE_IDENTIFIER=" + Bash.string(isabelle_identifier) + "\n" def isabelle_identifier(): Option[String] = proper_string(getenv("ISABELLE_IDENTIFIER")) def isabelle_heading(): String = isabelle_identifier() match { case None => "" case Some(version) => " (" + version + ")" } def isabelle_name(): String = getenv_strict("ISABELLE_NAME") def identification(): String = "Isabelle" + (try { "/" + isabelle_id () } catch { case ERROR(_) => "" }) + isabelle_heading() /** file-system operations **/ /* scala functions */ private def apply_paths( args: List[String], fun: PartialFunction[List[Path], Unit] ): List[String] = { fun(args.map(Path.explode)) Nil } private def apply_paths1(args: List[String], fun: Path => Unit): List[String] = apply_paths(args, { case List(path) => fun(path) }) private def apply_paths2(args: List[String], fun: (Path, Path) => Unit): List[String] = apply_paths(args, { case List(path1, path2) => fun(path1, path2) }) private def apply_paths3(args: List[String], fun: (Path, Path, Path) => Unit): List[String] = apply_paths(args, { case List(path1, path2, path3) => fun(path1, path2, path3) }) /* permissions */ def chmod(arg: String, path: Path): Unit = bash("chmod " + arg + " " + File.bash_path(path)).check def chown(arg: String, path: Path): Unit = bash("chown " + arg + " " + File.bash_path(path)).check /* directories */ def make_directory(path: Path): Path = { if (!path.is_dir) { try { Files.createDirectories(path.java_path) } catch { case ERROR(_) => error("Failed to create directory: " + path.absolute) } } path } def new_directory(path: Path): Path = if (path.is_dir) error("Directory already exists: " + path.absolute) else make_directory(path) def copy_dir(dir1: Path, dir2: Path): Unit = { val res = bash("cp -a " + File.bash_path(dir1) + " " + File.bash_path(dir2)) if (!res.ok) { cat_error("Failed to copy directory " + dir1.absolute + " to " + dir2.absolute, res.err) } } def with_copy_dir[A](dir1: Path, dir2: Path)(body: => A): A = { if (dir2.is_file || dir2.is_dir) error("Directory already exists: " + dir2.absolute) else { try { copy_dir(dir1, dir2); body } finally { rm_tree(dir2 ) } } } object Make_Directory extends Scala.Fun_Strings("make_directory") { val here = Scala_Project.here def apply(args: List[String]): List[String] = apply_paths1(args, make_directory) } object Copy_Dir extends Scala.Fun_Strings("copy_dir") { val here = Scala_Project.here def apply(args: List[String]): List[String] = apply_paths2(args, copy_dir) } /* copy files */ def copy_file(src: JFile, dst: JFile): Unit = { val target = if (dst.isDirectory) new JFile(dst, src.getName) else dst if (!File.eq(src, target)) { try { Files.copy(src.toPath, target.toPath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING) } catch { case ERROR(msg) => cat_error("Failed to copy file " + File.path(src).absolute + " to " + File.path(dst).absolute, msg) } } } def copy_file(src: Path, dst: Path): Unit = copy_file(src.file, dst.file) def copy_file_base(base_dir: Path, src: Path, target_dir: Path): Unit = { val src1 = src.expand val src1_dir = src1.dir if (!src1.starts_basic) error("Illegal path specification " + src1 + " beyond base directory") copy_file(base_dir + src1, Isabelle_System.make_directory(target_dir + src1_dir)) } object Copy_File extends Scala.Fun_Strings("copy_file") { val here = Scala_Project.here def apply(args: List[String]): List[String] = apply_paths2(args, copy_file) } object Copy_File_Base extends Scala.Fun_Strings("copy_file_base") { val here = Scala_Project.here def apply(args: List[String]): List[String] = apply_paths3(args, copy_file_base) } /* move files */ def move_file(src: JFile, dst: JFile): Unit = { val target = if (dst.isDirectory) new JFile(dst, src.getName) else dst if (!File.eq(src, target)) Files.move(src.toPath, target.toPath, StandardCopyOption.REPLACE_EXISTING) } def move_file(src: Path, dst: Path): Unit = move_file(src.file, dst.file) /* symbolic link */ def symlink(src: Path, dst: Path, force: Boolean = false, native: Boolean = false): Unit = { val src_file = src.file val dst_file = dst.file val target = if (dst_file.isDirectory) new JFile(dst_file, src_file.getName) else dst_file if (force) target.delete def cygwin_link(): Unit = { if (native) { error("Failed to create native symlink on Windows: " + quote(src_file.toString) + "\n(but it could work as Administrator)") } else isabelle.setup.Environment.cygwin_link(File.standard_path(src), target) } try { Files.createSymbolicLink(target.toPath, src_file.toPath) } catch { case _: UnsupportedOperationException if Platform.is_windows => cygwin_link() case _: FileSystemException if Platform.is_windows => cygwin_link() } } /* tmp files */ def isabelle_tmp_prefix(): JFile = { val path = Path.explode("$ISABELLE_TMP_PREFIX") path.file.mkdirs // low-level mkdirs to avoid recursion via Isabelle environment File.platform_file(path) } def tmp_file( name: String, ext: String = "", base_dir: JFile = isabelle_tmp_prefix(), initialized: Boolean = true ): JFile = { val suffix = if (ext == "") "" else "." + ext val file = Files.createTempFile(base_dir.toPath, name, suffix).toFile if (initialized) file.deleteOnExit() else file.delete() file } def with_tmp_file[A]( name: String, ext: String = "", base_dir: JFile = isabelle_tmp_prefix() )(body: Path => A): A = { val file = tmp_file(name, ext, base_dir = base_dir) try { body(File.path(file)) } finally { file.delete } } /* tmp dirs */ def rm_tree(root: JFile): Unit = { root.delete if (root.isDirectory) { Files.walkFileTree(root.toPath, new SimpleFileVisitor[JPath] { override def visitFile(file: JPath, attrs: BasicFileAttributes): FileVisitResult = { try { Files.deleteIfExists(file) } catch { case _: IOException => } FileVisitResult.CONTINUE } override def postVisitDirectory(dir: JPath, e: IOException): FileVisitResult = { if (e == null) { try { Files.deleteIfExists(dir) } catch { case _: IOException => } FileVisitResult.CONTINUE } else throw e } } ) } } def rm_tree(root: Path): Unit = rm_tree(root.file) object Rm_Tree extends Scala.Fun_Strings("rm_tree") { val here = Scala_Project.here def apply(args: List[String]): List[String] = apply_paths1(args, rm_tree) } def tmp_dir(name: String, base_dir: JFile = isabelle_tmp_prefix()): JFile = { val dir = Files.createTempDirectory(base_dir.toPath, name).toFile dir.deleteOnExit() dir } def with_tmp_dir[A]( name: String, base_dir: JFile = isabelle_tmp_prefix() )(body: Path => A): A = { val dir = tmp_dir(name, base_dir = base_dir) try { body(File.path(dir)) } finally { rm_tree(dir) } } /* quasi-atomic update of directory */ def update_directory(dir: Path, f: Path => Unit): Unit = { val new_dir = dir.ext("new") val old_dir = dir.ext("old") rm_tree(new_dir) rm_tree(old_dir) f(new_dir) if (dir.is_dir) move_file(dir, old_dir) move_file(new_dir, dir) rm_tree(old_dir) } /* TCP/IP ports */ def local_port(): Int = { val socket = new ServerSocket(0) val port = socket.getLocalPort socket.close() port } /* JVM shutdown hook */ def create_shutdown_hook(body: => Unit): Thread = { val shutdown_hook = Isabelle_Thread.create(new Runnable { def run: Unit = body }) try { Runtime.getRuntime.addShutdownHook(shutdown_hook) } catch { case _: IllegalStateException => } shutdown_hook } def remove_shutdown_hook(shutdown_hook: Thread): Unit = try { Runtime.getRuntime.removeShutdownHook(shutdown_hook) } catch { case _: IllegalStateException => } /** external processes **/ /* GNU bash */ def bash(script: String, description: String = "", cwd: JFile = null, env: JMap[String, String] = settings(), redirect: Boolean = false, input: String = "", progress_stdout: String => Unit = (_: String) => (), progress_stderr: String => Unit = (_: String) => (), watchdog: Option[Bash.Watchdog] = None, strict: Boolean = true, cleanup: () => Unit = () => () ): Process_Result = { Bash.process(script, description = description, cwd = cwd, env = env, redirect = redirect, cleanup = cleanup). result(input = input, progress_stdout = progress_stdout, progress_stderr = progress_stderr, watchdog = watchdog, strict = strict) } /* command-line tools */ def require_command(cmd: String, test: String = "--version"): Unit = { if (!bash(Bash.string(cmd) + " " + test).ok) error("Missing system command: " + quote(cmd)) } private lazy val gnutar_check: Boolean = try { bash("tar --version").check.out.containsSlice("GNU tar") || error("") } catch { case ERROR(_) => false } def gnutar( args: String, dir: Path = Path.current, original_owner: Boolean = false, strip: Boolean = false, redirect: Boolean = false ): Process_Result = { val options = (if (dir.is_current) "" else "-C " + File.bash_path(dir) + " ") + (if (original_owner) "" else "--owner=root --group=staff ") + (if (!strip) "" else "--strip-components=1 ") if (gnutar_check) bash("tar " + options + args, redirect = redirect) else error("Expected to find GNU tar executable") } def extract(archive: Path, dir: Path, strip: Boolean = false): Unit = { val name = archive.file_name make_directory(dir) - if (File.is_zip(name)) { - require(!strip, "Cannot extract/strip zip archive") - Isabelle_System.bash("unzip -x " + File.bash_path(archive.absolute), cwd = dir.file).check - } - else if (File.is_jar(name)) { - require(!strip, "Cannot extract/strip jar archive") - Isabelle_System.bash("isabelle_jdk jar xf " + File.bash_platform_path(archive.absolute), - cwd = dir.file).check + if (File.is_zip(name) || File.is_jar(name)) { + using(new ZipFile(archive.file)) { zip_file => + val items = + for (entry <- zip_file.entries().asScala.toList) + yield { + val input = JPath.of(entry.getName) + val count = input.getNameCount + val output = + if (strip && count <= 1) None + else if (strip) Some(input.subpath(1, count)) + else Some(input) + val result = output.map(dir.java_path.resolve(_)) + for (res <- result) { + if (entry.isDirectory) Files.createDirectories(res) + else { + val bytes = using(zip_file.getInputStream(entry))(Bytes.read_stream(_)) + Files.createDirectories(res.getParent) + Files.write(res, bytes.array) + } + } + (entry, result) + } + for { + (entry, Some(res)) <- items + if !entry.isDirectory + t <- Option(entry.getLastModifiedTime) + } Files.setLastModifiedTime(res, t) + } } else if (File.is_tar_bz2(name) || File.is_tgz(name) || File.is_tar_gz(name)) { val flags = if (File.is_tar_bz2(name)) "-xjf " else "-xzf " Isabelle_System.gnutar(flags + File.bash_path(archive), dir = dir, strip = strip).check } else error("Cannot extract " + archive) } def make_patch(base_dir: Path, src: Path, dst: Path, diff_options: String = ""): String = { with_tmp_file("patch") { patch => Isabelle_System.bash( "diff -ru " + diff_options + " -- " + File.bash_path(src) + " " + File.bash_path(dst) + " > " + File.bash_path(patch), cwd = base_dir.file).check_rc(_ <= 1) File.read(patch) } } def hostname(): String = bash("hostname -s").check.out def open(arg: String): Unit = bash("exec \"$ISABELLE_OPEN\" " + Bash.string(arg) + " >/dev/null 2>/dev/null &") def pdf_viewer(arg: Path): Unit = bash("exec \"$PDF_VIEWER\" " + File.bash_path(arg) + " >/dev/null 2>/dev/null &") def open_external_file(name: String): Boolean = { val ext = Library.take_suffix((c: Char) => c != '.', name.toList)._2.mkString val external = ext.nonEmpty && Library.space_explode(':', getenv("ISABELLE_EXTERNAL_FILES")).contains(ext) if (external) { if (ext == "pdf" && Path.is_wellformed(name)) pdf_viewer(Path.explode(name)) else open(name) } external } /** Isabelle resources **/ /* repository clone with Admin */ def admin(): Boolean = Path.explode("~~/Admin").is_dir /* default logic */ def default_logic(args: String*): String = { args.find(_ != "") match { case Some(logic) => logic case None => getenv_strict("ISABELLE_LOGIC") } } /* download file */ def download(url_name: String, progress: Progress = new Progress): HTTP.Content = { val url = Url(url_name) progress.echo("Getting " + quote(url_name)) try { HTTP.Client.get(url) } catch { case ERROR(msg) => cat_error("Failed to download " + quote(url_name), msg) } } def download_file(url_name: String, file: Path, progress: Progress = new Progress): Unit = Bytes.write(file, download(url_name, progress = progress).bytes) object Download extends Scala.Fun("download", thread = true) { val here = Scala_Project.here override def invoke(args: List[Bytes]): List[Bytes] = args.map(url => download(url.text).bytes) } /* repositories */ val isabelle_repository: Mercurial.Server = Mercurial.Server("https://isabelle.sketis.net/repos/isabelle") val afp_repository: Mercurial.Server = Mercurial.Server("https://isabelle.sketis.net/repos/afp-devel") def official_releases(): List[String] = Library.trim_split_lines( isabelle_repository.read_file(Path.explode("Admin/Release/official"))) } diff --git a/src/Tools/VSCode/src/build_vscodium.scala b/src/Tools/VSCode/src/build_vscodium.scala --- a/src/Tools/VSCode/src/build_vscodium.scala +++ b/src/Tools/VSCode/src/build_vscodium.scala @@ -1,469 +1,464 @@ /* Title: Tools/VSCode/src/build_vscodium.scala Author: Makarius Build the Isabelle system component for VSCodium: cross-compilation for all platforms. */ package isabelle.vscode import isabelle._ import java.security.MessageDigest import java.util.Base64 object Build_VSCodium { /* global parameters */ lazy val version: String = Isabelle_System.getenv_strict("ISABELLE_VSCODE_VERSION") val vscodium_repository = "https://github.com/VSCodium/vscodium.git" val vscodium_download = "https://github.com/VSCodium/vscodium/releases/download" private val resources = Path.explode("resources") /* Isabelle symbols (static subset only) */ def make_symbols(): File.Content = { val symbols = Symbol.Symbols.load(static = true) val symbols_js = JSON.Format.pretty_print( for (entry <- symbols.entries) yield JSON.Object( "symbol" -> entry.symbol, "name" -> entry.name, "abbrevs" -> entry.abbrevs) ++ JSON.optional("code", entry.code)) File.content(Path.explode("symbols.json"), symbols_js) } def make_isabelle_encoding(header: String): File.Content = { val symbols = Symbol.Symbols.load(static = true) val symbols_js = JSON.Format.pretty_print( for (entry <- symbols.entries; code <- entry.code) yield JSON.Object("symbol" -> entry.symbol, "code" -> code)) val path = Path.explode("isabelle_encoding.ts") val body = File.read(Path.explode("$ISABELLE_VSCODE_HOME/patches") + path) .replace("[/*symbols*/]", symbols_js) File.content(path, header + "\n" + body) } /* platform info */ sealed case class Platform_Info( platform: Platform.Family.Value, download_template: String, build_name: String, env: List[String] ) { def is_linux: Boolean = platform == Platform.Family.linux def download_name: String = "VSCodium-" + download_template.replace("{VERSION}", version) - def download_zip: Boolean = File.is_zip(download_name) def download(dir: Path, progress: Progress = new Progress): Unit = { Isabelle_System.with_tmp_file("download") { download_file => Isabelle_System.download_file(vscodium_download + "/" + version + "/" + download_name, download_file, progress = progress) progress.echo("Extract ...") Isabelle_System.extract(download_file, dir) } } def get_vscodium_repository(build_dir: Path, progress: Progress = new Progress): Unit = { progress.echo("Getting VSCodium repository ...") Isabelle_System.bash( List( "set -e", "git clone -n " + Bash.string(vscodium_repository) + " .", "git checkout -q " + Bash.string(version) ).mkString("\n"), cwd = build_dir.file).check progress.echo("Getting VSCode repository ...") Isabelle_System.bash(environment + "\n" + "./get_repo.sh", cwd = build_dir.file).check } def platform_dir(dir: Path): Path = { val platform_name = if (platform == Platform.Family.windows) Platform.Family.native(platform) else Platform.Family.standard(platform) dir + Path.explode(platform_name) } def build_dir(dir: Path): Path = dir + Path.explode(build_name) def environment: String = (("MS_TAG=" + Bash.string(version)) :: "SHOULD_BUILD=yes" :: "VSCODE_ARCH=x64" :: env) .map(s => "export " + s + "\n").mkString def patch_sources(base_dir: Path): String = { val dir = base_dir + Path.explode("vscode") Isabelle_System.with_copy_dir(dir, dir.orig) { // macos icns for (name <- Seq("build/lib/electron.js", "build/lib/electron.ts")) { File.change(dir + Path.explode(name), strict = true) { _.replace("""'resources/darwin/' + icon + '.icns'""", """'resources/darwin/' + icon.toLowerCase() + '.icns'""") } } // isabelle_encoding.ts { val common_dir = dir + Path.explode("src/vs/workbench/services/textfile/common") val header = split_lines(File.read(common_dir + Path.explode("encoding.ts"))) .takeWhile(_.trim.nonEmpty) make_isabelle_encoding(cat_lines(header)).write(common_dir) } // explicit patches { val patches_dir = Path.explode("$ISABELLE_VSCODE_HOME/patches") for (name <- Seq("cli", "isabelle_encoding", "no_ocaml_icons")) { val path = patches_dir + Path.explode(name).patch Isabelle_System.bash("patch -p1 < " + File.bash_path(path), cwd = dir.file).check } } Isabelle_System.make_patch(base_dir, dir.base.orig, dir.base) } } def patch_resources(base_dir: Path): String = { val dir = base_dir + resources val patch = Isabelle_System.with_copy_dir(dir, dir.orig) { val fonts_dir = dir + Path.explode("app/out/vs/base/browser/ui/fonts") HTML.init_fonts(fonts_dir.dir) make_symbols().write(fonts_dir) val workbench_css = dir + Path.explode("app/out/vs/workbench/workbench.desktop.main.css") val checksum1 = file_checksum(workbench_css) File.append(workbench_css, "\n\n" + HTML.fonts_css_dir(prefix = "../base/browser/ui")) val checksum2 = file_checksum(workbench_css) val file_name = workbench_css.file_name File.change_lines(dir + Path.explode("app/product.json")) { _.map(line => if (line.containsSlice(file_name) && line.contains(checksum1)) { line.replace(checksum1, checksum2) } else line) } Isabelle_System.make_patch(dir.dir, dir.orig.base, dir.base) } val app_dir = dir + Path.explode("app") val vscodium_app_dir = dir + Path.explode("vscodium") Isabelle_System.move_file(app_dir, vscodium_app_dir) Isabelle_System.make_directory(app_dir) if ((vscodium_app_dir + resources).is_dir) { Isabelle_System.copy_dir(vscodium_app_dir + resources, app_dir) } patch } def init_resources(base_dir: Path): Path = { val dir = base_dir + resources if (platform == Platform.Family.macos) { Isabelle_System.symlink(Path.explode("VSCodium.app/Contents/Resources"), dir) } dir } def setup_node(target_dir: Path, progress: Progress): Unit = { Isabelle_System.with_tmp_dir("download") { download_dir => download(download_dir, progress = progress) val dir1 = init_resources(download_dir) val dir2 = init_resources(target_dir) for (name <- Seq("app/node_modules.asar", "app/node_modules.asar.unpacked")) { val path = Path.explode(name) Isabelle_System.rm_tree(dir2 + path) Isabelle_System.copy_dir(dir1 + path, dir2 + path) } } } def setup_electron(dir: Path): Unit = { val electron = Path.explode("electron") platform match { case Platform.Family.linux | Platform.Family.linux_arm => Isabelle_System.move_file(dir + Path.explode("codium"), dir + electron) case Platform.Family.windows => Isabelle_System.move_file(dir + Path.explode("VSCodium.exe"), dir + electron.exe) Isabelle_System.move_file( dir + Path.explode("VSCodium.VisualElementsManifest.xml"), dir + Path.explode("electron.VisualElementsManifest.xml")) case Platform.Family.macos => } } def setup_executables(dir: Path): Unit = { Isabelle_System.rm_tree(dir + Path.explode("bin")) if (platform == Platform.Family.windows) { val files = File.find_files(dir.file, pred = { file => val name = file.getName File.is_dll(name) || File.is_exe(name) || File.is_node(name) }) files.foreach(file => File.set_executable(File.path(file), true)) Isabelle_System.bash("chmod -R o-w " + File.bash_path(dir)).check } } } // see https://github.com/microsoft/vscode/blob/main/build/gulpfile.vscode.js // function computeChecksum(filename) private def file_checksum(path: Path): String = { val digest = MessageDigest.getInstance("MD5") digest.update(Bytes.read(path).array) Bytes(Base64.getEncoder.encode(digest.digest())) .text.replaceAll("=", "") } private val platform_infos: Map[Platform.Family.Value, Platform_Info] = Iterator( Platform_Info(Platform.Family.linux, "linux-x64-{VERSION}.tar.gz", "VSCode-linux-x64", List("OS_NAME=linux", "SKIP_LINUX_PACKAGES=True")), Platform_Info(Platform.Family.linux_arm, "linux-arm64-{VERSION}.tar.gz", "VSCode-linux-arm64", List("OS_NAME=linux", "SKIP_LINUX_PACKAGES=True", "VSCODE_ARCH=arm64")), Platform_Info(Platform.Family.macos, "darwin-x64-{VERSION}.zip", "VSCode-darwin-x64", List("OS_NAME=osx")), Platform_Info(Platform.Family.windows, "win32-x64-{VERSION}.zip", "VSCode-win32-x64", List("OS_NAME=windows", "SHOULD_BUILD_ZIP=no", "SHOULD_BUILD_EXE_SYS=no", "SHOULD_BUILD_EXE_USR=no", "SHOULD_BUILD_MSI=no", "SHOULD_BUILD_MSI_NOUP=no"))) .map(info => info.platform -> info).toMap def the_platform_info(platform: Platform.Family.Value): Platform_Info = platform_infos.getOrElse(platform, error("No platform info for " + quote(platform.toString))) def linux_platform_info: Platform_Info = the_platform_info(Platform.Family.linux) /* check system */ def check_system(platforms: List[Platform.Family.Value]): Unit = { if (Platform.family != Platform.Family.linux) error("Not a Linux/x86_64 system") Isabelle_System.require_command("git") Isabelle_System.require_command("node") Isabelle_System.require_command("yarn") Isabelle_System.require_command("jq") if (platforms.contains(Platform.Family.windows)) { Isabelle_System.require_command("wine") } - - if (platforms.exists(platform => the_platform_info(platform).download_zip)) { - Isabelle_System.require_command("unzip", test = "-h") - } } /* original repository clones and patches */ def vscodium_patch(verbose: Boolean = false, progress: Progress = new Progress): String = { val platform_info = linux_platform_info check_system(List(platform_info.platform)) Isabelle_System.with_tmp_dir("build") { build_dir => platform_info.get_vscodium_repository(build_dir, progress = progress) val vscode_dir = build_dir + Path.explode("vscode") progress.echo("Prepare ...") Isabelle_System.with_copy_dir(vscode_dir, vscode_dir.orig) { progress.bash( List( "set -e", platform_info.environment, "./prepare_vscode.sh", // enforce binary diff of code.xpm "cp vscode/resources/linux/code.png vscode/resources/linux/rpm/code.xpm" ).mkString("\n"), cwd = build_dir.file, echo = verbose).check Isabelle_System.make_patch(build_dir, vscode_dir.orig.base, vscode_dir.base, diff_options = "--exclude=.git --exclude=node_modules") } } } /* build vscodium */ def default_platforms: List[Platform.Family.Value] = Platform.Family.list def build_vscodium( target_dir: Path = Path.current, platforms: List[Platform.Family.Value] = default_platforms, verbose: Boolean = false, progress: Progress = new Progress ): Unit = { check_system(platforms) /* component */ val component_name = "vscodium-" + version val component_dir = Components.Directory.create(target_dir + Path.explode(component_name), progress = progress) /* patches */ progress.echo("\n* Building patches:") val patches_dir = Isabelle_System.new_directory(component_dir.path + Path.explode("patches")) def write_patch(name: String, patch: String): Unit = File.write(patches_dir + Path.explode(name).patch, patch) write_patch("01-vscodium", vscodium_patch(verbose = verbose, progress = progress)) /* build */ for (platform <- platforms) yield { val platform_info = the_platform_info(platform) Isabelle_System.with_tmp_dir("build") { build_dir => progress.echo("\n* Building " + platform + ":") platform_info.get_vscodium_repository(build_dir, progress = progress) val sources_patch = platform_info.patch_sources(build_dir) if (platform_info.is_linux) write_patch("02-isabelle_sources", sources_patch) progress.echo("Build ...") progress.bash(platform_info.environment + "\n" + "./build.sh", cwd = build_dir.file, echo = verbose).check if (platform_info.is_linux) { Isabelle_System.copy_file(build_dir + Path.explode("LICENSE"), component_dir.path) } val platform_dir = platform_info.platform_dir(component_dir.path) Isabelle_System.copy_dir(platform_info.build_dir(build_dir), platform_dir) platform_info.setup_node(platform_dir, progress) platform_info.setup_electron(platform_dir) val resources_patch = platform_info.patch_resources(platform_dir) if (platform_info.is_linux) write_patch("03-isabelle_resources", resources_patch) Isabelle_System.copy_file( build_dir + Path.explode("vscode/node_modules/electron/dist/resources/default_app.asar"), platform_dir + resources) platform_info.setup_executables(platform_dir) } } Isabelle_System.bash("gzip *.patch", cwd = patches_dir.file).check /* settings */ File.write(component_dir.settings, """# -*- shell-script -*- :mode=shellscript: ISABELLE_VSCODIUM_HOME="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}" if [ "$ISABELLE_PLATFORM_FAMILY" = "macos" ]; then ISABELLE_VSCODIUM_ELECTRON="$ISABELLE_VSCODIUM_HOME/VSCodium.app/Contents/MacOS/Electron" ISABELLE_VSCODIUM_RESOURCES="$ISABELLE_VSCODIUM_HOME/VSCodium.app/Contents/Resources" else ISABELLE_VSCODIUM_ELECTRON="$ISABELLE_VSCODIUM_HOME/electron" ISABELLE_VSCODIUM_RESOURCES="$ISABELLE_VSCODIUM_HOME/resources" fi """) /* README */ File.write(component_dir.README, "This is VSCodium " + version + " from " + vscodium_repository + """ It has been built from sources using "isabelle build_vscodium". This applies a few changes required for Isabelle/VSCode, see "patches" directory for a formal record. Makarius """ + Date.Format.date(Date.now()) + "\n") } /* Isabelle tool wrappers */ val isabelle_tool1 = Isabelle_Tool("build_vscodium", "build component for VSCodium", Scala_Project.here, { args => var target_dir = Path.current var platforms = default_platforms var verbose = false val getopts = Getopts(""" Usage: build_vscodium [OPTIONS] Options are: -D DIR target directory (default ".") -p NAMES platform families (default: """ + quote(platforms.mkString(",")) + """) -v verbose Build VSCodium from sources and turn it into an Isabelle component. The build platform needs to be Linux with nodejs/yarn, jq, and wine for targeting Windows. """, "D:" -> (arg => target_dir = Path.explode(arg)), "p:" -> (arg => platforms = Library.space_explode(',', arg).map(Platform.Family.parse)), "v" -> (_ => verbose = true)) val more_args = getopts(args) if (more_args.nonEmpty) getopts.usage() val progress = new Console_Progress() build_vscodium(target_dir = target_dir, platforms = platforms, verbose = verbose, progress = progress) }) val isabelle_tool2 = Isabelle_Tool("vscode_patch", "patch VSCode source tree", Scala_Project.here, { args => var base_dir = Path.current val getopts = Getopts(""" Usage: vscode_patch [OPTIONS] Options are: -D DIR base directory (default ".") Patch original VSCode source tree for use with Isabelle/VSCode. """, "D:" -> (arg => base_dir = Path.explode(arg))) val more_args = getopts(args) if (more_args.nonEmpty) getopts.usage() val platform_info = the_platform_info(Platform.family) platform_info.patch_sources(base_dir) }) }