diff --git a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala index 1ea859b995..37355def74 100644 --- a/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala +++ b/integrations/sbt-bloop/src/main/scala/bloop/integrations/sbt/SbtBloop.scala @@ -77,6 +77,7 @@ object BloopDefaults { import Compat._ import sbt.{Task, Defaults, State} + private lazy val cwd: String = System.getProperty("user.dir") lazy val globalSettings: Seq[Def.Setting[_]] = List( BloopKeys.bloopExportJarClassifiers := None, BloopKeys.bloopInstall := bloopInstall.value, @@ -87,7 +88,12 @@ object BloopDefaults { val bloopClassifiers = BloopKeys.bloopExportJarClassifiers.in(ThisBuild).value (if (bloopClassifiers.isEmpty) old else bloopClassifiers.get).toList }, - BloopKeys.bloopIsMetaBuild := Keys.sbtPlugin.in(LocalRootProject).value, + BloopKeys.bloopIsMetaBuild := { + val buildStructure = Keys.loadedBuild.value + val baseDirectory = new File(buildStructure.root) + val isMetaBuild = Keys.sbtPlugin.in(LocalRootProject).value + isMetaBuild && baseDirectory.getAbsolutePath != cwd + }, Keys.onLoad := { val oldOnLoad = Keys.onLoad.value oldOnLoad.andThen { state => @@ -775,8 +781,8 @@ object BloopDefaults { } private final val allJson = sbt.GlobFilter("*.json") - private final val removeStaleProjects = { allConfigDirs: Set[File] => - { (s: State, generatedFiles: Set[Option[File]]) => + private final val removeStaleProjects = { + allConfigDirs: Set[File] => { (s: State, generatedFiles: Set[Option[File]]) => val logger = s.globalLogging.full val allConfigs = allConfigDirs.flatMap(configDir => sbt.PathFinder(configDir).*(allJson).get) @@ -845,8 +851,7 @@ object BloopDefaults { } val generatedTask = productDirs.toList.join.map(_.flatten.distinct).flatMap { a => - bloopProductDirs.toList.join.map(_.flatten.distinct).map { b => - a.zip(b) + bloopProductDirs.toList.join.map(_.flatten.distinct).map { b => a.zip(b) } } @@ -889,8 +894,7 @@ object BloopDefaults { val oldResourceDir = Keys.resourceManaged.in(configKey).value val newResourceDir = BloopKeys.bloopResourceManaged.in(configKey).value / Defaults.nameForSrc(configName) - oldUnmanagedResourceDirs.map { dir => - if (dir == oldResourceDir) newResourceDir else dir + oldUnmanagedResourceDirs.map { dir => if (dir == oldResourceDir) newResourceDir else dir } } } diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/build.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/build.sbt new file mode 100644 index 0000000000..b8651951b5 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/build.sbt @@ -0,0 +1,20 @@ +name := "sbt-plugin-foobar" +sbtPlugin := true + +import java.nio.file.Files + +val checkMetaBuildInfo = taskKey[Unit]("Check sbt meta build info is not generated") +checkMetaBuildInfo in ThisBuild := { + def readBareFile(p: java.nio.file.Path): String = + new String(Files.readAllBytes(p)).replaceAll("\\s", "") + + def check(f: File): Unit = { + val metaContents = readBareFile(f.toPath) + assert(metaContents.contains("\"autoImports\":[\""), "Missing auto imports.") + assert(metaContents.contains("\"sbtVersion\":\""), "Missing sbt version.") + } + + val bloopMetaDir = Keys.baseDirectory.value./("project")./(".bloop") + val metaBuildConfig = bloopMetaDir./("sbt-plugin-build.json") + check(metaBuildConfig) +} diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/project/plugins.sbt new file mode 100644 index 0000000000..a4a378eb12 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/project/plugins.sbt @@ -0,0 +1,2 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version")) + diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/project/project/plugins.sbt b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/project/project/plugins.sbt new file mode 100644 index 0000000000..a4a378eb12 --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/project/project/plugins.sbt @@ -0,0 +1,2 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version")) + diff --git a/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/test b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/test new file mode 100644 index 0000000000..d27e47c7ff --- /dev/null +++ b/integrations/sbt-bloop/src/sbt-test/sbt-bloop/sbt-plugin-build/test @@ -0,0 +1 @@ +> bloopInstall