Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Add command line options for new inc options
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlugter committed Feb 28, 2013
1 parent e51d47b commit 60c7e4d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/main/scala/com/typesafe/zinc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.io.File
import java.net.URLClassLoader
import sbt.{ ClasspathOptions, CompileOptions, CompileSetup, LoggerReporter, ScalaInstance }
import sbt.compiler.{ AggressiveCompile, AnalyzingCompiler, CompilerCache, CompileOutput, IC }
import sbt.inc.{ Analysis, AnalysisStore, FileBasedStore, IncOptions }
import sbt.inc.{ Analysis, AnalysisStore, FileBasedStore }
import sbt.Path._
import xsbti.compile.{ JavaCompiler, GlobalsCache }
import xsbti.Logger
Expand Down Expand Up @@ -158,7 +158,6 @@ class Compiler(scalac: AnalyzingCompiler, javac: JavaCompiler) {
val skip = false
val compileSetup = new CompileSetup(compileOutput, new CompileOptions(scalacOptions, javacOptions), scalac.scalaInstance.actualVersion, compileOrder)
val analysisStore = Compiler.analysisStore(cacheFile)
val incOptions = IncOptions.Default
val analysis = aggressive.compile1(sources, cp, compileSetup, progress, analysisStore, getAnalysis, definesClass, scalac, javac, reporter, skip, globalsCache, incOptions)(log)
if (mirrorAnalysis) {
SbtAnalysis.printRelations(analysis, Some(new File(cacheFile.getPath() + ".relations")), cwd)
Expand Down
45 changes: 31 additions & 14 deletions src/main/scala/com/typesafe/zinc/Inputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package com.typesafe.zinc
import java.io.File
import java.util.{ List => JList, Map => JMap }
import sbt.compiler.IC
import sbt.inc.{ Analysis, Locate }
import sbt.inc.{ Analysis, IncOptions, Locate }
import sbt.Path._
import scala.collection.JavaConverters._
import xsbti.compile.CompileOrder
Expand All @@ -27,6 +27,7 @@ case class Inputs(
definesClass: File => String => Boolean,
javaOnly: Boolean,
compileOrder: CompileOrder,
incOptions: IncOptions,
outputRelations: Option[File],
outputProducts: Option[File],
mirrorAnalysis: Boolean)
Expand All @@ -48,6 +49,7 @@ object Inputs {
analysis.forceClean,
javaOnly,
compileOrder,
incOptions,
analysis.outputRelations,
analysis.outputProducts,
analysis.mirrorAnalysis)
Expand All @@ -67,6 +69,7 @@ object Inputs {
forceClean: Boolean,
javaOnly: Boolean,
compileOrder: CompileOrder,
incOptions: IncOptions,
outputRelations: Option[File],
outputProducts: Option[File],
mirrorAnalysis: Boolean): Inputs =
Expand All @@ -78,9 +81,10 @@ object Inputs {
val cacheFile = normalise(analysisCache.getOrElse(defaultCacheLocation(classesDirectory)))
val upstreamAnalysis = analysisCacheMap map { case (k, v) => (normalise(k), normalise(v)) }
val analysisMap = (cp map { file => (file, analysisFor(file, classes, upstreamAnalysis)) }).toMap
val incOpts = incOptions.copy(apiDumpDirectory = incOptions.apiDumpDirectory map normalise)
val printRelations = outputRelations map normalise
val printProducts = outputProducts map normalise
new Inputs(cp, srcs, classes, scalacOptions, javacOptions, cacheFile, analysisMap, forceClean, Locate.definesClass, javaOnly, compileOrder, printRelations, printProducts, mirrorAnalysis)
new Inputs(cp, srcs, classes, scalacOptions, javacOptions, cacheFile, analysisMap, forceClean, Locate.definesClass, javaOnly, compileOrder, incOpts, printRelations, printProducts, mirrorAnalysis)
}

/**
Expand All @@ -95,6 +99,7 @@ object Inputs {
analysisCache: File,
analysisMap: JMap[File, File],
compileOrder: String,
incOptions: IncOptions,
mirrorAnalysisCache: Boolean): Inputs =
inputs(
classpath.asScala,
Expand All @@ -107,6 +112,7 @@ object Inputs {
forceClean = false,
javaOnly = false,
Settings.compileOrder(compileOrder),
incOptions,
outputRelations = None,
outputProducts = None,
mirrorAnalysis = mirrorAnalysisCache
Expand Down Expand Up @@ -152,19 +158,30 @@ object Inputs {
*/
def show(inputs: Inputs, output: String => Unit): Unit = {
import inputs._

val incOpts = Seq(
"transitive step" -> incOptions.transitiveStep,
"recompile all fraction" -> incOptions.recompileAllFraction,
"debug relations" -> incOptions.relationsDebug,
"debug api" -> incOptions.apiDebug,
"api dump" -> incOptions.apiDumpDirectory
)

val values = Seq(
"classpath" -> classpath,
"sources" -> sources,
"output directory" -> classesDirectory,
"scalac options" -> scalacOptions,
"javac options" -> javacOptions,
"cache file" -> cacheFile,
"analysis map" -> analysisMap,
"force clean" -> forceClean,
"java only" -> javaOnly,
"compile order" -> compileOrder,
"output relations" -> outputRelations,
"output products" -> outputProducts)
"classpath" -> classpath,
"sources" -> sources,
"output directory" -> classesDirectory,
"scalac options" -> scalacOptions,
"javac options" -> javacOptions,
"cache file" -> cacheFile,
"analysis map" -> analysisMap,
"force clean" -> forceClean,
"java only" -> javaOnly,
"compile order" -> compileOrder,
"incremental compiler options" -> incOpts,
"output relations" -> outputRelations,
"output products" -> outputProducts)

Util.show(("Inputs", values), output)
}
}
26 changes: 26 additions & 0 deletions src/main/scala/com/typesafe/zinc/Options.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ extends ArgumentOption[Int, Context] {
}
}

