Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify declaration of module path in sbt build #10836

Merged
merged 8 commits into from
Aug 19, 2024
273 changes: 94 additions & 179 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,25 @@ val jnaVersion = "5.14.0"
// === Utility methods =====================================================
// ============================================================================

lazy val componentModulesIds =
taskKey[Seq[ModuleID]](
"Gather all sbt module IDs that will be put on the module-path for the engine runner"
)
(ThisBuild / componentModulesIds) := {
GraalVM.modules ++ GraalVM.langsPkgs ++ GraalVM.toolsPkgs ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"ch.qos.logback" % "logback-classic" % logbackClassicVersion,
"ch.qos.logback" % "logback-core" % logbackClassicVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
(`runtime-language-arrow` / projectID).value,
(`syntax-rust-definition` / projectID).value,
(`ydoc-server` / projectID).value,
(`profiling-utils` / projectID).value,
(`runtime-fat-jar` / projectID).value
)
}

// TODO[pm]: this is now deprecated and should be removed
lazy val componentModulesPaths =
taskKey[Seq[File]](
"Gathers all component modules (Jar archives that should be put on module-path" +
Expand Down Expand Up @@ -836,15 +855,10 @@ lazy val `profiling-utils` = project
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test
),
modulePath := {
JPMSUtils.filterModulesFromUpdate(
update.value,
Seq(
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
"org.slf4j" % "slf4j-api" % slf4jVersion
),
streams.value.log,
shouldContainAll = true
moduleDependencies := {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same format as libraryDependencies. No longer need to call this cryptic filterModulesFromUpdate methods ...

Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion
)
}
)
Expand Down Expand Up @@ -1094,33 +1108,14 @@ lazy val `project-manager` = (project in file("lib/scala/project-manager"))
(`profiling-utils` / javaModuleName).value,
(`ydoc-server` / javaModuleName).value
),
Test / modulePath := {
val updateReport = (Test / update).value
val requiredModIds =
GraalVM.modules ++ GraalVM.langsPkgs ++ logbackPkg ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion
)
val requiredMods = JPMSUtils.filterModulesFromUpdate(
updateReport,
requiredModIds,
streams.value.log,
shouldContainAll = true
)
val runtimeMod =
(`runtime-fat-jar` / Compile / productDirectories).value.head
val ydocMod =
(`ydoc-server` / Compile / exportedProducts).value.head.data
val syntaxMod =
(`syntax-rust-definition` / Compile / exportedProducts).value.head.data
val profilingMod =
(`profiling-utils` / Compile / exportedProducts).value.head.data

requiredMods ++ Seq(
runtimeMod,
ydocMod,
syntaxMod,
profilingMod
Test / moduleDependencies := {
GraalVM.modules ++ GraalVM.langsPkgs ++ logbackPkg ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
(`runtime-fat-jar` / projectID).value,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how you specify that you want to put runtime-fat-jar/target/classes directory on module-path. I have found no way to infer this directly.

(`ydoc-server` / projectID).value,
(`syntax-rust-definition` / projectID).value,
(`profiling-utils` / projectID).value
)
},
Test / javaOptions ++= testLogProviderOptions
Expand Down Expand Up @@ -1168,6 +1163,9 @@ lazy val `project-manager` = (project in file("lib/scala/project-manager"))
.dependsOn(testkit % Test)
.dependsOn(`runtime-version-manager-test` % Test)
.dependsOn(`logging-service-logback` % "test->test")
.dependsOn(`runtime-fat-jar` % Test)
.dependsOn(`ydoc-server` % Test)
.dependsOn(`profiling-utils` % Test)

