diff -r 7d15ebca4bb3 -r 17c09d1b3588 src/Tools/Setup/isabelle/setup/Build_Scala.java --- a/src/Tools/Setup/isabelle/setup/Build_Scala.java Tue Jul 06 12:36:47 2021 +0200 +++ b/src/Tools/Setup/isabelle/setup/Build_Scala.java Wed Jul 07 14:32:43 2021 +0200 @@ -10,19 +10,17 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Properties; import java.util.jar.Attributes; import java.util.jar.JarEntry; @@ -30,6 +28,8 @@ import java.util.jar.Manifest; import java.util.stream.Stream; +import scala.tools.nsc.MainClass; + public class Build_Scala { @@ -93,6 +93,25 @@ } + /** compile sources **/ + + public static void compile_sources( + Path target_dir, List deps, String options, List sources) + { + ArrayList args = new ArrayList(); + args.add("-d"); + args.add(target_dir.toString()); + args.add("-bootclasspath"); + args.add(Environment.join_paths(deps)); + for (String s : options.split("\\s+")) { args.add(s); } + args.add("--"); + for (Path p : sources) { args.add(p.toString()); } + + MainClass main = new MainClass(); + boolean ok = main.process(args.toArray(String[]::new)); + if (!ok) throw new RuntimeException("Failed to compile sources"); + } + /** create jar **/ @@ -134,13 +153,14 @@ throws IOException, InterruptedException, NoSuchAlgorithmException { String jar_name = context.jar_name(); + Path jar_path = context.path(jar_name); String shasum_name = context.shasum_name(); String[] sources = context.sources(); String[] resources = context.resources(); if (sources.length == 0) { - Files.deleteIfExists(context.path(jar_name)); + Files.deleteIfExists(jar_path); Files.deleteIfExists(context.path(shasum_name)); } else { @@ -156,46 +176,25 @@ shasum_sources = _shasum.toString(); } if (fresh || !shasum_old.equals(context.shasum(jar_name) + shasum_sources)) { - System.out.println("### Building " + context.description() + " ..."); + System.out.println( + "### Building " + context.description() + " (" + jar_path + ") ..."); - String java_home = Environment.getenv("JAVA_HOME"); - String scala_home = Environment.getenv("SCALA_HOME"); String scalac_options = Environment.getenv("ISABELLE_SCALAC_OPTIONS"); String isabelle_class_path = Environment.getenv("ISABELLE_CLASSPATH"); - if (java_home.isEmpty()) { - throw new RuntimeException("Unknown JAVA_HOME -- Java unavailable"); - } - if (scala_home.isEmpty()) { - throw new RuntimeException("Unknown SCALA_HOME -- Scala unavailable"); - } - Path build_dir = Files.createTempDirectory("isabelle"); try { - /* classpath */ + /* compile sources */ - List classpath = new LinkedList(); + List compiler_deps = new LinkedList(); for (String s : isabelle_class_path.split(":", -1)) { - classpath.add(Environment.platform_path(s)); + compiler_deps.add(Path.of(Environment.platform_path(s))); } - Map env = new HashMap(Environment.settings()); - env.put("CLASSPATH", String.join(File.pathSeparator, classpath)); - - - /* compile sources */ - - List cmd = new LinkedList(); - Environment.Exec_Result res; + List compiler_sources = new LinkedList(); + for (String s : sources) { compiler_sources.add(context.path(s)); } - cmd.add(Environment.platform_path(scala_home + "/bin/scalac")); - for (String s : scalac_options.split("\\s+")) { cmd.add(s); } - cmd.add("-d"); - cmd.add(build_dir.toString()); - for (String s : sources) { cmd.add(context.path(s).toString()); } - - res = Environment.exec_process(cmd, build_dir.toFile(), env, false); - if (!res.ok()) throw new RuntimeException(res.err()); + compile_sources(build_dir, compiler_deps, scalac_options, compiler_sources); /* copy resources */ @@ -226,7 +225,7 @@ /* packaging */ - create_jar(build_dir, context.main(), context.path(jar_name)); + create_jar(build_dir, context.main(), jar_path); String shasum = context.shasum(jar_name) + shasum_sources; Files.writeString(context.path(shasum_name), shasum);