class DoubleOption[Context](
val options: Seq[String],
val argument: String,
val description: String,
val action: (Context, Double) => Context)
extends ArgumentOption[Double, Context] {
def parse(arg: String): Option[Double] = {
try { Some(arg.toDouble) }
catch { case _: NumberFormatException => None }
}
}

class FractionOption[Context](
val options: Seq[String],
val argument: String,
val description: String,
val action: (Context, Double) => Context)
extends ArgumentOption[Double, Context] {
def parse(arg: String): Option[Double] = {
try {
val fraction = arg.toDouble
if (fraction < 0.0 || fraction > 1.0) None else Some(fraction)
} catch { case _: NumberFormatException => None }
}
}

class FileOption[Context](
val options: Seq[String],
val argument: String,
Expand Down
14 changes: 14 additions & 0 deletions src/main/scala/com/typesafe/zinc/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.typesafe.zinc

import java.io.File
import java.util.{ List => JList }
import sbt.inc.IncOptions
import sbt.Level
import sbt.Path._
import scala.collection.JavaConverters._
Expand All @@ -30,6 +31,7 @@ case class Settings(
javacOptions: Seq[String] = Seq.empty,
compileOrder: CompileOrder = CompileOrder.Mixed,
sbt: SbtJars = SbtJars(),
incOptions: IncOptions = IncOptions.Default,
analysis: AnalysisOptions = AnalysisOptions(),
analysisUtil: AnalysisUtil = AnalysisUtil(),
properties: Seq[String] = Seq.empty)
Expand Down Expand Up @@ -155,6 +157,13 @@ object Settings {
file( "-sbt-interface", "file", "Specify sbt interface jar", (s: Settings, f: File) => s.copy(sbt = s.sbt.copy(sbtInterface = Some(f)))),
file( "-compiler-interface", "file", "Specify compiler interface sources jar", (s: Settings, f: File) => s.copy(sbt = s.sbt.copy(compilerInterfaceSrc = Some(f)))),

header("Incremental compiler options:"),
int( "-transitive-step", "n", "Steps before transitive closure", (s: Settings, i: Int) => s.copy(incOptions = s.incOptions.copy(transitiveStep = i))),
fraction( "-recompile-all-fraction", "x", "Limit before recompiling all sources", (s: Settings, d: Double) => s.copy(incOptions = s.incOptions.copy(recompileAllFraction = d))),
boolean( "-debug-relations", "Enable debug logging of analysis relations", (s: Settings) => s.copy(incOptions = s.incOptions.copy(relationsDebug = true))),
boolean( "-debug-api", "Enable analysis API debugging", (s: Settings) => s.copy(incOptions = s.incOptions.copy(apiDebug = true))),
file( "-api-dump", "directory", "Destination for analysis API dump", (s: Settings, f: File) => s.copy(incOptions = s.incOptions.copy(apiDumpDirectory = Some(f)))),

header("Analysis options:"),
file( "-analysis-cache", "file", "Cache file for compile analysis", (s: Settings, f: File) => s.copy(analysis = s.analysis.copy(cache = Some(f)))),
fileMap( "-analysis-map", "Upstream analysis mapping (file:file,...)", (s: Settings, m: Map[File, File]) => s.copy(analysis = s.analysis.copy(cacheMap = m))),
Expand Down Expand Up @@ -247,6 +256,9 @@ object Settings {
sbtInterface = Util.normaliseOpt(cwd)(sbt.sbtInterface),
compilerInterfaceSrc = Util.normaliseOpt(cwd)(sbt.compilerInterfaceSrc)
),
incOptions = incOptions.copy(
apiDumpDirectory = Util.normaliseOpt(cwd)(incOptions.apiDumpDirectory)
),
analysis = analysis.copy(
cache = Util.normaliseOpt(cwd)(analysis.cache),
cacheMap = Util.normaliseMap(cwd)(analysis.cacheMap),
Expand All @@ -270,6 +282,8 @@ object Settings {
def boolean(opts: (String, String), desc: String, action: Settings => Settings) = new BooleanOption[Settings](Seq(opts._1, opts._2), desc, action)
def string(opt: String, arg: String, desc: String, action: (Settings, String) => Settings) = new StringOption[Settings](Seq(opt), arg, desc, action)
def int(opt: String, arg: String, desc: String, action: (Settings, Int) => Settings) = new IntOption[Settings](Seq(opt), arg, desc, action)
def double(opt: String, arg: String, desc: String, action: (Settings, Double) => Settings) = new DoubleOption[Settings](Seq(opt), arg, desc, action)
def fraction(opt: String, arg: String, desc: String, action: (Settings, Double) => Settings) = new FractionOption[Settings](Seq(opt), arg, desc, action)
def file(opt: String, arg: String, desc: String, action: (Settings, File) => Settings) = new FileOption[Settings](Seq(opt), arg, desc, action)
def path(opt: String, arg: String, desc: String, action: (Settings, Seq[File]) => Settings) = new PathOption[Settings](Seq(opt), arg, desc, action)
def path(opts: (String, String), arg: String, desc: String, action: (Settings, Seq[File]) => Settings) = new PathOption[Settings](Seq(opts._1, opts._2), arg, desc, action)
Expand Down

1 comment on commit 60c7e4d

@gkossakowski
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pvlugter: you rock! Thanks a lot, man! 👍

Please sign in to comment.