Skip to content

Commit

Permalink
Merge pull request #689 from scalacenter/topic/bsp-sbt-build
Browse files Browse the repository at this point in the history
Don't fail in builds of single sbt plugins
  • Loading branch information
jvican authored Oct 22, 2018
2 parents 573affb + c771e2b commit 187b7ca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 =>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version"))

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version"))

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> bloopInstall

0 comments on commit 187b7ca

Please sign in to comment.