Last active
August 29, 2015 14:01
-
-
Save retronym/e16746e3ef5b554825f6 to your computer and use it in GitHub Desktop.
alternative to `set every` in SBT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% sbt 'appendScalacOptions -Ydebug' "show scalacOptions" "show test:scalacOptions" | |
[info] Loading global plugins from /Users/jason/.sbt/0.13/plugins | |
[info] Loading project definition from /Users/jason/code/scratch3/project | |
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/) | |
[info] Reapplying settings... | |
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/) | |
[info] b/*:scalacOptions | |
[info] List(-Ydebug) | |
[info] a/*:scalacOptions | |
[info] List(-Xcheckinit, -Ydebug) | |
[info] scratch3/compile:scalacOptions | |
[info] List(-Ydebug) | |
[success] Total time: 0 s, completed May 12, 2014 11:21:47 AM | |
[info] Updating {file:/Users/jason/code/scratch3/}b... | |
[info] Updating {file:/Users/jason/code/scratch3/}a... | |
[info] Resolving org.fusesource.jansi#jansi;1.4 ... | |
[info] Done updating. | |
[info] Resolving org.fusesource.jansi#jansi;1.4 ... | |
[info] Done updating. | |
[info] b/test:scalacOptions | |
[info] List(-Ydebug) | |
[info] a/test:scalacOptions | |
[info] List(-Xcheckinit, -Xprint:typer, -Ydebug) | |
[info] scratch3/test:scalacOptions | |
[info] List(-Ydebug) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val a = project.settings(scalacOptions := Seq("-Xcheckinit"), scalacOptions in Test += "-Xprint:typer") | |
val b = project.settings(scalacOptions += "-Ydebug") | |
def appendScalacOptions(s: State, args: Seq[String]): State = { | |
val extracted = Project extract s | |
def appendDistinct[A](x: Seq[A], y: Seq[A]) = x.filterNot(y.contains) ++ y | |
import extracted._ | |
val r = Project.relation(extracted.structure, true) | |
val allDefs = r._1s.toSeq | |
val projectScope = Load.projectScope(currentRef) | |
val scopes = allDefs.filter(_.key == scalacOptions.key).map(_.scope).distinct | |
val redefined = scopes.map(scope => scalacOptions in scope := appendDistinct((scalacOptions in scope).value, args)) | |
val session = extracted.session.appendRaw(redefined) | |
BuiltinCommands.reapply(session, structure, s) | |
} | |
commands += Command.args("appendScalacOptions", "<option>")(appendScalacOptions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sbt 'set every scalacOptions in Compile += "-Ydebug"' | |
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=384m; support was removed in 8.0 | |
[info] Loading global plugins from /Users/jason/.sbt/0.13/plugins | |
[info] Loading project definition from /Users/jason/code/scratch3/project | |
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/) | |
[info] Defining */*:scalacOptions, a/*:scalacOptions and 6 others. | |
[info] The new values will be used by a/compile:compile::compileInputs, a/compile:console and 28 others. | |
[info] Run `last` for details. | |
[info] Reapplying settings... | |
Cyclic reference involving | |
{file:/Users/jason/code/scratch3/}scratch3/compile:scalacOptions | |
*/*:scalacOptions | |
at sbt.Dag$Cyclic.$colon$colon(Dag.scala:68) | |
at xsbt.boot.Boot.main(Boot.scala) | |
[error] Cyclic reference involving | |
[error] {file:/Users/jason/code/scratch3/}scratch3/compile:scalacOptions | |
[error] */*:scalacOptions | |
[error] Use 'last' for the full log. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like
projectScope
is not used above.