2012-04-18 17 views
6

packageタスクをquick-installコマンド(私が書いているsbtプラグインで定義)の中から実行しているときに、コンパイルタスクを一時的にスキップしようとしています。私はcompile作業にskip設定を置くことによって、すべてのコンパイルをスキップすることができるよ、それはすべてのcompileタスクはスキップされます:コンパイルタスクの実行をカスタムsbtコマンドで一時的にスキップするにはどうすればよいですか?

object MyPlugin extends Plugin { 
    override lazy val settings = Seq(
     (skip in compile) := true 
    ) 
    ... 
    } 

私はquick-installコマンドを実行している場合にのみcompileをスキップすることで必要なもの。一時的に設定を変更したり、クイックインストールコマンドだけに範囲を設定する方法はありますか? (つまり、コンパイルまだ変換した後に発生する)

は、私はそれがskip := trueskip := falseのすべてのインスタンスを置き換える必要があり、(https://github.com/harrah/xsbt/wiki/Advanced-Command-Exampleに基づく)設定変換を試みたが、それは何の効果もありません。

object SbtQuickInstallPlugin extends Plugin { 
    private lazy val installCommand = Command.args("quick-install", "quick install that skips compile step")(doCommand(Configurations.Compile)) 

    override lazy val settings = Seq(
    commands ++= Seq(installCommand), 
    (Keys.skip in compile) := false // by default, don't skip compiles 
) 

    def doCommand(configs: Configuration*)(state: State, args: Seq[String]): State = { 
    val extracted = Project.extract(state) 
    import extracted._ 
    val oldStructure = structure 

    val transformedSettings = session.mergeSettings.map(
     s => s.key.key match { 
     case skip.key => { skip in s.key.scope := true } // skip compiles 
     case _ => s 
     } 
    ) 

    // apply transformed settings (in theory) 
    val newStructure = Load.reapply(transformedSettings, oldStructure) 
    Project.setProject(session, newStructure, state) 

    ... 
} 

私には何が欠けているのか、これを行うにはよりよい方法がありますか?

編集:

スキップの設定がタスクで、そう簡単に修正はしました:

object SbtQuickInstallPlugin extends Plugin { 
    private lazy val installCommand = Command.args("quick-install", "quick install that skips compile step")(doCommand(Configurations.Compile)) 

    private var shouldSkipCompile = false // by default, don't skip compiles 

    override lazy val settings = Seq(
    commands ++= Seq(installCommand), 
    (Keys.skip in compile) := shouldSkipCompile 
) 

    def doCommand(configs: Configuration*)(state: State, args: Seq[String]): State = { 
    shouldSkipCompile = true // start skipping compiles 

    ... // do stuff that would normally trigger a compile such as running the packageBin task 

    shouldSkipCompile = false // stop skipping compiles 
    } 
} 

私はこれが最も堅牢なソリューションです確信していないが、何のために働くように見えます必要だった。

答えて

0
object SbtQuickInstallPlugin extends Plugin { 
    private lazy val installCommand = Command.args("quick-install", "quick install that skips compile step")(doCommand(Configurations.Compile)) 

    private var shouldSkipCompile = false // by default, don't skip compiles 

    override lazy val settings = Seq(
    commands ++= Seq(installCommand), 
    (Keys.skip in compile) := shouldSkipCompile 
) 

    def doCommand(configs: Configuration*)(state: State, args: Seq[String]): State = { 
    shouldSkipCompile = true // start skipping compiles 

    ... // do stuff that would normally trigger a compile such as running the packageBin task 

    shouldSkipCompile = false // stop skipping compiles 
    } 
} 

これでいいですか?

関連する問題