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

Stop shading stuff in sbt-bloop plugins #1754

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
"gradleBloop211/compile" \
"gradleBloop212/compile" \
"gradleBloop212/test" \
"sbtBloop10Shaded/publishLocal" \
"sbtBloop10/publishLocal" \
"sbtBloop10/scripted"
shell: bash
bridges:
Expand Down
2 changes: 1 addition & 1 deletion benchmark-bridge
119 changes: 2 additions & 117 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -583,121 +583,13 @@ def isJdiJar(file: File): Boolean = {
else file.getAbsolutePath.contains(SbtJdiTools.JavaTools.getAbsolutePath.toString)
}

def shadeSbtSettingsForModule(
moduleId: String,
module: Reference
) = {
List(
(Compile / packageBin) := {
Def.taskDyn {
val baseJar = (module / Compile / Keys.packageBin).value
val unshadedJarDependencies =
(module / Compile / internalDependencyAsJars).value.map(_.data)
shadingPackageBin(baseJar, unshadedJarDependencies)
}.value
},
shadeOwnNamespaces := Set("bloop"),
shadeIgnoredNamespaces := Set("com.google.gson", "scala"),
toShadeJars := {
val eclipseJarsUnsignedDir = (Keys.crossTarget.value / "eclipse-jars-unsigned").toPath
java.nio.file.Files.createDirectories(eclipseJarsUnsignedDir)

val dependencyJars = (module / Runtime / dependencyClasspath).value.map(_.data)
dependencyJars.flatMap { path =>
val ppath = path.toString
val isEclipseJar = ppath.contains("eclipse")
val shouldShadeJar = !(
ppath.contains("scala-compiler") ||
ppath.contains("scala-library") ||
ppath.contains("scala-reflect") ||
ppath.contains("scala-xml") ||
ppath.contains("macro-compat") ||
ppath.contains("scalamacros") ||
ppath.contains("jsr") ||
ppath.contains("bcprov-jdk15on") ||
ppath.contains("bcpkix-jdk15on") ||
ppath.contains("jna") ||
ppath.contains("jna-platform") ||
isJdiJar(path)
) && path.exists && !path.isDirectory

if (!shouldShadeJar) Nil
else if (!isEclipseJar) List(path)
else {
val targetJar = eclipseJarsUnsignedDir.resolve(path.getName)
build.Shading.deleteSignedJarMetadata(path.toPath, targetJar)
List(targetJar.toFile)
}
}
},
shadeNamespaces := Set(
"machinist",
"shapeless",
"cats",
"jawn",
"org.typelevel.jawn",
"io.circe",
"com.github.plokhotnyuk.jsoniter_scala",
"snailgun",
"org.zeroturnaround",
"io.github.soc",
"org.slf4j",
"scopt",
"macrocompat",
"coursierapi",
"shapeless",
"argonaut",
"org.checkerframework",
"com.google.guava",
"com.google.common",
"com.google.j2objc",
"com.google.thirdparty",
"com.google.errorprone",
"org.codehaus",
"ch.epfl.scala.bsp4j",
"org.eclipse",
"io.github.alexarchambault.windowsansi",
"org.fusesource.hawtjni",
"org.fusesource.jansi",
"concurrentrefhashmap"
)
)
}

def defineShadedSbtPlugin(
projectName: String,
sbtVersion: String,
sbtBloop: Reference
) = {
sbt
.Project(projectName, integrations / "sbt-bloop" / "target" / s"sbt-bloop-shaded-$sbtVersion")
.enablePlugins(BloopShadingPlugin)
.disablePlugins(ScriptedPlugin)
.disablePlugins(SbtJdiTools)
.settings(sbtPluginSettings("sbt-bloop", sbtVersion))
.settings(shadedModuleSettings)
.settings(shadeSbtSettingsForModule("sbt-bloop-core", sbtBloop))
.settings(
(run / fork) := true,
(Test / fork) := true,
(Compile / bloopGenerate) := None,
(Test / bloopGenerate) := None,
target := (file("integrations") / "sbt-bloop-shaded" / "target" / sbtVersion).getAbsoluteFile
)
}

