Merge pull request #5086 from eatkins/build-sources

Monitor project build sources
This commit is contained in:
eugene yokota 2019-09-17 00:23:29 -04:00 committed by GitHub
commit d119818656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 79 additions and 11 deletions

View File

@ -371,13 +371,16 @@ object Defaults extends BuildCommon {
}).value
)
def paths = Seq(
// Appended to JvmPlugin.projectSettings
def paths: Seq[Setting[_]] = Seq(
baseDirectory := thisProject.value.base,
target := baseDirectory.value / "target",
historyPath := (historyPath or target(t => Option(t / ".history"))).value,
sourceDirectory := baseDirectory.value / "src",
sourceManaged := crossTarget.value / "src_managed",
resourceManaged := crossTarget.value / "resource_managed"
resourceManaged := crossTarget.value / "resource_managed",
// Adds subproject build.sbt files to the global list of build files to monitor
Scope.Global / checkBuildSources / fileInputs += baseDirectory.value.toGlob / "*.sbt"
)
lazy val configPaths = sourceConfigPaths ++ resourceConfigPaths ++ outputConfigPaths

View File

@ -13,7 +13,10 @@ import sbt.SlashSyntax0._
import sbt.io.syntax._
import sbt.nio.FileChanges
import sbt.nio.Keys._
import sbt.nio.file.{ Glob, RecursiveGlob }
import sbt.nio.file.{ Glob, ** }
import sbt.nio.file.syntax._
import scala.annotation.tailrec
private[sbt] object CheckBuildSources {
private[sbt] def needReloadImpl: Def.Initialize[Task[StateTransform]] = Def.task {
@ -60,15 +63,20 @@ private[sbt] object CheckBuildSources {
private[sbt] def buildSourceFileInputs: Def.Initialize[Seq[Glob]] = Def.setting {
if (onChangedBuildSource.value != IgnoreSourceChanges) {
val baseDir = (LocalRootProject / baseDirectory).value
val sourceFilter = "*.{sbt,scala,java}"
val projectDir = baseDir / "project"
Seq(
Glob(baseDir, "*.sbt"),
Glob(projectDir, sourceFilter),
// We only want to recursively look in source because otherwise we have to search
// the project target directories which is expensive.
Glob(projectDir / "src", RecursiveGlob / sourceFilter),
)
@tailrec
def projectGlobs(projectDir: File, globs: Seq[Glob]): Seq[Glob] = {
val glob = projectDir.toGlob
val base = Seq(
glob / "*.{sbt,scala,java}",
// We only want to recursively look in source because otherwise we have to search
// the project target directories which is expensive.
glob / "src" / ** / "*.{scala,java}"
)
val nextLevel = projectDir / "project"
if (nextLevel.exists) projectGlobs(nextLevel, base) else base
}
projectGlobs(projectDir, baseDir.toGlob / "*.sbt" :: Nil)
} else Nil
}
}

View File

@ -0,0 +1,21 @@
version = 2.0.0
maxColumn = 100
project.git = true
project.excludeFilters = [ "\\Wsbt-test\\W", "\\Winput_sources\\W", "\\Wcontraband-scala\\W" ]
# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings = JavaDoc
# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true
# This is more idiomatic Scala.
# http://docs.scala-lang.org/style/indentation.html#methods-with-numerous-arguments
align.openParenCallSite = false
align.openParenDefnSite = false
# For better code clarity
danglingParentheses = true
trailingCommas = preserve

View File

@ -11,3 +11,5 @@ exists := {
}
Global / onChangedBuildSource := ReloadOnSourceChanges
val sub = project

View File

@ -0,0 +1,3 @@
object ScalafmtVersion {
val value = "2.0.4"
}

View File

@ -8,3 +8,5 @@ exists := {
}
Global / onChangedBuildSource := ReloadOnSourceChanges
val sub = project

View File

@ -0,0 +1 @@
libraryDependencies += "org.scala-sbt" % "sbt" % "1.3.0"

View File

@ -11,3 +11,5 @@ exists := {
}
Global / onChangedBuildSource := ReloadOnSourceChanges
val sub = project

View File

@ -0,0 +1,8 @@
libraryDependencies ++= {
if (ScalafmtVersion.value == "2.0.4") {
val sbtV = (sbtBinaryVersion in pluginCrossBuild).value
val scalaV = (scalaBinaryVersion in update).value
val dep = "org.scalameta" % "sbt-scalafmt" % ScalafmtVersion.value
sbt.Defaults.sbtPluginExtra(dep, sbtV, scalaV) :: Nil
} else Nil
}

View File

@ -0,0 +1,3 @@
object ScalafmtVersion {
val value = "2.0.3"
}

View File

@ -0,0 +1,3 @@
object Test {
val x = sbt.Keys
}

View File

@ -17,3 +17,15 @@ $ copy-file changes/working.sbt build.sbt
> foo foo; reload
> exists foo
-> compile
$ copy-file changes/sub.sbt sub/build.sbt
> compile
-> scalafmt
$ copy-file changes/ScalafmtVersion.scala project/project/ScalafmtVersion.scala
> scalafmt