From 81ce14d58cfa8326f5e319fe7430ef4a3fe8dbd5 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Thu, 25 Apr 2019 15:56:08 -0700 Subject: [PATCH] Allow calling TaskKey.previous in input tasks I discovered that it wasn't possible to call .previous in an input task. While I understand why you can't call .previous on an InputKey, I think it makes sense to allow calling .previous on a TaskKey within an input task. --- main-settings/src/main/scala/sbt/std/TaskMacro.scala | 1 + .../sbt-test/actions/previous-in-input-task/build.sbt | 10 ++++++++++ sbt/src/sbt-test/actions/previous-in-input-task/test | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 sbt/src/sbt-test/actions/previous-in-input-task/build.sbt create mode 100644 sbt/src/sbt-test/actions/previous-in-input-task/test diff --git a/main-settings/src/main/scala/sbt/std/TaskMacro.scala b/main-settings/src/main/scala/sbt/std/TaskMacro.scala index 650914c7a..198b4adb1 100644 --- a/main-settings/src/main/scala/sbt/std/TaskMacro.scala +++ b/main-settings/src/main/scala/sbt/std/TaskMacro.scala @@ -450,6 +450,7 @@ object TaskMacro { def expand(nme: String, tpe: Type, tree: Tree): Converted[c.type] = nme match { case WrapInitTaskName => Converted.Success(wrapInitTask(tree)(c.WeakTypeTag(tpe))) + case WrapPreviousName => Converted.Success(wrapInitTask(tree)(c.WeakTypeTag(tpe))) case ParserInput.WrapInitName => Converted.Success(wrapInitParser(tree)(c.WeakTypeTag(tpe))) case WrapInitInputName => Converted.Success(wrapInitInput(tree)(c.WeakTypeTag(tpe))) case WrapInputName => Converted.Success(wrapInput(tree)(c.WeakTypeTag(tpe))) diff --git a/sbt/src/sbt-test/actions/previous-in-input-task/build.sbt b/sbt/src/sbt-test/actions/previous-in-input-task/build.sbt new file mode 100644 index 000000000..a7e169d7e --- /dev/null +++ b/sbt/src/sbt-test/actions/previous-in-input-task/build.sbt @@ -0,0 +1,10 @@ +import sjsonnew.BasicJsonProtocol._ + +val cacheTask = taskKey[Int]("task") +cacheTask := 1 + +val checkTask = inputKey[Unit]("validate that the correct value is set by cacheTask") +checkTask := { + val expected = Def.spaceDelimited("").parsed.head.toInt + assert(cacheTask.previous.getOrElse(0) == expected) +} \ No newline at end of file diff --git a/sbt/src/sbt-test/actions/previous-in-input-task/test b/sbt/src/sbt-test/actions/previous-in-input-task/test new file mode 100644 index 000000000..1b7969eea --- /dev/null +++ b/sbt/src/sbt-test/actions/previous-in-input-task/test @@ -0,0 +1,5 @@ +> checkTask 0 + +> cacheTask + +> checkTask 1 \ No newline at end of file