lazy val sbtBloop10: Project = project
.dependsOn(jsonConfig212.jvm)
.enablePlugins(ScriptedPlugin)
.disablePlugins(ScalafixPlugin)
.in(integrations / "sbt-bloop")
.settings(BuildDefaults.scriptedSettings)
.settings(sbtPluginSettings("sbt-bloop-core", Sbt1Version))

lazy val sbtBloop10Shaded: Project =
defineShadedSbtPlugin("sbtBloop10Shaded", Sbt1Version, sbtBloop10).settings(
scalaVersion := (sbtBloop10 / scalaVersion).value
)
.settings(sbtPluginSettings("sbt-bloop", Sbt1Version))

lazy val sbtBloop013 = project
.dependsOn(jsonConfig210.jvm)
Expand All @@ -706,14 +598,9 @@ lazy val sbtBloop013 = project
.disablePlugins(ScalafixPlugin)
.in(integrations / "sbt-bloop")
.settings(scalaVersion := Scala210Version)
.settings(sbtPluginSettings("sbt-bloop-core", Sbt013Version))
.settings(sbtPluginSettings("sbt-bloop", Sbt013Version))
.settings(resolvers += Resolver.typesafeIvyRepo("releases"))

lazy val sbtBloop013Shaded =
defineShadedSbtPlugin("sbtBloop013Shaded", Sbt013Version, sbtBloop013).settings(
scalaVersion := (sbtBloop013 / scalaVersion).value
)

lazy val mavenBloop = project
.in(integrations / "maven-bloop")
.disablePlugins(ScriptedPlugin)
Expand Down Expand Up @@ -940,8 +827,6 @@ val allProjectsToRelease = Seq[ProjectReference](
jsonConfig213.jvm,
sbtBloop013,
sbtBloop10,
sbtBloop013Shaded,
sbtBloop10Shaded,
mavenBloop,
gradleBloop211,
gradleBloop212,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.3.7")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.1")
addSbtPlugin("com.softwaremill.clippy" % "plugin-sbt" % "0.5.3")

addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.3")

addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.26")

addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1")

addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.1")

addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build-shaded" % "1.0.0-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop-build" % "1.0.0-SNAPSHOT")
updateOptions := updateOptions.value.withLatestSnapshots(false)
2 changes: 1 addition & 1 deletion project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ val mvnPluginToolsVersion = "3.6.0"
val `bloop-shaded-plugin` = project
.settings(
sbtPlugin := true,
libraryDependencies += "ch.epfl.scala" %% "sbt-bloop-build-shaded-naked" % "1.0.0-SNAPSHOT"
libraryDependencies += "ch.epfl.scala" %% "sbt-bloop-build-naked" % "1.0.0-SNAPSHOT"
)

updateOptions := updateOptions.value.withLatestSnapshots(false)
Expand Down
90 changes: 14 additions & 76 deletions project/project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,18 @@ val emptySbtPlugin = project
.settings(sharedSettings)
.settings(sbtPlugin := true)

