mirror of
https://github.com/enso-org/enso.git
synced 2024-11-29 05:52:59 +03:00
9182f91e35
* Use moduleDependencies instead of modulePath * Fix compilation of editions * Fix compilation of distribution-manager * polyglot-api needs to explicitly compile module-info * Fix compilationOrder in library-manager and edition-updater * engine-runner-common is module * JPMSPlugin provides default implementation of compileModuleInfo * Remove unused setting key from JPMSUtils.compileModuleInfo * JPMSPlugin has internalModuleDependencies and exportedModule tasks. * Use BuildVersion instead of buildInfo * Manual compilation of module-info.java is reported as warning * Define org.enso.scalalibs.wrapper meta project. * Fix module check in JPMSPlugin. This is a fix for projects that declare `Compile /exportJars := true` * version-output is a module * ydoc-server uses internalModuleDependencies * persistance is module * engine-common uses internalModuleDependencies * polyglot-api does not override compileModuleInfo task * runtime-parser uses internalModuleDependencies * edition-updater is module * Update moduleDependencies for distribution-manager * editions is module * Fix some dependencies of modules * scala-yaml is a module * Add scala-compiler to scala-libs-wrapper * cli depends on scala-library module * Add dependencies for distribution-manager module * Add some scala-library dependencies in some modules * engine-runner uses internalModuleDependencies * Fix module dependencies of library-manager * Rename org.enso.scalalibs.wrapper to org.enso.scala.wrapper * Add jsoniter-scala-macros to org.enso.scala.wrapper fat module * Fix dependencies of some projects * polyglot-api does not depend on truffle-api * Fix dependencies of some projects * runtime does not use com.google.common * runtime is a module * text-buffer is a module * refactoring-utils is a module * runtime-compiler is a module * runtime-instrument-common is a module * connected-lock-manager is a module * JPMSUtils reports project name in some error messages * Modularize some instruments * module-info compilation is cached * runtime-instrument-runtime-server is module * runtime-language-epb is module * Remove runtime-fat-jar * engine-runner is not a fat jar * JPMSPlugin defines exportedModuleBin task * Redefine componentModulesPaths task * interpreter-dsl is module * Redefine componentModulesPaths task * fmt sbt * scala-libs-wrapper is a modular fat jar * Add some module deps to org.enso.runtime * engine-runner is not a fat jar * Rename package in logging-config * Rename package in logging-service * Rename package in logging-service-logback * Fix dependencies of exportedModuleBin task * Mixed projects have own compileJava task this task does not compile only module-info.java but all the java sources. So that we can see errors more easily. When only module-info.java is compiled, the only errors that we can see are that we did not include some modules on module-path. * Fix definition of exportedModule task. * Remove usages of non-existing buildInfo and replace it with BuildVersion * Fix some dependencies of org.enso.runtime module * module-info compilation is handled directly by FrgaalCompiler * module-info compilation is forced for projects that has only Scala sources with single module-info.java * Fix compilation of org.enso.runtime * manual module-info compilation is not a warning * Rename packages in logging-utils-akka * Create org.enso.language.server.deps.wrapper module * language-server is module * Creat akka-wrapper modular fat jar * fmt * Define common settings for modularFatJarWrapper * Fix compilation of json-rpc-server * Use akka and zio wrappers * language-server depends on org.eclipse.jgit * Fix some dependencies - update library manifests works now! * update library manifests invokes runner directly * buildEngineDistribution does not copy runner.jar * Remove EngineRunnerBootLoader * Fix compilation of std libs * --patch-module and --add-exports are also passed to javac * Rename package in runtime-integration-tests. The package name org.enso.compiler clashes with the package from the module * Remove usage of buildInfo * FrgaalJavaCompiler can deal with non-existing module-info.java when shouldCompileModuleInfo is true. It just generates a warning in such case as it suggests that there is something wrong with the project configuration. * Revert AliasAnalysisTest.scala * Fix dependencies and java cmdline options for runtime-integration-tests * Rename test package * runtime-integration-test depends on logging-service-logback/Test/compile * Rename package in logging-service-logback/Test * Fix FrgaalJavaCompiler creation for projects * Sanitize Test/javaOptions arguments * Sanitize Test/javaOptions arguments * All the JPMSPlugin settings are scoped * Remove unused sbt tasks * modularFatJarWrapperSettings do not override javacOptions * Resolve issue "Cannot find TestLoggerProvider" in runtime-integration-tests * org.enso.runtime module is open * Test that test classes are unconditionally opened and exported * polyglot-api-macros is a module * JPMSPlugin handles --add-opens cmdline option * RuntimeServerTest ensures instruments are initialized * Add some exports to org.enso.runtime.compiler * Add instruments on module-path to runtime-integration-tests * Replace TestLogProviderOnClassPath with TestLogProviderOnModulePath * Replace buildInfo with BuildVersion * Add jpms-wrapper-scalatest * ReportLogsOnFailure is in non-modular testkit project * Add necessary dependencies to testkit project * Revert "Add jpms-wrapper-scalatest" This reverts commit732b3427a2
. * modularize filewatcher and wrap its dependencies * Initial fix for language-server/test * frgaal compiler setting are scoped for Compile and Test * Rename package in language-server/test * Exclude com.sun.jna from wrapper jars * Rename package in library-manager-test * testkit is an automatic module * process-utils is module * akka-wrapper contains akka-http * Some fixes for library-manager-test * Fix dependencies for akka-wrapper * scala-libs-wrapper exports shapeless * lang server deps wrapper exports pureconfig * json-rpc-server requires org.slf4j * Add some dependencies * lang server deps wrapper exports pureconfig.generic * language server test requires bouncycastle provider * language server depends on cli * directory-watcher wrapper requires org.slf4j * WatcherAdapter logs unsuccessful initialization errors * Fix error reporting in WatcherAdapter * Fix rest of the language-server tests * language-server-deps-wrapper depends on scala-libs-wrapper * Fix rest of the language-server tests * Missing module-info.class in an internal project is a warning, not an error * Rename jpms-methvin-directory-watcher-wrapper to a simpler name * compileOrder has to be specified before libraryDependencies * exclude module-info.java from polyglot-api-macros * Remove temporary logging in customFrgaalCompilerSettings * Fix compilation of logging-service-logback * Fix compilation of runtime-benchmarks * Fix runtime-benchmarks/run * HostClassLoader delegates to org.graalvm.polyglot class loader if org.enso.runtime is not on boot layer * org.enso.runtime.lnaguage.epb module must be opened to allow it to be used by annnotation processor * fmt * Fix afetr merge * Add module deps after merge * Print stack trace of the uncaught exception from the annotation processor * Remove akka-actor-typed from akka-wrapper * runtime-instrument-common depends on slf4j * Fix module-path for runtime-instrument-repl-debugger * runtime-benchmarks depends on runtime-language-arrow * --module-path is passed directly to frgaal * Fix some module-related cmd line options for std-benchmarks * Revert "--module-path is passed directly to frgaal" This reverts commitda63f66a0e
. * Avoid closing of System.err when closing Context * Avoid processing altogether when requested annotations are empty * Pass shouldNotLimitModules opt to frgaal * Pass module-path and add-modules options with -J prefix to frgaal * BenchProcessor annotation processor creates its own truffle module layer * bench-processor and benchmarks-common are modules * fmt * Fix after mege * Enable JMH annotation processor * Fix compileOrder in some projects * Insert TruffleBoundary to QualifiedName. This is a revert * Fix building of engine-runner native image * Add more deps to the native image * Force module-info compilation in instruments. This fixes some weird sbt bug * Don't run engine-runner/assembly from Rust build script * Update docs of JPMSPlugin * fmt * runtime-benchmarks depends on benchmarks-common module * Fix benchmark report writing * std-benchmarks annot processing does not take settings from runtime-benchmarks * Suppress interpreter only warning in annotation processor * Runtime version manager does not expect runtime.jar fat jar * fmt * Fix module entry point * Move some polyglot tests to runtime-integration-tests. Also make their output silent * pkg has no dependency on org.graalvm.truffle * Fix compiler dependencies test * Rename all runtime.jar in fake releases * Add language-server with dependencies to component dir * No module-info.class in target dir is warning not error * language-server does not depend on netbeans lookup uitl * Declare LanguageServerApi service provider in module-info * connected-lock-manager-server is JPMS module * task-progress-notifications is module * Add fansi-wrapper module * Fix compilation of connected-lock-manager-server * Define correct Test/internalModuleDependencies for project-manager * fmt * Fix LauncherRunnerSpec - no runtime.jar * Add fansi-wrapper to runtime-integration-tests and runtime-benchmarks * Fix engine-runner native image build * Use newer JNA version - fixes running of hyperd * DRY * scala-compiler DRY * fmt * More build.sbt refactoring * Include runtime-instrument-id-execution in engine-runner native image * TruffleBoundary for QualifiedName.toString * Finding a needle in a haystack 🤦 * More scala-library DRY * more mixed-java/scala goodies * Fix compilation of syntax-rust-definition * Test that engine-runner does not depend on language-server * Append rather than assign `moduleDependencies` `++=` is less error prone than `:=`. Also discovered some unnecessary dependencies. * Replace : with File.pathSeparator * [WIP] Make logging in ProjectService more verbose * language-server/test didn't start because of missing lookup and fansi modules * Formatting * org.enso.cli.task.notifications needs Akka and Circe to link * project-manager/test depends on buildEngineDistribution * [WIP] Even more verbose logging for creating projects * [WIP] Even more verbose logging for creating projects * Revert "[WIP] Even more verbose logging for creating projects" This reverts commita7067c8472
. * Revert "[WIP] Even more verbose logging for creating projects" This reverts commitfc6f53d4f1
. * Revert "[WIP] Make logging in ProjectService more verbose" This reverts commit427428e142
. * All the project with JPMSPlugin has stripped artifact names * Revert all placeholder fake release components to runtime.jar without version * Eliminate a cross version hack We shouldn't be specifying Scala dependencies with a Scala cross version in the suffix. * Address SBT lint warnings * Revert "Eliminate a cross version hack" This reverts commit8861dab288
. * logging-service-logback is mixedJavaScalaProject * fmt * Stripped artifact name contains classifier. This fixes tests as those were named like `artifact-tests.jar`. * Don't use LocalProject unless really needed * Add more logging when BenchProcessor fails * logging-service-logback is not mixed project * Work with java.io.File.getPath to avoid mixing slash and backslash on Windows * Reapply "Eliminate a cross version hack" This reverts commitedaa436ee8
. * Pass scalaBinaryVersion correctly * Remove scala-compiler from the distribution * Fix IllegalAccessErrors from serde * typos * License review * fmt * Move testLogProviderOnModulePath to TestJPMSConfiguration * logging-service-logback is not a mixed project --------- Co-authored-by: Jaroslav Tulach <jaroslav.tulach@enso.org> Co-authored-by: Hubert Plociniczak <hubert.plociniczak@gmail.com>
395 lines
16 KiB
Scala
395 lines
16 KiB
Scala
import JPMSPlugin.autoImport.{javaModuleName, modulePath}
|
|
import sbt._
|
|
import sbt.Keys._
|
|
import sbt.internal.inc.{CompileOutput, PlainVirtualFile}
|
|
import sbt.util.CacheStore
|
|
import xsbti.compile.IncToolOptionsUtil
|
|
|
|
import java.io.File
|
|
import java.nio.file.attribute.BasicFileAttributes
|
|
import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor}
|
|
import scala.collection.mutable
|
|
|
|
/** Collection of utility methods dealing with JPMS modules.
|
|
* The motivation comes from the update of GraalVM to
|
|
* [Truffle unchained](https://medium.com/graalvm/truffle-unchained-13887b77b62c) -
|
|
* we need to add Truffle and Graal related Jars on module-path.
|
|
* We also need to convert our runtime projects to *explicit modules*, and thus,
|
|
* all our other projects to *automatic modules*.
|
|
* @see
|
|
*/
|
|
object JPMSUtils {
|
|
val slf4jVersion = "2.0.9"
|
|
val logbackClassicVersion = "1.3.7"
|
|
|
|
/** The list of modules that are included in the `component` directory in engine distribution.
|
|
* When invoking the `java` command, these modules need to be put on the module-path.
|
|
*/
|
|
val componentModules: Seq[ModuleID] =
|
|
GraalVM.modules ++ GraalVM.langsPkgs ++ GraalVM.toolsPkgs ++ Seq(
|
|
"org.slf4j" % "slf4j-api" % slf4jVersion,
|
|
"ch.qos.logback" % "logback-classic" % logbackClassicVersion,
|
|
"ch.qos.logback" % "logback-core" % logbackClassicVersion
|
|
)
|
|
|
|
/** Filters modules by their IDs from the given classpath.
|
|
*
|
|
* @param cp The classpath to filter
|
|
* @param modules These modules are looked for in the class path, can be duplicated
|
|
* @param projName Name of the current sbt project for debugging
|
|
* @param shouldContainAll If true, the method will throw an exception if not all modules were found
|
|
* in the classpath
|
|
* @param scalaBinaryVersion Scala version used in all dependencies
|
|
* @return The classpath with only the provided modules searched by their IDs
|
|
*/
|
|
def filterModulesFromClasspath(
|
|
cp: Def.Classpath,
|
|
modules: Seq[ModuleID],
|
|
log: sbt.util.Logger,
|
|
projName: String,
|
|
scalaBinaryVersion: String,
|
|
shouldContainAll: Boolean = false
|
|
): Def.Classpath = {
|
|
val distinctModules = modules.distinct
|
|
|
|
val ret = cp.filter(dep => {
|
|
val moduleID = dep.metadata.get(AttributeKey[ModuleID]("moduleID")).get
|
|
shouldFilterModule(distinctModules, scalaBinaryVersion)(moduleID)
|
|
})
|
|
|
|
if (shouldContainAll) {
|
|
if (ret.size < distinctModules.size) {
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Not all modules from classpath were found"
|
|
)
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Ensure libraryDependencies and moduleDependencies are correct"
|
|
)
|
|
log.error(s"[JPMSUtils/$projName] Returned (${ret.size}): $ret")
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Expected: (${distinctModules.size}): $distinctModules"
|
|
)
|
|
}
|
|
}
|
|
ret
|
|
}
|
|
|
|
/** Filters all the requested modules from the given [[UpdateReport]].
|
|
*
|
|
* @param updateReport The update report to filter. This is the result of `update.value`.
|
|
* @param modules The modules to filter from the update report. Can be duplicated.
|
|
* @param log The logger to use for logging.
|
|
* @param projName Name of the current sbt project for debugging.
|
|
* @param scalaBinaryVersion Scala version used in all dependencies
|
|
* @param shouldContainAll If true, the method will log an error if not all modules were found.
|
|
* @return The list of files (Jar archives, directories, etc.) that were found in the update report.
|
|
*/
|
|
def filterModulesFromUpdate(
|
|
updateReport: UpdateReport,
|
|
modules: Seq[ModuleID],
|
|
log: sbt.util.Logger,
|
|
projName: String,
|
|
scalaBinaryVersion: String,
|
|
shouldContainAll: Boolean = false
|
|
): Seq[File] = {
|
|
val distinctModules = modules.distinct
|
|
|
|
val foundFiles = updateReport.select(
|
|
module = shouldFilterModule(distinctModules, scalaBinaryVersion)
|
|
)
|
|
if (shouldContainAll) {
|
|
if (foundFiles.size < distinctModules.size) {
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Not all modules from update were found"
|
|
)
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Ensure libraryDependencies and moduleDependencies are correct"
|
|
)
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Returned (${foundFiles.size}): $foundFiles"
|
|
)
|
|
log.error(
|
|
s"[JPMSUtils/$projName] Expected: (${distinctModules.size}): $distinctModules"
|
|
)
|
|
}
|
|
}
|
|
foundFiles
|
|
}
|
|
|
|
def shouldFilterModule(
|
|
distinctModules: Seq[ModuleID],
|
|
scalaBinaryVersion: String
|
|
)(module: ModuleID): Boolean = {
|
|
distinctModules.exists(m =>
|
|
m.organization == module.organization &&
|
|
(m.name == module.name || m.crossVersion.isInstanceOf[
|
|
sbt.librarymanagement.Binary
|
|
] && s"${m.name}_$scalaBinaryVersion" == module.name) &&
|
|
m.revision == module.revision
|
|
)
|
|
}
|
|
|
|
def filterArtifacts(
|
|
classPath: Def.Classpath,
|
|
predicates: String*
|
|
): Def.Classpath = {
|
|
val truffleRelatedArtifacts =
|
|
classPath.filter(file =>
|
|
predicates.exists(p => file.data.getPath.contains(p))
|
|
)
|
|
truffleRelatedArtifacts
|
|
}
|
|
|
|
lazy val extraMp = taskKey[Def.Classpath](
|
|
"Additional internal projects to put on the module path"
|
|
)
|
|
|
|
/** Compiles a single `module-info.java` source file with the default java compiler (
|
|
* the one that is defined for the project). Before the module-info is compiled, all the
|
|
* class files from `scopeFilter` are copied into the `target` directory of the current project.
|
|
* This is because we want the `module-info.java` to be an *Uber module-info* that is defined for
|
|
* multiple sbt projects, like `runtime` and `runtime-with-instruments`, so before the `module-info.java`
|
|
* is passed to the compiler, we need to copy all the classes from the sbt projects into a single directory
|
|
* so that the compiler has an illusion that all these projects are in fact a single project.
|
|
*
|
|
* Note that sbt is not able to correctly handle `module-info.java` files when
|
|
* compilation order is defined to mixed order.
|
|
*
|
|
* Compilation of `module-info.java` is skipped iff none of all the classes from all the dependencies
|
|
* changed and if the `module-info.java` itself have not changed.
|
|
*
|
|
* To put internal modules (any sbt project defined in `build.sbt`) on module path, use `extraMp` setting.
|
|
*
|
|
* Note that this task will only work if it is defined inside `Compile` scope. In other words, it won't work
|
|
* e.g. in `Test` scope.
|
|
*
|
|
* @param copyDepsFilter The filter of scopes of the projects from which the class files are first
|
|
* copied into the `target` directory before `module-info.java` is compiled.
|
|
* @param modulePath IDs of dependencies that should be put on the module path. The modules
|
|
* put into `modulePath` are filtered away from class-path, so that module-path
|
|
* and class-path passed to the `javac` are exclusive.
|
|
*
|
|
* @see https://users.scala-lang.org/t/scala-jdk-11-and-jpms/6102/19
|
|
*/
|
|
def compileModuleInfo(
|
|
copyDepsFilter: ScopeFilter,
|
|
modulePath: Seq[ModuleID] = Seq()
|
|
): Def.Initialize[Task[Unit]] =
|
|
Def
|
|
.task {
|
|
val moduleInfo = (Compile / javaSource).value / "module-info.java"
|
|
val log = streams.value.log
|
|
val incToolOpts = IncToolOptionsUtil.defaultIncToolOptions()
|
|
val reporter = (Compile / compile / bspReporter).value
|
|
val output = CompileOutput((Compile / classDirectory).value.toPath)
|
|
// Target directory where all the classes from all the dependencies will be
|
|
// copied to.
|
|
val outputPath: Path = output.getSingleOutputAsPath
|
|
.get()
|
|
// Class directories of all the dependencies.
|
|
val sourceProducts =
|
|
productDirectories.all(copyDepsFilter).value.flatten
|
|
|
|
val extraModuleDirs = (Compile / extraMp).value.map(_.data)
|
|
val moduleName = javaModuleName.value
|
|
val cacheStore = streams.value.cacheStoreFactory
|
|
val repoRootDir = (LocalProject("enso") / baseDirectory).value
|
|
var someDepChanged = false
|
|
sourceProducts.foreach(sourceProduct => {
|
|
if (!sourceProduct.exists()) {
|
|
log.error(s"Source product ${sourceProduct} does not exist")
|
|
log.error(
|
|
"This means that the Compile/compile task was probably not run in " +
|
|
"the corresponding project"
|
|
)
|
|
log.error("Run Compile/compile before this task")
|
|
}
|
|
val relPath = repoRootDir.toPath.relativize(sourceProduct.toPath)
|
|
val cache = cacheStore.make("cache-" + relPath.toString)
|
|
val depChanged = copyClasses(sourceProduct, output, cache, log)
|
|
if (depChanged) {
|
|
someDepChanged = true
|
|
}
|
|
})
|
|
|
|
val baseJavacOpts = (Compile / javacOptions).value
|
|
val fullCp = (Compile / fullClasspath).value
|
|
val javaCompiler =
|
|
(Compile / compile / compilers).value.javaTools.javac()
|
|
|
|
// Skip module-info.java compilation if the source have not changed
|
|
// Force the compilation if some class file from one of the dependencies changed,
|
|
// just to be sure that we don't cause any weird compilation errors.
|
|
val moduleInfoCache = cacheStore.make("cache-module-info-" + moduleName)
|
|
Tracked.diffInputs(moduleInfoCache, FileInfo.lastModified)(
|
|
Set(moduleInfo)
|
|
) { changeReport =>
|
|
if (
|
|
someDepChanged || changeReport.modified.nonEmpty || changeReport.added.nonEmpty
|
|
) {
|
|
log.info(s"Compiling $moduleInfo with javac")
|
|
val (mp, cp) = fullCp.partition(file => {
|
|
val moduleID =
|
|
file.metadata.get(AttributeKey[ModuleID]("moduleID")).get
|
|
modulePath.exists(mod => {
|
|
mod.organization == moduleID.organization &&
|
|
mod.name == moduleID.name &&
|
|
mod.revision == moduleID.revision
|
|
})
|
|
})
|
|
val allDirsOnMp = mp.map(_.data) ++ extraModuleDirs
|
|
|
|
val allOpts = baseJavacOpts ++ Seq(
|
|
"--class-path",
|
|
cp.map(_.data.getAbsolutePath).mkString(File.pathSeparator),
|
|
"--module-path",
|
|
allDirsOnMp.map(_.getAbsolutePath).mkString(File.pathSeparator),
|
|
"-d",
|
|
outputPath.toAbsolutePath.toString
|
|
)
|
|
log.debug(s"javac options: $allOpts")
|
|
|
|
val succ = javaCompiler.run(
|
|
Array(PlainVirtualFile(moduleInfo.toPath)),
|
|
allOpts.toArray,
|
|
output,
|
|
incToolOpts,
|
|
reporter,
|
|
log
|
|
)
|
|
if (!succ) {
|
|
val msg = s"Compilation of ${moduleInfo} failed"
|
|
log.error(s"javac options: $allOpts")
|
|
log.error(msg)
|
|
throw new IllegalStateException(msg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Compiles `module-info.java` in the current project. The module path is
|
|
* gathered from [[JPMSPlugin.autoImport.modulePath]] settings.
|
|
* @see [[compileModuleInfo]].
|
|
*/
|
|
def compileModuleInfo(): Def.Initialize[Task[Unit]] = Def.task {
|
|
val moduleInfo = (Compile / javaSource).value / "module-info.java"
|
|
val projName = moduleName.value
|
|
val log = streams.value.log
|
|
val incToolOpts = IncToolOptionsUtil.defaultIncToolOptions()
|
|
val reporter = (Compile / compile / bspReporter).value
|
|
val output = CompileOutput((Compile / classDirectory).value.toPath)
|
|
val outputPath: Path = output.getSingleOutputAsPath.get()
|
|
val mp = (Compile / modulePath).value
|
|
val baseJavacOpts = (Compile / javacOptions).value
|
|
val cp = (Compile / fullClasspath).value
|
|
val javaCompiler =
|
|
(Compile / compile / compilers).value.javaTools.javac()
|
|
val cache =
|
|
streams.value.cacheStoreFactory.make("cache-module-info-" + projName)
|
|
|
|
Tracked.diffInputs(cache, FileInfo.lastModified)(
|
|
Set(moduleInfo)
|
|
) { changeReport =>
|
|
if (changeReport.modified.nonEmpty || changeReport.added.nonEmpty) {
|
|
log.info(s"Compiling $moduleInfo with javac")
|
|
val allOpts = baseJavacOpts ++ Seq(
|
|
"--class-path",
|
|
cp.map(_.data.getAbsolutePath).mkString(File.pathSeparator),
|
|
"--module-path",
|
|
mp.map(_.getAbsolutePath).mkString(File.pathSeparator),
|
|
"-d",
|
|
outputPath.toAbsolutePath.toString
|
|
)
|
|
log.debug(s"javac options: $allOpts")
|
|
val succ = javaCompiler.run(
|
|
Array(PlainVirtualFile(moduleInfo.toPath)),
|
|
allOpts.toArray,
|
|
output,
|
|
incToolOpts,
|
|
reporter,
|
|
log
|
|
)
|
|
if (!succ) {
|
|
val msg = s"Compilation of ${moduleInfo} failed"
|
|
log.error(s"javac options: $allOpts")
|
|
log.error(msg)
|
|
throw new IllegalStateException(msg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Copies all classes from all the dependencies `classes` directories into the target directory.
|
|
* @param sourceClassesDir Directory from where the classes will be copied.
|
|
* @param output Target directory where all the classes from all the dependencies
|
|
* will be copied to.
|
|
* @param log
|
|
* @return True iff some of the dependencies changed, i.e., if there is a modified class file, or
|
|
* some class file was added, or removed
|
|
*/
|
|
private def copyClasses(
|
|
sourceClassesDir: File,
|
|
output: xsbti.compile.Output,
|
|
cache: CacheStore,
|
|
log: Logger
|
|
): Boolean = {
|
|
require(sourceClassesDir.isDirectory)
|
|
val outputPath: Path = output.getSingleOutputAsPath.get()
|
|
val outputDir = outputPath.toFile
|
|
val filesToCopy = mutable.HashSet.empty[File]
|
|
val fileVisitor = new SimpleFileVisitor[Path] {
|
|
override def visitFile(
|
|
path: Path,
|
|
attrs: BasicFileAttributes
|
|
): FileVisitResult = {
|
|
if (!path.toFile.isDirectory) {
|
|
filesToCopy.add(path.toFile)
|
|
}
|
|
FileVisitResult.CONTINUE
|
|
}
|
|
|
|
override def preVisitDirectory(
|
|
dir: Path,
|
|
attrs: BasicFileAttributes
|
|
): FileVisitResult = {
|
|
// We do not care about files in META-INF directory. Everything should be described
|
|
// in the `module-info.java`.
|
|
if (dir.getFileName.toString == "META-INF") {
|
|
FileVisitResult.SKIP_SUBTREE
|
|
} else {
|
|
FileVisitResult.CONTINUE
|
|
}
|
|
}
|
|
}
|
|
Files.walkFileTree(sourceClassesDir.toPath, fileVisitor)
|
|
if (!outputDir.exists()) {
|
|
IO.createDirectory(outputDir)
|
|
}
|
|
var someDependencyChanged = false
|
|
Tracked.diffInputs(cache, FileInfo.lastModified)(filesToCopy.toSet) {
|
|
changeReport =>
|
|
for (f <- changeReport.removed) {
|
|
val relPath = sourceClassesDir.toPath.relativize(f.toPath)
|
|
val dest = outputDir.toPath.resolve(relPath)
|
|
IO.delete(dest.toFile)
|
|
someDependencyChanged = true
|
|
}
|
|
for (f <- changeReport.modified -- changeReport.removed) {
|
|
val relPath = sourceClassesDir.toPath.relativize(f.toPath)
|
|
val dest = outputDir.toPath.resolve(relPath)
|
|
IO.copyFile(f, dest.toFile)
|
|
someDependencyChanged = true
|
|
}
|
|
for (f <- changeReport.unmodified) {
|
|
val relPath = sourceClassesDir.toPath.relativize(f.toPath)
|
|
val dest = outputDir.toPath.resolve(relPath)
|
|
if (!dest.toFile.exists()) {
|
|
IO.copyFile(f, dest.toFile)
|
|
someDependencyChanged = true
|
|
}
|
|
}
|
|
}
|
|
someDependencyChanged
|
|
}
|
|
}
|