Skip to content

Instantly share code, notes, and snippets.

@retronym
Created September 28, 2018 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/7c098c0eab4880402a524e7d38c08615 to your computer and use it in GitHub Desktop.
Save retronym/7c098c0eab4880402a524e7d38c08615 to your computer and use it in GitHub Desktop.
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