From c1e0785a1f40ce1cb68223f8273dd8dbdd1a7153 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Tue, 26 Dec 2017 16:32:29 +0900 Subject: [PATCH 1/5] delete buildinfo.BuildInfo from sbt main sbt-buildinfo plugin have `buildInfoScopedSettings(Compile)` in default. I think it is unnecessary. or we should set "buildinfoPackage in Compile" and "buildinfoObject in Compile" https://github.com/sbt/sbt-buildinfo/blob/v0.7.0/src/main/scala/sbtbuildinfo/BuildInfoPlugin.scala#L11 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index adadee53c..f859d7ee0 100644 --- a/build.sbt +++ b/build.sbt @@ -443,7 +443,6 @@ lazy val mainProj = (project in file("main")) // with the sole purpose of providing certain identifiers without qualification (with a package object) lazy val sbtProj = (project in file("sbt")) .dependsOn(mainProj, scriptedSbtProj % "test->test") - .enablePlugins(BuildInfoPlugin) .settings( testedBaseSettings, name := "sbt", @@ -453,6 +452,7 @@ lazy val sbtProj = (project in file("sbt")) javaOptions ++= Seq("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"), mimaSettings, mimaBinaryIssueFilters ++= sbtIgnoredProblems, + BuildInfoPlugin.buildInfoDefaultSettings, addBuildInfoToConfig(Test), buildInfoObject in Test := "TestBuildInfo", buildInfoKeys in Test := Seq[BuildInfoKey](fullClasspath in Compile), From c7cc52092e6379e5a98b0c239dc8dab0f389a41a Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 1 Feb 2018 13:38:00 +0000 Subject: [PATCH 2/5] Fix how fullClasspath is defined in TestBuildInfo --- build.sbt | 4 +++- sbt/src/test/scala/sbt/RunFromSourceMain.scala | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index f859d7ee0..a3d213b6a 100644 --- a/build.sbt +++ b/build.sbt @@ -455,7 +455,9 @@ lazy val sbtProj = (project in file("sbt")) BuildInfoPlugin.buildInfoDefaultSettings, addBuildInfoToConfig(Test), buildInfoObject in Test := "TestBuildInfo", - buildInfoKeys in Test := Seq[BuildInfoKey](fullClasspath in Compile), + buildInfoKeys in Test := Seq[BuildInfoKey]( + BuildInfoKey.map(fullClasspath in Compile) { case (ident, cp) => ident -> cp.files }, + ), connectInput in run in Test := true, outputStrategy in run in Test := Some(StdoutOutput), fork in Test := true, diff --git a/sbt/src/test/scala/sbt/RunFromSourceMain.scala b/sbt/src/test/scala/sbt/RunFromSourceMain.scala index 27cba48fe..6816e24c7 100644 --- a/sbt/src/test/scala/sbt/RunFromSourceMain.scala +++ b/sbt/src/test/scala/sbt/RunFromSourceMain.scala @@ -87,11 +87,7 @@ object RunFromSourceMain { Nil ) - def mainClasspath = - buildinfo.TestBuildInfo.fullClasspath.iterator - .map(s => file(s.stripPrefix("Attributed(").stripSuffix(")"))) - .toArray - + def mainClasspath = buildinfo.TestBuildInfo.fullClasspath.toArray def loader = new java.net.URLClassLoader(mainClasspath map (_.toURI.toURL), null) def entryPoint = classOf[xMain] def mainClass = classOf[xMain] From edb828a8d7c8275163d086d4954842db8b859d38 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 22 Feb 2018 16:48:09 +0000 Subject: [PATCH 3/5] Upgrade to sbt-buildinfo 0.8.0 --- build.sbt | 3 ++- project/plugins.sbt | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build.sbt b/build.sbt index a3d213b6a..abdca46ad 100644 --- a/build.sbt +++ b/build.sbt @@ -456,7 +456,8 @@ lazy val sbtProj = (project in file("sbt")) addBuildInfoToConfig(Test), buildInfoObject in Test := "TestBuildInfo", buildInfoKeys in Test := Seq[BuildInfoKey]( - BuildInfoKey.map(fullClasspath in Compile) { case (ident, cp) => ident -> cp.files }, + // WORKAROUND https://github.com/sbt/sbt-buildinfo/issues/117 + BuildInfoKey.map((fullClasspath in Compile).taskValue) { case (ident, cp) => ident -> cp.files }, ), connectInput in run in Test := true, outputStrategy in run in Test := Some(StdoutOutput), diff --git a/project/plugins.sbt b/project/plugins.sbt index 7ea70f8ea..8988c3d05 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ scalaVersion := "2.12.4" scalacOptions ++= Seq("-feature", "-language:postfixOps") -addSbtPlugin("org.scala-sbt" % "sbt-houserules" % "0.3.5") -addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.2") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "3.0.2") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0") +addSbtPlugin("org.scala-sbt" % "sbt-houserules" % "0.3.5") +addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.2") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "3.0.2") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.8.0") From 81827414806894e6a2f615c9630506dfe7478869 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 26 Jan 2018 15:29:15 +0000 Subject: [PATCH 4/5] Cleanup generateToolboxClasspath --- build.sbt | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/build.sbt b/build.sbt index abdca46ad..1c932281c 100644 --- a/build.sbt +++ b/build.sbt @@ -364,21 +364,20 @@ lazy val coreMacrosProj = (project in file("core-macros")) /* Write all the compile-time dependencies of the spores macro to a file, * in order to read it from the created Toolbox to run the neg tests. */ lazy val generateToolboxClasspath = Def.task { - val classpathAttributes = (dependencyClasspath in Compile).value - val dependenciesClasspath = - classpathAttributes.map(_.data.getAbsolutePath).mkString(":") - val scalaBinVersion = (scalaBinaryVersion in Compile).value - val targetDir = (target in Compile).value - val compiledClassesDir = targetDir / s"scala-$scalaBinVersion/classes" - val testClassesDir = targetDir / s"scala-$scalaBinVersion/test-classes" - val classpath = s"$compiledClassesDir:$testClassesDir:$dependenciesClasspath" + val mainClassesDir = (classDirectory in Compile).value + val testClassesDir = (classDirectory in Test).value + val depsClasspath = (dependencyClasspath in Compile).value + + val classpath = mainClassesDir +: testClassesDir +: (Attributed data depsClasspath) mkString ":" + val resourceDir = (resourceDirectory in Compile).value - resourceDir.mkdir() // In case it doesn't exist val toolboxTestClasspath = resourceDir / "toolbox.classpath" + IO.write(toolboxTestClasspath, classpath) - val result = List(toolboxTestClasspath.getAbsoluteFile) + streams.value.log.success("Wrote the classpath for the macro neg test suite.") - result + + List(toolboxTestClasspath) } // Fixes scope=Scope for Setting (core defined in collectionProj) to define the settings system used in build definitions @@ -387,7 +386,7 @@ lazy val mainSettingsProj = (project in file("main-settings")) .settings( testedBaseSettings, name := "Main Settings", - resourceGenerators in Compile += generateToolboxClasspath.taskValue, + resourceGenerators in Test += generateToolboxClasspath.taskValue, mimaSettings, mimaBinaryIssueFilters ++= Seq( exclude[DirectMissingMethodProblem]("sbt.Scope.display012StyleMasked"), From 27fe5a6957b751bc0d5d6d311f2f8b1fd382e4e0 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 26 Jan 2018 16:02:30 +0000 Subject: [PATCH 5/5] Re-write toolboxClasspath to use sbt-buildinfo --- .gitignore | 1 - build.sbt | 29 ++++++------------- .../src/test/scala/sbt/std/TestUtil.scala | 8 ++--- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 3996caad8..42de74605 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ target/ __pycache__ -toolbox.classpath out node_modules vscode-sbt-scala/client/server diff --git a/build.sbt b/build.sbt index 1c932281c..bb6df2c9d 100644 --- a/build.sbt +++ b/build.sbt @@ -361,32 +361,21 @@ lazy val coreMacrosProj = (project in file("core-macros")) mimaSettings, ) -/* Write all the compile-time dependencies of the spores macro to a file, - * in order to read it from the created Toolbox to run the neg tests. */ -lazy val generateToolboxClasspath = Def.task { - val mainClassesDir = (classDirectory in Compile).value - val testClassesDir = (classDirectory in Test).value - val depsClasspath = (dependencyClasspath in Compile).value - - val classpath = mainClassesDir +: testClassesDir +: (Attributed data depsClasspath) mkString ":" - - val resourceDir = (resourceDirectory in Compile).value - val toolboxTestClasspath = resourceDir / "toolbox.classpath" - - IO.write(toolboxTestClasspath, classpath) - - streams.value.log.success("Wrote the classpath for the macro neg test suite.") - - List(toolboxTestClasspath) -} - // Fixes scope=Scope for Setting (core defined in collectionProj) to define the settings system used in build definitions lazy val mainSettingsProj = (project in file("main-settings")) .dependsOn(completeProj, commandProj, stdTaskProj, coreMacrosProj) .settings( testedBaseSettings, name := "Main Settings", - resourceGenerators in Test += generateToolboxClasspath.taskValue, + BuildInfoPlugin.buildInfoDefaultSettings, + addBuildInfoToConfig(Test), + buildInfoObject in Test := "TestBuildInfo", + buildInfoKeys in Test := Seq[BuildInfoKey]( + classDirectory in Compile, + classDirectory in Test, + // WORKAROUND https://github.com/sbt/sbt-buildinfo/issues/117 + BuildInfoKey.map((dependencyClasspath in Compile).taskValue) { case (ident, cp) => ident -> cp.files }, + ), mimaSettings, mimaBinaryIssueFilters ++= Seq( exclude[DirectMissingMethodProblem]("sbt.Scope.display012StyleMasked"), diff --git a/main-settings/src/test/scala/sbt/std/TestUtil.scala b/main-settings/src/test/scala/sbt/std/TestUtil.scala index ed6f15530..df02fb29c 100644 --- a/main-settings/src/test/scala/sbt/std/TestUtil.scala +++ b/main-settings/src/test/scala/sbt/std/TestUtil.scala @@ -24,9 +24,9 @@ object TestUtil { } lazy val toolboxClasspath: String = { - val resource = getClass.getClassLoader.getResource("toolbox.classpath") - val classpathFile = scala.io.Source.fromFile(resource.toURI) - val completeSporesCoreClasspath = classpathFile.getLines.mkString - completeSporesCoreClasspath + val mainClassesDir = buildinfo.TestBuildInfo.classDirectory + val testClassesDir = buildinfo.TestBuildInfo.test_classDirectory + val depsClasspath = buildinfo.TestBuildInfo.dependencyClasspath + mainClassesDir +: testClassesDir +: depsClasspath mkString ":" } }