Próbuję tymczasowo pominąć zadanie kompilacji podczas wykonywania zadania package
z poziomu polecenia(zdefiniowanego w pisanej przeze mnie wtyczce sbt). Jestem w stanie przejść wszystkie kompiluje umieszczając ustawienie skip
na zadaniu compile
, ale powoduje, że wszystkie compile
zadania do pominięcia:Jak tymczasowo pominąć uruchamianie zadania kompilacji w niestandardowym poleceniu sbt?
object MyPlugin extends Plugin {
override lazy val settings = Seq(
(skip in compile) := true
)
...
}
Co potrzebne jest tylko pominąć compile
podczas uruchamiania mojego polecenia quick-install
. Czy istnieje sposób tymczasowego zmodyfikowania ustawienia lub jego zakresu tylko dla mojego polecenia szybkiej instalacji?
Próbowałem transformację ustawień (w oparciu o https://github.com/harrah/xsbt/wiki/Advanced-Command-Example), który powinien zastąpić wszystkie wystąpienia skip := false
z skip := true
, ale to nie ma żadnego wpływu (tj kompiluje nadal występować po przekształceniu):
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)
...
}
Każdy pomysł, czego mi brakuje i/lub lepszy sposób na zrobienie tego?
Edit:
ustawienie Skip to zadanie, więc łatwo naprawić było:
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
}
}
nie jestem przekonany, że jest to najbardziej niezawodne rozwiązanie, ale wydaje się, aby pracować na co Potrzebowałem.