From a058a38b7b7a4b3959be085b3718ff7afc58bbb3 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 6 Mar 2015 17:33:54 +0000 Subject: [PATCH 1/2] Define Project.settings with SettingsDefinition. This maintains old, existing ways of configurating project settings, while adding the possibility to: * Define add a sequence of settings, between other individual settings * Pass a Seq[Setting[_]] to Project.settings without having to do "varargs expansion", ie. ": _*" --- main/src/main/scala/sbt/Project.scala | 2 +- .../project/settings-definition/build.sbt | 39 +++++++++++++++++++ .../sbt-test/project/settings-definition/test | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 sbt/src/sbt-test/project/settings-definition/build.sbt create mode 100644 sbt/src/sbt-test/project/settings-definition/test diff --git a/main/src/main/scala/sbt/Project.scala b/main/src/main/scala/sbt/Project.scala index c6521271f..e9ec9e074 100755 --- a/main/src/main/scala/sbt/Project.scala +++ b/main/src/main/scala/sbt/Project.scala @@ -141,7 +141,7 @@ sealed trait Project extends ProjectDefinition[ProjectReference] { def aggregate(refs: ProjectReference*): Project = copy(aggregate = (aggregate: Seq[ProjectReference]) ++ refs) /** Appends settings to the current settings sequence for this project. */ - def settings(ss: Setting[_]*): Project = copy(settings = (settings: Seq[Setting[_]]) ++ ss) + def settings(ss: SettingsDefinition*): Project = copy(settings = (settings: Seq[Setting[_]]) ++ ss.flatMap(_.settings)) @deprecated("Use settingSets method.", "0.13.5") def autoSettings(select: AddSettings*): Project = settingSets(select.toSeq: _*) diff --git a/sbt/src/sbt-test/project/settings-definition/build.sbt b/sbt/src/sbt-test/project/settings-definition/build.sbt new file mode 100644 index 000000000..0b448e961 --- /dev/null +++ b/sbt/src/sbt-test/project/settings-definition/build.sbt @@ -0,0 +1,39 @@ +// Just checking that existing ways of +// setting up projects typechecks + +val sharedSettings1 = Seq( + name := "sharedSettings1" +) + +val sharedSettings2 = Seq[Setting[_]]( + name := "sharedSettings2" +) + +lazy val root = project in file(".") + +lazy val oldSchool = (project + settings ((sharedSettings1 ++ sharedSettings2): _*) + settings ( + name := "pre seq settings" + ) + settings (sharedSettings1: _*) + settings ( + name := "mid seq settings" + ) + settings (sharedSettings2: _*) + settings ( + name := "post seq settings" + ) +) + +lazy val newSchool = (project + settings sharedSettings1 + settings sharedSettings2 + settings ( + name := "pre seq settings", + sharedSettings1, + name := "mid seq settings", + sharedSettings2, + name := "post seq settings" + ) +) diff --git a/sbt/src/sbt-test/project/settings-definition/test b/sbt/src/sbt-test/project/settings-definition/test new file mode 100644 index 000000000..4e3db8162 --- /dev/null +++ b/sbt/src/sbt-test/project/settings-definition/test @@ -0,0 +1 @@ +> about From 82c599d90787040e2f35df85e3fa1eb13ee1a24e Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 8 Mar 2015 10:33:28 +0000 Subject: [PATCH 2/2] Add notes about Project.settings enhancements. --- ...settings-with-settings-definition.markdown | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 notes/0.13.8/define-project-settings-with-settings-definition.markdown diff --git a/notes/0.13.8/define-project-settings-with-settings-definition.markdown b/notes/0.13.8/define-project-settings-with-settings-definition.markdown new file mode 100644 index 000000000..37120e2d9 --- /dev/null +++ b/notes/0.13.8/define-project-settings-with-settings-definition.markdown @@ -0,0 +1,32 @@ + [@dwijnand]: https://github.com/dwijnand + [1902]: https://github.com/sbt/sbt/pull/1902 + +### Fixes with compatibility implications + +### Improvements + +- Facilitate nicer ways of declaring project settings. See below. [#1902][1902] by [@dwijnand][@dwijnand] + +### Bug fixes + +### Nicer ways of declaring project settings + +Now a `Seq[Setting[_]]` can be passed to `Project.settings` without the needs for "varargs expansion", ie. `: _*` + +Instead of: + + lazy val foo = project settings (sharedSettings: _*) + +It is now possible to do: + + lazy val foo = project settings sharedSettings + +Also, `Seq[Setting[_]]` can be declared at the same level as individual settings in `Project.settings`, for instance: + + lazy val foo = project settings ( + sharedSettings, + version := "1.0", + someMoreSettings + ) + +[#1902][1902] by [@dwijnand][@dwijnand]