From 55c23253be365b43f1e026cd68b97f4256fb2e58 Mon Sep 17 00:00:00 2001 From: Maciej Gorywoda Date: Tue, 22 Jun 2021 17:59:38 +0200 Subject: [PATCH 1/2] Add Automatic-Module-Names to MANIFEST.MF files of projects with suffix _3 The issue is described in https://github.com/lampepfl/dotty/issues/12899 In this PR I decided to add `Automatic-Module-Name` values only to projects with the suffix _3, that is: 1. scala3-compiler_3 2. scala3-library_3 3. scala3-library-sjs1_3 4. scala3-language-server_3 5. scala3-staging_3 6. scala3-tasty-inspector_3 7. scaladoc_3 8. tasty-core_3 and for consistency also tasty-core-scala2. The values are derived from dottyOrganization + the project name. --- project/Build.scala | 64 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 4f85e7676b96..2c62c3c1e129 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -751,9 +751,18 @@ object Build { def dottyCompilerSettings(implicit mode: Mode): sbt.Def.SettingsDefinition = if (mode == NonBootstrapped) nonBootstrapedDottyCompilerSettings else bootstrapedDottyCompilerSettings - lazy val `scala3-compiler` = project.in(file("compiler")).asDottyCompiler(NonBootstrapped) - lazy val `scala3-compiler-bootstrapped` = project.in(file("compiler")).asDottyCompiler(Bootstrapped) - + lazy val `scala3-compiler` = project.in(file("compiler")). + asDottyCompiler(NonBootstrapped). + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) + lazy val `scala3-compiler-bootstrapped` = project.in(file("compiler")). + asDottyCompiler(Bootstrapped). + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) def dottyCompiler(implicit mode: Mode): Project = mode match { case NonBootstrapped => `scala3-compiler` case Bootstrapped => `scala3-compiler-bootstrapped` @@ -767,8 +776,18 @@ object Build { ), ) - lazy val `scala3-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped) - lazy val `scala3-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped) + lazy val `scala3-library` = project.in(file("library")). + asDottyLibrary(NonBootstrapped). + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) + lazy val `scala3-library-bootstrapped`: Project = project.in(file("library")). + asDottyLibrary(Bootstrapped). + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) def dottyLibrary(implicit mode: Mode): Project = mode match { case NonBootstrapped => `scala3-library` @@ -792,6 +811,8 @@ object Build { ("org.scala-js" %% "scalajs-library" % scalaJSVersion).cross(CrossVersion.for3Use2_13), Compile / unmanagedSourceDirectories ++= (`scala3-library-bootstrapped` / Compile / unmanagedSourceDirectories).value, + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}"), // Configure the source maps to point to GitHub for releases scalacOptions ++= { @@ -813,9 +834,24 @@ object Build { scalacOptions += "-source:3.0-migration" ) - lazy val `tasty-core` = project.in(file("tasty")).asTastyCore(NonBootstrapped) - lazy val `tasty-core-bootstrapped`: Project = project.in(file("tasty")).asTastyCore(Bootstrapped) - lazy val `tasty-core-scala2`: Project = project.in(file("tasty")).asTastyCoreScala2 + lazy val `tasty-core` = project.in(file("tasty")). + asTastyCore(NonBootstrapped). + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) + lazy val `tasty-core-bootstrapped`: Project = project.in(file("tasty")). + asTastyCore(Bootstrapped). + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) + lazy val `tasty-core-scala2`: Project = project.in(file("tasty")). + asTastyCoreScala2. + settings( + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + ) def tastyCore(implicit mode: Mode): Project = mode match { case NonBootstrapped => `tasty-core` @@ -829,7 +865,9 @@ object Build { // but we always need it to be present on the JVM classpath at runtime. dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). settings( - javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value + javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") ) lazy val `scala3-tasty-inspector` = project.in(file("tasty-inspector")). @@ -839,7 +877,9 @@ object Build { // but we always need it to be present on the JVM classpath at runtime. dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). settings( - javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value + javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") ) /** Scala library compiled by dotty using the latest published sources of the library */ @@ -999,6 +1039,8 @@ object Build { // Work around https://github.com/eclipse/lsp4j/issues/295 dependencyOverrides += "org.eclipse.xtend" % "org.eclipse.xtend.lib" % "2.16.0", javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}"), run := Def.inputTaskDyn { val inputArgs = spaceDelimited("").parsed @@ -1302,6 +1344,8 @@ object Build { Compile / mainClass := Some("dotty.tools.scaladoc.Main"), Compile / buildInfoKeys := Seq[BuildInfoKey](version), Compile / buildInfoPackage := "dotty.tools.scaladoc", + Compile / packageBin / packageOptions += + Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}"), BuildInfoPlugin.buildInfoScopedSettings(Compile), BuildInfoPlugin.buildInfoDefaultSettings, From 792cfd6014d0cc23fde2601a545dbdc4732f430b Mon Sep 17 00:00:00 2001 From: Maciej Gorywoda Date: Wed, 23 Jun 2021 19:02:04 +0200 Subject: [PATCH 2/2] Changes in order to make setting Automatic-Module-Name automatic for all projects with commonSettings --- project/Build.scala | 71 +++++++++++---------------------------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 2c62c3c1e129..e28c88a39c64 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -269,6 +269,13 @@ object Build { // If someone puts a source file at the root (e.g., for manual testing), // don't pick it up as part of any project. sourcesInBase := false, + + // For compatibility with Java 9+ module system; + // without Automatic-Module-Name, the module name is derived from the jar file which is invalid because of the _3 suffix. + Compile / packageBin / packageOptions += + Package.ManifestAttributes( + "Automatic-Module-Name" -> s"${dottyOrganization.replaceAll("-",".")}.${moduleName.value.replaceAll("-",".")}" + ) ) // Settings used for projects compiled only with Java @@ -751,18 +758,9 @@ object Build { def dottyCompilerSettings(implicit mode: Mode): sbt.Def.SettingsDefinition = if (mode == NonBootstrapped) nonBootstrapedDottyCompilerSettings else bootstrapedDottyCompilerSettings - lazy val `scala3-compiler` = project.in(file("compiler")). - asDottyCompiler(NonBootstrapped). - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) - lazy val `scala3-compiler-bootstrapped` = project.in(file("compiler")). - asDottyCompiler(Bootstrapped). - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) + lazy val `scala3-compiler` = project.in(file("compiler")).asDottyCompiler(NonBootstrapped) + lazy val `scala3-compiler-bootstrapped` = project.in(file("compiler")).asDottyCompiler(Bootstrapped) + def dottyCompiler(implicit mode: Mode): Project = mode match { case NonBootstrapped => `scala3-compiler` case Bootstrapped => `scala3-compiler-bootstrapped` @@ -776,18 +774,8 @@ object Build { ), ) - lazy val `scala3-library` = project.in(file("library")). - asDottyLibrary(NonBootstrapped). - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) - lazy val `scala3-library-bootstrapped`: Project = project.in(file("library")). - asDottyLibrary(Bootstrapped). - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) + lazy val `scala3-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped) + lazy val `scala3-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped) def dottyLibrary(implicit mode: Mode): Project = mode match { case NonBootstrapped => `scala3-library` @@ -811,8 +799,6 @@ object Build { ("org.scala-js" %% "scalajs-library" % scalaJSVersion).cross(CrossVersion.for3Use2_13), Compile / unmanagedSourceDirectories ++= (`scala3-library-bootstrapped` / Compile / unmanagedSourceDirectories).value, - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}"), // Configure the source maps to point to GitHub for releases scalacOptions ++= { @@ -834,24 +820,9 @@ object Build { scalacOptions += "-source:3.0-migration" ) - lazy val `tasty-core` = project.in(file("tasty")). - asTastyCore(NonBootstrapped). - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) - lazy val `tasty-core-bootstrapped`: Project = project.in(file("tasty")). - asTastyCore(Bootstrapped). - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) - lazy val `tasty-core-scala2`: Project = project.in(file("tasty")). - asTastyCoreScala2. - settings( - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") - ) + lazy val `tasty-core` = project.in(file("tasty")).asTastyCore(NonBootstrapped) + lazy val `tasty-core-bootstrapped`: Project = project.in(file("tasty")).asTastyCore(Bootstrapped) + lazy val `tasty-core-scala2`: Project = project.in(file("tasty")).asTastyCoreScala2 def tastyCore(implicit mode: Mode): Project = mode match { case NonBootstrapped => `tasty-core` @@ -865,9 +836,7 @@ object Build { // but we always need it to be present on the JVM classpath at runtime. dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). settings( - javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value ) lazy val `scala3-tasty-inspector` = project.in(file("tasty-inspector")). @@ -877,9 +846,7 @@ object Build { // but we always need it to be present on the JVM classpath at runtime. dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). settings( - javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}") + javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value ) /** Scala library compiled by dotty using the latest published sources of the library */ @@ -1039,8 +1006,6 @@ object Build { // Work around https://github.com/eclipse/lsp4j/issues/295 dependencyOverrides += "org.eclipse.xtend" % "org.eclipse.xtend.lib" % "2.16.0", javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}"), run := Def.inputTaskDyn { val inputArgs = spaceDelimited("").parsed @@ -1344,8 +1309,6 @@ object Build { Compile / mainClass := Some("dotty.tools.scaladoc.Main"), Compile / buildInfoKeys := Seq[BuildInfoKey](version), Compile / buildInfoPackage := "dotty.tools.scaladoc", - Compile / packageBin / packageOptions += - Package.ManifestAttributes("Automatic-Module-Name" -> s"$dottyOrganization-${name.value}"), BuildInfoPlugin.buildInfoScopedSettings(Compile), BuildInfoPlugin.buildInfoDefaultSettings,