如何动态调用SBT InputTask?

马丁·塞内(Martin Senne)

我想创建一个新的自定义InputTasktestOnlyCustom

  • testOnly用与给testOnlyCustom相同的参数调用
  • 可能是基于SBT设置(调用testOnly之前调用了condition另一个任务(我们称之为pre在这里,我必须强制执行“顺序”执行。

因此:

If condition is true
  testOnlyCustom com.dummy.TestSuite calls
    pre and then
    testOnly com.dummy.TestSuite

If condition is false
  testOnlyCustom com.dummy.TestSuite calls
    testOnly com.dummy.TestSuite

虽然我能够实现溶液与testCustom参照pretest(因而具有无参数),我不能够解决该问题testOnlyCustom,作为InputTask使用的

这是我的代码:

import sbt._
import sbt.Keys._
import sbt.Def._
import sbtsequential.Plugin._


object Simple extends sbt.Plugin {

  import SimpleKeys._

  object SimpleKeys {
    lazy val condition = SettingKey[Boolean]("mode", "The mode.")

    lazy val pre = TaskKey[Unit]("test-with-pre", "Do some pre step.")

    lazy val testWithPre = TaskKey[Unit]("test-with-pre", "Run pre task beforehand")
    lazy val testCustom = TaskKey[Unit]("test-custom", "Run pre (depending on condition) and then test.")

    lazy val testOnlyWithPre = InputKey[Unit]("test-only-with-pre", "Run selected tests (like test-only in SBT) with pre executed before.")
    lazy val testOnlyCustom = InputKey[Unit]("test-only-configured", "Run pre (depending on condition) and then call test-only.")
  }

  lazy val baseSettings: Seq[sbt.Def.Setting[_]] = Seq(

    // this is working
    testWithPre := test.value,
    testWithPre <<= testWithPre.dependsOn( pre ),

    testCustom := Def.taskDyn {
      val c = condition.value

      if (c) {
        testWithPre
      } else {
        test
      }
    }.value,


    //
    // this is the part, where my question focuses on
    //
    testOnlyWithPre := testOnly.evaluated,
    testOnlyWithPre <<= testOnlyWithPre.dependsOn( pre ),

    // is this the correct approach?
    testOnlyCustom := Def.inputTaskDyn {
      // ???????????????????????????????
      Def.task()
    }.evaluated
  )

  lazy val testSimpleSettings: Seq[sbt.Def.Setting[_]] = baseSettings
}
  1. inputTaskDyn路要走吗?到底是什么?我刚刚选择了它,因为它似乎是的动态版本InputTasks不幸的是,上的文档很少inputTaskDyn
  2. 是否可以dependsOn像我一样通过强制“顺序”执行我已经看到SBT 0.13.8包含了Def.sequantial但这似乎不适用于InputTasks吗?
  3. 如何将A转换InputTask为A Task(与taskDyn / inputTaskDyn一起使用),但仍然坚持evaluated使用显式解析器?还是有一种重用testOnly解析器的方法?
  4. 可能有人说明多了几分.evaluated.parsedInputTask到底是做InputTask.parse什么的?

如果有人可以提供可行的解决方案,那就太好了!

提前谢谢了

马丁

马丁·塞内(Martin Senne)

补充评论

首先,OlegYch_在Freenode#sbt上指出,随着SBT 0.13.9的Inputtask出现,可以通过以下命令执行s

def runInputTask[T](key: InputKey[T], input: String, state: State): (State, T)

sbt.Extracted.scala

其次,testOnly解析器可以通过进行重用sbt.Defaults#inputTests

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章