/* Note [Classpath Separation]
* ~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1268,24 +1266,15 @@ lazy val `ydoc-server` = project
autoScalaLibrary := false,
Test / fork := true,
commands += WithDebugCommand.withDebug,
// GraalVM and helidon modules (3rd party modules)
modulePath := {
JPMSUtils.filterModulesFromUpdate(
update.value,
GraalVM.modules ++ GraalVM.jsPkgs ++ GraalVM.chromeInspectorPkgs ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"ch.qos.logback" % "logback-classic" % logbackClassicVersion,
"ch.qos.logback" % "logback-core" % logbackClassicVersion
),
streams.value.log,
shouldContainAll = true
)
moduleDependencies := {
GraalVM.modules ++ GraalVM.jsPkgs ++ GraalVM.chromeInspectorPkgs ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"ch.qos.logback" % "logback-classic" % logbackClassicVersion,
"ch.qos.logback" % "logback-core" % logbackClassicVersion,
(`syntax-rust-definition` / projectID).value,
(`profiling-utils` / projectID).value
),
},
// Internal project modules
modulePath ++= Seq(
(`syntax-rust-definition` / Compile / productDirectories).value.head,
(`profiling-utils` / Compile / productDirectories).value.head
),
libraryDependencies ++= Seq(
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % "provided",
"org.graalvm.polyglot" % "inspect" % graalMavenPackagesVersion % "runtime",
Expand All @@ -1296,7 +1285,10 @@ lazy val `ydoc-server` = project
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion % Test
)
),
libraryDependencies ++= {
GraalVM.modules ++ GraalVM.jsPkgs ++ GraalVM.chromeInspectorPkgs ++ helidon
}
)
// `Compile/run` settings are necessary for the `run` task to work.
// We add it here for convenience so that one can start ydoc-server directly
Expand Down Expand Up @@ -1585,32 +1577,14 @@ lazy val `language-server` = (project in file("engine/language-server"))
(`profiling-utils` / javaModuleName).value,
(`ydoc-server` / javaModuleName).value
),
Test / modulePath := {
val updateReport = (Test / update).value
val requiredModIds =
GraalVM.modules ++ GraalVM.langsPkgs ++ logbackPkg ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion
)
val requiredMods = JPMSUtils.filterModulesFromUpdate(
updateReport,
requiredModIds,
streams.value.log,
shouldContainAll = true
)
val runtimeMod =
(`runtime-fat-jar` / Compile / productDirectories).value.head
val syntaxMod =
(`syntax-rust-definition` / Compile / productDirectories).value.head
val ydocMod =
(`ydoc-server` / Compile / productDirectories).value.head
val profilingMod =
(`profiling-utils` / Compile / productDirectories).value.head
requiredMods ++ Seq(
runtimeMod,
syntaxMod,
ydocMod,
profilingMod
Test / moduleDependencies := {
GraalVM.modules ++ GraalVM.langsPkgs ++ logbackPkg ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
(`runtime-fat-jar` / projectID).value,
(`syntax-rust-definition` / projectID).value,
(`ydoc-server` / projectID).value,
(`profiling-utils` / projectID).value
)
},
Test / javaOptions ++= testLogProviderOptions,
Expand Down Expand Up @@ -1698,6 +1672,7 @@ lazy val `language-server` = (project in file("engine/language-server"))
.dependsOn(filewatcher)
.dependsOn(testkit % Test)
.dependsOn(`logging-service-logback` % "test->test")
.dependsOn(`runtime-fat-jar` % Test)
.dependsOn(`library-manager-test` % Test)
.dependsOn(`runtime-version-manager-test` % Test)
.dependsOn(`ydoc-server`)
Expand Down Expand Up @@ -1843,19 +1818,9 @@ lazy val `runtime-language-arrow` =
"org.apache.arrow" % "arrow-memory-netty" % apacheArrowVersion % Test
),
javaModuleName := "org.enso.interpreter.arrow",
modulePath := {
val updateReport = (Test / update).value
JPMSUtils.filterModulesFromUpdate(
updateReport,
GraalVM.modules,
streams.value.log,
shouldContainAll = true
) ++ Seq(
(LocalProject(
"runtime-language-arrow"
) / Compile / productDirectories).value.head
)
},
moduleDependencies := GraalVM.modules,
Test / moduleDependencies +=
(LocalProject("runtime-language-arrow") / projectID).value,
Test / patchModules := {
val testClassesDir = (Test / productDirectories).value.head
Map(javaModuleName.value -> Seq(testClassesDir))
Expand All @@ -1881,29 +1846,24 @@ lazy val `runtime-test-instruments` =
inConfig(Compile)(truffleRunOptionsSettings),
truffleDslSuppressWarnsSetting,
instrumentationSettings,
javaModuleName := "org.enso.runtime.test",
modulePath := {
JPMSUtils.filterModulesFromUpdate(
update.value,
GraalVM.modules ++ Seq(
"org.graalvm.sdk" % "polyglot-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-common" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-tests" % graalMavenPackagesVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion
),
streams.value.log,
shouldContainAll = true
)
},
libraryDependencies ++= GraalVM.modules,
libraryDependencies ++= Seq(
"org.graalvm.sdk" % "polyglot-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-common" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-tests" % graalMavenPackagesVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion % "provided"
)
),
javaModuleName := "org.enso.runtime.test",
moduleDependencies := {
GraalVM.modules ++ Seq(
"org.graalvm.sdk" % "polyglot-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-common" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-tests" % graalMavenPackagesVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion % "provided"
)
}
)

lazy val runtime = (project in file("engine/runtime"))
Expand Down Expand Up @@ -2025,40 +1985,20 @@ lazy val `runtime-integration-tests` =
(`profiling-utils` / javaModuleName).value,
(`ydoc-server` / javaModuleName).value
),
Test / modulePath := {
val updateReport = (Test / update).value
val requiredModIds =
GraalVM.modules ++ GraalVM.langsPkgs ++ GraalVM.insightPkgs ++ logbackPkg ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
"org.graalvm.sdk" % "polyglot-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-common" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-tests" % graalMavenPackagesVersion
)
val requiredMods = JPMSUtils.filterModulesFromUpdate(
updateReport,
requiredModIds,
streams.value.log,
shouldContainAll = true
)
val runtimeTestInstrumentsMod =
(`runtime-test-instruments` / Compile / exportedProducts).value.head.data
val runtimeMod =
(`runtime-fat-jar` / Compile / exportedProducts).value.head.data
val ydocMod =
(`ydoc-server` / Compile / exportedProducts).value.head.data
val syntaxMod =
(`syntax-rust-definition` / Compile / exportedProducts).value.head.data
val profilingMod =
(`profiling-utils` / Compile / exportedProducts).value.head.data
requiredMods ++ Seq(
runtimeTestInstrumentsMod,
runtimeMod,
ydocMod,
syntaxMod,
profilingMod
Test / moduleDependencies := {
GraalVM.modules ++ GraalVM.langsPkgs ++ GraalVM.insightPkgs ++ logbackPkg ++ helidon ++ Seq(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty understandable! It is a format I hope to be able to work with.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad. More info in the scaladocs of JPMSPlugin

"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
"org.graalvm.sdk" % "polyglot-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-common" % graalMavenPackagesVersion,
"org.graalvm.truffle" % "truffle-tck-tests" % graalMavenPackagesVersion,
(`runtime-test-instruments` / projectID).value,
(`runtime-fat-jar` / projectID).value,
(`ydoc-server` / projectID).value,
(`syntax-rust-definition` / projectID).value,
(`profiling-utils` / projectID).value
)
},
Test / patchModules := {
Expand Down Expand Up @@ -2158,32 +2098,15 @@ lazy val `runtime-benchmarks` =
.dependsOn(`runtime-fat-jar` / assembly)
.value,
parallelExecution := false,
modulePath := {
val requiredModIds =
GraalVM.modules ++ GraalVM.langsPkgs ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "slf4j-nop" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion
)
val requiredMods = JPMSUtils.filterModulesFromUpdate(
(Compile / update).value,
requiredModIds,
streams.value.log,
shouldContainAll = true
)
val runtimeMod =
(`runtime-fat-jar` / assembly / assemblyOutputPath).value
val ydocMod =
(`ydoc-server` / Compile / exportedProducts).value.head.data
val syntaxMod =
(`syntax-rust-definition` / Compile / exportedProducts).value.head.data
val profilingMod =
(`profiling-utils` / Compile / exportedProducts).value.head.data
requiredMods ++ Seq(
runtimeMod,
ydocMod,
syntaxMod,
profilingMod
moduleDependencies := {
GraalVM.modules ++ GraalVM.langsPkgs ++ helidon ++ Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "slf4j-nop" % slf4jVersion,
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
(`runtime-fat-jar` / projectID).value,
(`ydoc-server` / projectID).value,
(`syntax-rust-definition` / projectID).value,
(`profiling-utils` / projectID).value
)
},
addModules := {
Expand Down Expand Up @@ -2969,18 +2892,10 @@ lazy val `std-benchmarks` = (project in file("std-bits/benchmarks"))
"-J-Dpolyglotimpl.DisableClassPathIsolation=true",
"-J-Dpolyglot.engine.WarnInterpreterOnly=false"
),
modulePath := {
val allRuntimeMods = componentModulesPaths.value
val otherModIds = Seq(
moduleDependencies := {
componentModulesIds.value ++ Seq(
"org.slf4j" % "slf4j-nop" % slf4jVersion
)
val requiredMods = JPMSUtils.filterModulesFromUpdate(
(Compile / update).value,
otherModIds,
streams.value.log,
shouldContainAll = true
)
allRuntimeMods ++ requiredMods
},
addModules := {
val runtimeModuleName = (`runtime-fat-jar` / javaModuleName).value
Expand Down
Loading
Loading