Skip to content

Commit 11a55b4

Browse files
authored
Merge pull request scala#6800 from dwijnand/add-testJDeps
Enforce library/reflect restriction to compat1 profile
2 parents 1b808c3 + 7ddfd3c commit 11a55b4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ lazy val root: Project = (project in file("."))
805805
state
806806
},
807807

808+
testJDeps := TestJDeps.testJDepsImpl.value,
809+
808810
testAll := {
809811
val results = ScriptCommands.sequence[(Result[Unit], String)](List(
810812
(Keys.test in Test in junit).result map (_ -> "junit/test"),
@@ -819,6 +821,7 @@ lazy val root: Project = (project in file("."))
819821
(Keys.test in Test in osgiTestEclipse).result map (_ -> "osgiTestEclipse/test"),
820822
(mimaReportBinaryIssues in library).result map (_ -> "library/mimaReportBinaryIssues"),
821823
(mimaReportBinaryIssues in reflect).result map (_ -> "reflect/mimaReportBinaryIssues"),
824+
testJDeps.result map (_ -> "testJDeps"),
822825
(compile in Compile in bench).map(_ => ()).result map (_ -> "bench/compile"),
823826
Def.task(()).dependsOn( // Run these in parallel:
824827
doc in Compile in library,
@@ -939,6 +942,8 @@ lazy val mkQuick = taskKey[File]("Generate a full build, including scripts, in b
939942
lazy val mkPack = taskKey[File]("Generate a full build, including scripts, in build/pack")
940943
lazy val testAll = taskKey[Unit]("Run all test tasks sequentially")
941944

945+
val testJDeps = taskKey[Unit]("Run jdeps to check dependencies")
946+
942947
// Defining these settings is somewhat redundant as we also redefine settings that depend on them.
943948
// However, IntelliJ's project import works better when these are set correctly.
944949
def clearSourceAndResourceDirectories = Seq(Compile, Test).flatMap(config => inConfig(config)(Seq(

project/TestJDeps.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package scala.build
2+
3+
import sbt._, Keys._
4+
5+
object TestJDeps {
6+
val testJDepsImpl: Def.Initialize[Task[Unit]] = Def.task {
7+
val libraryJar = (packageBin in Compile in LocalProject("library")).value
8+
val reflectJar = (packageBin in Compile in LocalProject("reflect")).value
9+
10+
// jdeps -s -P build/pack/lib/scala-{library,reflect}.jar | grep -v build/pack | perl -pe 's/.*\((.*)\)$/$1/' | sort -u
11+
val jdepsOut = Process("jdeps", Seq("-s", "-P", libraryJar.getPath, reflectJar.getPath)).lines
12+
13+
val profilePart = ".*\\((.*)\\)$".r
14+
val profiles = jdepsOut.collect {
15+
case profilePart(profile) => profile
16+
}.toSet
17+
18+
if (profiles != Set("compact1"))
19+
throw new RuntimeException(jdepsOut.mkString("Detected dependency outside of compact1:\n", "\n", ""))
20+
}
21+
}

0 commit comments

Comments
 (0)