val sbtBloopBuildShadedJar = project
.in(file("target")./("sbt-bloop-build-shaded"))
.enablePlugins(BloopShadingPlugin)
val sbtBloopBuildJar = project
.in(file("target")./("sbt-bloop-build"))
.settings(sharedSettings)
.settings(
// Published name will be sbt-bloop-shaded because of `shading:publishLocal`
sbtPlugin := true,
name := "sbt-bloop-build-shaded",
name := "sbt-bloop-build",
scalacOptions in Compile :=
(scalacOptions in Compile).value.filterNot(_ == "-deprecation"),
libraryDependencies ++= List(
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.4.0",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.4.0"
),
toShadeClasses := {
build.Shading.toShadeClasses(
shadeNamespaces.value,
shadeIgnoredNamespaces.value ++ shadeOwnNamespaces.value,
toShadeJars.value,
streams.value.log,
verbose = false
)
},
toShadeJars := {
val sbtCompileDependencies = (dependencyClasspath in Compile in emptySbtPlugin).value
val currentCompileDependencies = (dependencyClasspath in Runtime).value

val dependenciesToShade = currentCompileDependencies.filterNot { dep =>
sbtCompileDependencies.contains(dep)
}

import java.nio.file.{Files, FileSystems}
val eclipseJarsUnsignedDir = (Keys.crossTarget.value / "eclipse-jars-unsigned").toPath
Files.createDirectories(eclipseJarsUnsignedDir)
dependenciesToShade.map(_.data).flatMap { path =>
val ppath = path.toString

// Copy over jar and remove signed entries
if (!path.exists || !path.isFile) Nil
else if (ppath.contains("gson") || ppath.contains("jsr") || ppath.contains("jna")) Nil
else if (!ppath.contains("eclipse")) List(path)
else {
val targetJar = eclipseJarsUnsignedDir.resolve(path.getName)
build.Shading.deleteSignedJarMetadata(path.toPath, targetJar)
List(targetJar.toFile)
}
}

},
shadingNamespace := "shaded.build",
shadeIgnoredNamespaces := Set("scala"),
shadeNamespaces := Set(
"com.github.plokhotnyuk.jsoniter_scala"
),
// Let's add our sbt plugin sources to the module
unmanagedSourceDirectories in Compile ++= {
val baseDir = baseDirectory.value.getParentFile.getParentFile.getParentFile.getParentFile
Expand All @@ -77,41 +35,21 @@ val sbtBloopBuildShadedJar = project
pluginMainDir / "scala",
pluginMainDir / s"scala-sbt-${Keys.sbtBinaryVersion.value}"
)
},
packageBin in Compile := {
val namespace = shadingNamespace.?.value.getOrElse {
throw new NoSuchElementException("shadingNamespace key not set")
}

val packagedBin = packageBin.in(Compile).value
val namespaces = shadeNamespaces.value
val ignored = shadeIgnoredNamespaces.value
val classes = toShadeClasses.value
val jars = toShadeJars.value

val inputs = Keys.sources.in(Compile).value.toSet
val cacheDirectory = Keys.target.value / "shaded-inputs-cached"

import sbt.util.{FileFunction, FileInfo}
val cacheShading = FileFunction.cached(cacheDirectory, FileInfo.hash) { srcs =>
Set(
build.Shading
.createPackage(packagedBin, Nil, namespace, namespaces, ignored, classes, jars)
)
}

cacheShading(inputs).head
}
)

// Create a proxy project instead of depending on plugin directly to work around https://github.com/sbt/sbt/issues/892
val sbtBloopBuildShadedNakedJar = project
.in(file("sbt-bloop-build-shaded-naked"))
val sbtBloopBuildNakedJar = project
.in(file("sbt-bloop-build-naked"))
.settings(sharedSettings)
.settings(
name := "sbt-bloop-build-shaded-naked",
name := "sbt-bloop-build-naked",
libraryDependencies ++= List(
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "2.4.0",
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.4.0"
),
products in Compile := {
val packagedPluginJar = (packageBin in Compile in sbtBloopBuildShadedJar).value.toPath
val packagedPluginJar = (packageBin in Compile in sbtBloopBuildJar).value.toPath

// Proceed to remove META-INF, which contains sbt.autoplugins, from jar
val classDirectory = Keys.classDirectory.in(Compile).value
Expand All @@ -126,11 +64,11 @@ val sbtBloopBuildShadedNakedJar = project
val root = project
.in(file("."))
.settings(sharedSettings)
.dependsOn(sbtBloopBuildShadedNakedJar)
.dependsOn(sbtBloopBuildNakedJar)
.settings(
sbtPlugin := true,
update := update
.dependsOn(publishLocal in Compile in sbtBloopBuildShadedJar)
.dependsOn(publishLocal in Compile in sbtBloopBuildShadedNakedJar)
.dependsOn(publishLocal in Compile in sbtBloopBuildJar)
.dependsOn(publishLocal in Compile in sbtBloopBuildNakedJar)
.value
)