diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 03212aa94..072a7595d 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -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 diff --git a/main/src/main/scala/sbt/internal/nio/CheckBuildSources.scala b/main/src/main/scala/sbt/internal/nio/CheckBuildSources.scala index 54a0fe752..782975b75 100644 --- a/main/src/main/scala/sbt/internal/nio/CheckBuildSources.scala +++ b/main/src/main/scala/sbt/internal/nio/CheckBuildSources.scala @@ -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 } } diff --git a/sbt/src/sbt-test/nio/reload/.scalafmt.conf b/sbt/src/sbt-test/nio/reload/.scalafmt.conf new file mode 100644 index 000000000..8a81e8505 --- /dev/null +++ b/sbt/src/sbt-test/nio/reload/.scalafmt.conf @@ -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 diff --git a/sbt/src/sbt-test/nio/reload/build.sbt b/sbt/src/sbt-test/nio/reload/build.sbt index c143ba056..c5e320e75 100644 --- a/sbt/src/sbt-test/nio/reload/build.sbt +++ b/sbt/src/sbt-test/nio/reload/build.sbt @@ -11,3 +11,5 @@ exists := { } Global / onChangedBuildSource := ReloadOnSourceChanges + +val sub = project diff --git a/sbt/src/sbt-test/nio/reload/changes/ScalafmtVersion.scala b/sbt/src/sbt-test/nio/reload/changes/ScalafmtVersion.scala new file mode 100644 index 000000000..42ad05178 --- /dev/null +++ b/sbt/src/sbt-test/nio/reload/changes/ScalafmtVersion.scala @@ -0,0 +1,3 @@ +object ScalafmtVersion { + val value = "2.0.4" +} \ No newline at end of file diff --git a/sbt/src/sbt-test/nio/reload/changes/broken.sbt b/sbt/src/sbt-test/nio/reload/changes/broken.sbt index 57e15cd57..5210c3db2 100644 --- a/sbt/src/sbt-test/nio/reload/changes/broken.sbt +++ b/sbt/src/sbt-test/nio/reload/changes/broken.sbt @@ -8,3 +8,5 @@ exists := { } Global / onChangedBuildSource := ReloadOnSourceChanges + +val sub = project diff --git a/sbt/src/sbt-test/nio/reload/changes/sub.sbt b/sbt/src/sbt-test/nio/reload/changes/sub.sbt new file mode 100644 index 000000000..f0ce2b852 --- /dev/null +++ b/sbt/src/sbt-test/nio/reload/changes/sub.sbt @@ -0,0 +1 @@ +libraryDependencies += "org.scala-sbt" % "sbt" % "1.3.0" \ No newline at end of file diff --git a/sbt/src/sbt-test/nio/reload/changes/working.sbt b/sbt/src/sbt-test/nio/reload/changes/working.sbt index c143ba056..c5e320e75 100644 --- a/sbt/src/sbt-test/nio/reload/changes/working.sbt +++ b/sbt/src/sbt-test/nio/reload/changes/working.sbt @@ -11,3 +11,5 @@ exists := { } Global / onChangedBuildSource := ReloadOnSourceChanges + +val sub = project diff --git a/sbt/src/sbt-test/nio/reload/project/plugins.sbt b/sbt/src/sbt-test/nio/reload/project/plugins.sbt new file mode 100644 index 000000000..99c853f12 --- /dev/null +++ b/sbt/src/sbt-test/nio/reload/project/plugins.sbt @@ -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 +} diff --git a/sbt/src/sbt-test/nio/reload/project/project/ScalafmtVersion.scala b/sbt/src/sbt-test/nio/reload/project/project/ScalafmtVersion.scala new file mode 100644 index 000000000..d21e33494 --- /dev/null +++ b/sbt/src/sbt-test/nio/reload/project/project/ScalafmtVersion.scala @@ -0,0 +1,3 @@ +object ScalafmtVersion { + val value = "2.0.3" +} \ No newline at end of file diff --git a/sbt/src/sbt-test/nio/reload/sub/build.sbt b/sbt/src/sbt-test/nio/reload/sub/build.sbt new file mode 100644 index 000000000..e69de29bb diff --git a/sbt/src/sbt-test/nio/reload/sub/src/main/scala/Test.scala b/sbt/src/sbt-test/nio/reload/sub/src/main/scala/Test.scala new file mode 100644 index 000000000..405e020be --- /dev/null +++ b/sbt/src/sbt-test/nio/reload/sub/src/main/scala/Test.scala @@ -0,0 +1,3 @@ +object Test { + val x = sbt.Keys +} \ No newline at end of file diff --git a/sbt/src/sbt-test/nio/reload/test b/sbt/src/sbt-test/nio/reload/test index abfe64f5e..26ef1a9ff 100644 --- a/sbt/src/sbt-test/nio/reload/test +++ b/sbt/src/sbt-test/nio/reload/test @@ -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