Created
September 28, 2018 21:06
-
-
Save retronym/7c098c0eab4880402a524e7d38c08615 to your computer and use it in GitHub Desktop.
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
package io.github.retronym | |
import sbt._ | |
import Keys._ | |
object SbtArgsFilePlugin extends AutoPlugin { | |
override def trigger = allRequirements | |
override def requires = sbt.plugins.JvmPlugin | |
val argsFileContents = taskKey[String]("Contents of file suitable for `scalac @args.txt`") | |
val argsFile = taskKey[Unit]("Write compiler command line into an args file suitable for `scalac @target/compile.args`") | |
override lazy val projectSettings = List(Compile, Test).flatMap(c => inConfig(c)(Seq( | |
argsFileContents := { | |
val sourcesValue = sources.value | |
val depdependencyClasspathValue = dependencyClasspath.value | |
val cp = if (depdependencyClasspathValue.isEmpty) Nil else ("-classpath" :: depdependencyClasspathValue.map(_.data.toString).mkString(":") :: Nil) | |
val result = (scalacOptions.value.toList ::: List("-d", classDirectory.value) ::: cp ::: sourcesValue.distinct.toList).mkString("\n") | |
if (sourcesValue.isEmpty) "" else result | |
}, | |
argsFile := { | |
val f = target.value / (c.name + ".args") | |
val contents = argsFileContents.value | |
val log = streams.value.log | |
if (!contents.isEmpty) { | |
IO.write(f, contents) | |
log.info("Wrote compiler comand line to: " + f.getAbsolutePath) | |
} | |
} | |
))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment