From 108ecf59fad3830fc0d0d1ef78c759f47dd17775 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 17 Sep 2010 22:17:10 -0400 Subject: [PATCH] a demo Project type multi-project incremental compilation and dependency management 'update' currently runs on every compile built-in 'compile' command shadows 'compile' action --- main/DefaultProject.scala | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 main/DefaultProject.scala diff --git a/main/DefaultProject.scala b/main/DefaultProject.scala new file mode 100644 index 000000000..555e72631 --- /dev/null +++ b/main/DefaultProject.scala @@ -0,0 +1,63 @@ +/* sbt -- Simple Build Tool + * Copyright 2010 Mark Harrah + */ +package sbt + + import std._ + import inc.Analysis + import TaskExtra._ + import Configurations.{Compile => CompileConfig, Test => TestConfig} + import ClasspathProject._ + + import java.io.File + +abstract class DefaultProject extends TestProject with MultiClasspathProject with ReflectiveClasspathProject +{ + def javacOptions: Seq[String] = Nil + def scalacOptions: Seq[String] = Nil + + def outputDirectory = "target": Path + def cacheDirectory = outputDirectory / "cache" + + def classesDirectory(configuration: Configuration): File = + configuration match { + case CompileConfig => outputDirectory / "classes" + case x => outputDirectory / (x.toString + "-classes") + } + + // TODO: resources, jars, test classes + lazy val products: Classpath = + TaskMap { (conf: Configuration) => + conf match { + case CompileConfig => analyzed(compile, compileInputs) named(name + "/analyzed") map { _ :: Nil } named(name + "/products") + case x => error("Unknown compilation configuration: " + x) + } + } + + def sourceFilter: FileFilter = "*.java" | "*.scala" + + def compileTask(inputs: Task[Compile.Inputs]): Task[Analysis] = inputs map Compile.apply + + def compileInputsTask(configuration: Configuration, base: PathFinder): Task[Compile.Inputs] = + { + val dep = dependencyClasspath(configuration) + val prod: Task[Seq[Attributed[File]]] = (configuration.extendsConfigs map products).join.map(_.flatten) + (dep, prod) map { case (cp :+: prodcp :+: HNil) => + val log = ConsoleLogger() + val compilers = Compile.compilers(info.configuration, log) + val javaSrc = base / "java" + val scalaSrc = base / "scala" + val out = "target" / compilers.scalac.scalaInstance.actualVersion + + val sources = ((javaSrc +++ scalaSrc) ** sourceFilter) +++ (if(configuration == Compile) (".": Path) * sourceFilter else Path.emptyPathFinder) + println("Sources: " + sources) + val classes = classesDirectory(configuration) + val classpath = (classes +: data(prodcp)) ++ data(cp) + val analysis = analysisMap(prodcp ++ cp) + Compile.inputs(classpath, sources.getFiles.toSeq, classes, scalacOptions, javacOptions, javaSrc.getFiles.toSeq, analysis, cacheDirectory, 100)(compilers, log) + } + } + + lazy val compileInputs: Task[Compile.Inputs] = compileInputsTask(Configurations.Compile, "src" / "main") named(name + "/compile-inputs") + lazy val compile: Task[Analysis] = compileTask(compileInputs) named(name + "/compile") +}