Skip to content

Commit

Permalink
Stop shading stuff in sbt-bloop plugins
Browse files Browse the repository at this point in the history
They mainly depend on bloop-config and jsoniter-scala, which should be
stable enough.
  • Loading branch information
alexarchambault committed Jul 5, 2022
1 parent 690e4bf commit 1650ed6
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 124 deletions.
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
38 changes: 2 additions & 36 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -664,40 +664,13 @@ def shadeSbtSettingsForModule(
)
}

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 +679,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 +908,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
)

0 comments on commit 1650ed6

Please sign in to comment.