From ceccbf2d5ad16814f5ef89bc05fc7624b1b9c230 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 24 Jan 2016 16:50:21 -0800 Subject: [PATCH 1/2] Fixes #2415. Hide global setting fix behind sbt.globalsettingfix We are hiding a bug fix on global setting that was not importing auto imports because fixing this via sbt/sbt#2399 breaks the source compatibility: sbt/sbt#2415 I've split out the relevant portion of the scripted test into global-settings, and marked it pending. --- main/src/main/scala/sbt/Load.scala | 9 ++++++++- .../project/global-plugin/global/plugins/A.scala | 10 ---------- .../project/global-settings/global/plugins/A.scala | 11 +++++++++++ .../global/plugins/B.scala | 0 .../global/useGlobalAutoPlugin.sbt | 0 .../global/useGlobalLegacyPlugin.sbt | 0 sbt/src/sbt-test/project/global-settings/pending | 3 +++ 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 sbt/src/sbt-test/project/global-settings/global/plugins/A.scala rename sbt/src/sbt-test/project/{global-plugin => global-settings}/global/plugins/B.scala (100%) rename sbt/src/sbt-test/project/{global-plugin => global-settings}/global/useGlobalAutoPlugin.sbt (100%) rename sbt/src/sbt-test/project/{global-plugin => global-settings}/global/useGlobalLegacyPlugin.sbt (100%) create mode 100644 sbt/src/sbt-test/project/global-settings/pending diff --git a/main/src/main/scala/sbt/Load.scala b/main/src/main/scala/sbt/Load.scala index e5d8a5113..ed20fb389 100755 --- a/main/src/main/scala/sbt/Load.scala +++ b/main/src/main/scala/sbt/Load.scala @@ -71,12 +71,19 @@ object Load { if (files.isEmpty || base == globalBase) const(Nil) else buildGlobalSettings(globalBase, files, config) config.copy(injectSettings = config.injectSettings.copy(projectLoaded = compiled)) } + // We are hiding a bug fix on global setting that was not importing auto imports. + // Because fixing this via https://github.com/sbt/sbt/pull/2399 + // breaks the source compatibility: https://github.com/sbt/sbt/issues/2415 + @deprecated("Remove this when we can break source compatibility.", "0.13.10") + private[sbt] def useAutoImportInGlobal = sys.props.get("sbt.globalsettingfix") map { _.toLowerCase == "true" } getOrElse false def buildGlobalSettings(base: File, files: Seq[File], config: sbt.LoadBuildConfiguration): ClassLoader => Seq[Setting[_]] = { val eval = mkEval(data(config.globalPluginClasspath), base, defaultEvalOptions) val imports = BuildUtil.baseImports ++ - config.detectedGlobalPlugins.imports + (// when we can beak the source compat, remove this if and use config.detectedGlobalPlugins.imports + if (useAutoImportInGlobal) config.detectedGlobalPlugins.imports + else BuildUtil.importAllRoot(config.globalPluginNames)) loader => { val loaded = EvaluateConfigurations(eval, files, imports)(loader) diff --git a/sbt/src/sbt-test/project/global-plugin/global/plugins/A.scala b/sbt/src/sbt-test/project/global-plugin/global/plugins/A.scala index bbf9fc243..b75a623b5 100644 --- a/sbt/src/sbt-test/project/global-plugin/global/plugins/A.scala +++ b/sbt/src/sbt-test/project/global-plugin/global/plugins/A.scala @@ -1,15 +1,5 @@ package test -import sbt._ - object Global { val x = 3 } - -object GlobalAutoPlugin extends AutoPlugin { - - object autoImport { - lazy val globalAutoPluginSetting = settingKey[String]("A top level setting declared in a plugin.") - } - -} diff --git a/sbt/src/sbt-test/project/global-settings/global/plugins/A.scala b/sbt/src/sbt-test/project/global-settings/global/plugins/A.scala new file mode 100644 index 000000000..ee7171f10 --- /dev/null +++ b/sbt/src/sbt-test/project/global-settings/global/plugins/A.scala @@ -0,0 +1,11 @@ +package test + +import sbt._ + +object GlobalAutoPlugin extends AutoPlugin { + + object autoImport { + lazy val globalAutoPluginSetting = settingKey[String]("A top level setting declared in a plugin.") + } + +} diff --git a/sbt/src/sbt-test/project/global-plugin/global/plugins/B.scala b/sbt/src/sbt-test/project/global-settings/global/plugins/B.scala similarity index 100% rename from sbt/src/sbt-test/project/global-plugin/global/plugins/B.scala rename to sbt/src/sbt-test/project/global-settings/global/plugins/B.scala diff --git a/sbt/src/sbt-test/project/global-plugin/global/useGlobalAutoPlugin.sbt b/sbt/src/sbt-test/project/global-settings/global/useGlobalAutoPlugin.sbt similarity index 100% rename from sbt/src/sbt-test/project/global-plugin/global/useGlobalAutoPlugin.sbt rename to sbt/src/sbt-test/project/global-settings/global/useGlobalAutoPlugin.sbt diff --git a/sbt/src/sbt-test/project/global-plugin/global/useGlobalLegacyPlugin.sbt b/sbt/src/sbt-test/project/global-settings/global/useGlobalLegacyPlugin.sbt similarity index 100% rename from sbt/src/sbt-test/project/global-plugin/global/useGlobalLegacyPlugin.sbt rename to sbt/src/sbt-test/project/global-settings/global/useGlobalLegacyPlugin.sbt diff --git a/sbt/src/sbt-test/project/global-settings/pending b/sbt/src/sbt-test/project/global-settings/pending new file mode 100644 index 000000000..1b6bd3c6f --- /dev/null +++ b/sbt/src/sbt-test/project/global-settings/pending @@ -0,0 +1,3 @@ +# This test is marked pending because sbt.globalsettingfix flag is off by default +# See https://github.com/sbt/sbt/issues/2415 +> name From 9da5fc871bd183f0a2c9d6848d770ca5d0b1abf7 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Tue, 26 Jan 2016 03:05:30 +0900 Subject: [PATCH 2/2] Changed the flag name to "sbt.global.autoimport" per review. --- main/src/main/scala/sbt/Load.scala | 2 +- notes/0.13.10.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/src/main/scala/sbt/Load.scala b/main/src/main/scala/sbt/Load.scala index ed20fb389..ecd04cf07 100755 --- a/main/src/main/scala/sbt/Load.scala +++ b/main/src/main/scala/sbt/Load.scala @@ -75,7 +75,7 @@ object Load { // Because fixing this via https://github.com/sbt/sbt/pull/2399 // breaks the source compatibility: https://github.com/sbt/sbt/issues/2415 @deprecated("Remove this when we can break source compatibility.", "0.13.10") - private[sbt] def useAutoImportInGlobal = sys.props.get("sbt.globalsettingfix") map { _.toLowerCase == "true" } getOrElse false + private[sbt] def useAutoImportInGlobal = sys.props.get("sbt.global.autoimport") map { _.toLowerCase == "true" } getOrElse false def buildGlobalSettings(base: File, files: Seq[File], config: sbt.LoadBuildConfiguration): ClassLoader => Seq[Setting[_]] = { val eval = mkEval(data(config.globalPluginClasspath), base, defaultEvalOptions) diff --git a/notes/0.13.10.markdown b/notes/0.13.10.markdown index 572578a7a..eb252674d 100644 --- a/notes/0.13.10.markdown +++ b/notes/0.13.10.markdown @@ -95,6 +95,7 @@ - Fixes update option's `withLatestSnapshots` so it handles modules without an artifact. This flag will be enabled by default. [#1514][1514]/[#1616][1616]/[#2313][2313] by [@eed3si9n][@eed3si9n] - No longer passes `-J` options to the local Java compiler. [#1968][1968]/[#2272][2272] by [@Duhemm][@Duhemm] +- Fixes auto imports for auto plugins in global configuration files. Because this is *not* source compatible with 0.13.x, the fix is enabled only when `sbt.global.autoimport` flag is `true`. [#2120][2120]/[#2399][2399] by [@timcharper][@timcharper] ### Improvements @@ -148,7 +149,6 @@ - Fixes launcher configuration to add `sbt-ivy-snapshots` repository to resolve nightly builds. [@eed3si9n][@eed3si9n] - Fixes performance issues during tree traversal in the incremental compiler. [#2343][2343] by [@adriaanm][@adriaanm] - Fixes the tracking of self types and F-bounded existential types in the incremental compiler. [#2343][2343] by [@adriaanm][@adriaanm] -- Fixes autoImports for AutoPlugins for global configuration files. [#2120][2120]/[#2399][2399] by [@timcharper][@timcharper] ### Configurable Scala compiler bridge