2011-01-19 00:24:11 +01:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2011 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package sbt
|
|
|
|
|
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.net.URI
|
2011-01-27 01:49:54 +01:00
|
|
|
import compile.{Discovered,Discovery,Eval,EvalImports}
|
2011-01-19 00:24:11 +01:00
|
|
|
import classpath.ClasspathUtilities
|
|
|
|
|
import inc.Analysis
|
|
|
|
|
import scala.annotation.tailrec
|
2011-01-26 04:14:02 +01:00
|
|
|
import collection.mutable
|
2011-01-19 00:24:11 +01:00
|
|
|
import Compile.{Compilers,Inputs}
|
2011-02-01 00:15:15 +01:00
|
|
|
import Project.{AppConfig, Config, ScopedKey, Setting, ThisProject, ThisProjectRef}
|
2011-01-19 00:24:11 +01:00
|
|
|
import TypeFunctions.{Endo,Id}
|
|
|
|
|
import tools.nsc.reporters.ConsoleReporter
|
|
|
|
|
|
|
|
|
|
// name is more like BuildDefinition, but that is too long
|
|
|
|
|
trait Build
|
|
|
|
|
{
|
|
|
|
|
def projects: Seq[Project]
|
|
|
|
|
}
|
|
|
|
|
trait Plugin
|
|
|
|
|
{
|
|
|
|
|
def settings: Seq[Project.Setting[_]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object Build
|
|
|
|
|
{
|
|
|
|
|
def default(base: File): Build = new Build { def projects = defaultProject("default", base) :: Nil }
|
|
|
|
|
def defaultProject(id: String, base: File): Project = Project(id, base)
|
|
|
|
|
}
|
|
|
|
|
object RetrieveUnit
|
|
|
|
|
{
|
|
|
|
|
def apply(tempDir: File, base: URI): File =
|
|
|
|
|
{
|
|
|
|
|
lazy val tmp = temporary(tempDir, base)
|
|
|
|
|
base.getScheme match
|
|
|
|
|
{
|
|
|
|
|
case "file" => val f = new File(base); if(f.isDirectory) f else error("Not a directory: '" + base + "'")
|
|
|
|
|
case "git" => gitClone(base, tmp); tmp
|
|
|
|
|
case "http" | "https" => downloadAndExtract(base, tmp); tmp
|
|
|
|
|
case _ => error("Unknown scheme in '" + base + "'")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
def downloadAndExtract(base: URI, tempDir: File): Unit = if(!tempDir.exists) IO.unzipURL(base.toURL, tempDir)
|
|
|
|
|
def temporary(tempDir: File, uri: URI): File = new File(tempDir, hash(uri))
|
|
|
|
|
def hash(uri: URI): String = Hash.toHex(Hash(uri.toASCIIString))
|
|
|
|
|
|
|
|
|
|
import Process._
|
|
|
|
|
def gitClone(base: URI, tempDir: File): Unit =
|
|
|
|
|
if(!tempDir.exists) ("git" :: "clone" :: base.toASCIIString :: tempDir.getAbsolutePath :: Nil) ! ;
|
|
|
|
|
}
|
|
|
|
|
object EvaluateConfigurations
|
|
|
|
|
{
|
2011-01-27 01:49:54 +01:00
|
|
|
def apply(eval: Eval, srcs: Seq[File], imports: Seq[String]): Seq[Setting[_]] =
|
|
|
|
|
srcs flatMap { src => evaluateConfiguration(eval, src, imports) }
|
|
|
|
|
def evaluateConfiguration(eval: Eval, src: File, imports: Seq[String]): Seq[Setting[_]] =
|
|
|
|
|
evaluateConfiguration(eval, src.getPath, IO.readLines(src), imports)
|
|
|
|
|
def evaluateConfiguration(eval: Eval, name: String, lines: Seq[String], imports: Seq[String]): Seq[Setting[_]] =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
|
|
|
|
val (importExpressions, settingExpressions) = splitExpressions(name, lines)
|
2011-01-27 01:49:54 +01:00
|
|
|
for((settingExpression,line) <- settingExpressions) yield
|
2011-02-03 01:25:18 +01:00
|
|
|
evaluateSetting(eval, name, (imports.map(s => (s, -1)) ++ importExpressions), settingExpression, line)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-27 01:49:54 +01:00
|
|
|
def evaluateSetting(eval: Eval, name: String, imports: Seq[(String,Int)], expression: String, line: Int): Setting[_] =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-01-27 01:49:54 +01:00
|
|
|
val result = eval.eval(expression, imports = new EvalImports(imports, name), srcName = name, tpeName = Some("sbt.Project.Setting[_]"), line = line)
|
|
|
|
|
result.value.asInstanceOf[Setting[_]]
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
2011-01-27 01:49:54 +01:00
|
|
|
private[this] def fstS(f: String => Boolean): ((String,Int)) => Boolean = { case (s,i) => f(s) }
|
|
|
|
|
def splitExpressions(name: String, lines: Seq[String]): (Seq[(String,Int)], Seq[(String,Int)]) =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
|
|
|
|
val blank = (_: String).trim.isEmpty
|
2011-01-27 01:49:54 +01:00
|
|
|
val importOrBlank = fstS(t => blank(t) || (t.trim startsWith "import "))
|
2011-01-19 00:24:11 +01:00
|
|
|
|
2011-01-27 01:49:54 +01:00
|
|
|
val (imports, settings) = lines.zipWithIndex span importOrBlank
|
|
|
|
|
(imports filterNot fstS(blank), groupedLines(settings, blank))
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
2011-01-27 01:49:54 +01:00
|
|
|
def groupedLines(lines: Seq[(String,Int)], delimiter: String => Boolean): Seq[(String,Int)] =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-01-27 01:49:54 +01:00
|
|
|
val fdelim = fstS(delimiter)
|
|
|
|
|
@tailrec def group0(lines: Seq[(String,Int)], accum: Seq[(String,Int)]): Seq[(String,Int)] =
|
2011-01-25 00:08:43 +01:00
|
|
|
if(lines.isEmpty) accum.reverse
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-01-27 01:49:54 +01:00
|
|
|
val start = lines dropWhile fstS(delimiter)
|
|
|
|
|
val (next, tail) = start.span { case (s,_) => !delimiter(s) }
|
|
|
|
|
val grouped = if(next.isEmpty) accum else (next.map(_._1).mkString("\n"), next.head._2) +: accum
|
|
|
|
|
group0(tail, grouped)
|
2011-01-25 00:08:43 +01:00
|
|
|
}
|
2011-01-27 01:49:54 +01:00
|
|
|
group0(lines, Nil)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
object EvaluateTask
|
|
|
|
|
{
|
|
|
|
|
import Load.BuildStructure
|
|
|
|
|
import Project.display
|
|
|
|
|
import std.{TaskExtra,Transform}
|
|
|
|
|
import TaskExtra._
|
2011-01-21 23:22:18 +01:00
|
|
|
import BuildStreams.{Streams, TaskStreams}
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
val SystemProcessors = Runtime.getRuntime.availableProcessors
|
2011-02-05 04:02:39 +01:00
|
|
|
// TODO: we should use a Seq[Attributed[File]] so that we don't throw away Analysis information
|
|
|
|
|
val PluginDefinition = TaskKey[(Seq[File], Analysis)]("plugin-definition")
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
val (state, dummyState) = dummy[State]("state")
|
|
|
|
|
val (streams, dummyStreams) = dummy[TaskStreams]("streams")
|
|
|
|
|
|
2011-01-31 05:19:28 +01:00
|
|
|
def injectSettings: Seq[Project.Setting[_]] = Seq(
|
2011-02-05 04:02:39 +01:00
|
|
|
(state in Scope.GlobalScope) :== dummyState,
|
|
|
|
|
(streams in Scope.GlobalScope) :== dummyStreams
|
2011-01-19 00:24:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def dummy[T](name: String): (TaskKey[T], Task[T]) = (TaskKey[T](name), dummyTask(name))
|
|
|
|
|
def dummyTask[T](name: String): Task[T] = task( error("Dummy task '" + name + "' did not get converted to a full task.") ) named name
|
|
|
|
|
|
2011-02-05 04:02:39 +01:00
|
|
|
def evalPluginDef(log: Logger)(pluginDef: BuildStructure, state: State): (Seq[File], Analysis) =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-02-05 04:02:39 +01:00
|
|
|
val root = ProjectRef(pluginDef.root, Load.getRootProject(pluginDef.units)(pluginDef.root))
|
|
|
|
|
val evaluated = evaluateTask(pluginDef, ScopedKey(Scope.ThisScope, PluginDefinition.key), state, root)
|
2011-01-19 00:24:11 +01:00
|
|
|
val result = evaluated getOrElse error("Plugin task does not exist for plugin definition at " + pluginDef.root)
|
|
|
|
|
processResult(result, log)
|
|
|
|
|
}
|
2011-02-05 04:02:39 +01:00
|
|
|
def evaluateTask[T](structure: BuildStructure, taskKey: ScopedKey[Task[T]], state: State, thisProject: ProjectRef, checkCycles: Boolean = false, maxWorkers: Int = SystemProcessors): Option[Result[T]] =
|
|
|
|
|
for( (task, toNode) <- getTask(structure, taskKey, state, thisProject) ) yield
|
2011-01-19 00:24:11 +01:00
|
|
|
runTask(task, checkCycles, maxWorkers)(toNode)
|
|
|
|
|
|
2011-02-05 04:02:39 +01:00
|
|
|
def getTask[T](structure: BuildStructure, taskKey: ScopedKey[Task[T]], state: State, thisProject: ProjectRef): Option[(Task[T], Execute.NodeView[Task])] =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-02-05 04:02:39 +01:00
|
|
|
val thisScope = Scope(Select(thisProject), Global, Global, Global)
|
2011-01-19 00:24:11 +01:00
|
|
|
val resolvedScope = Scope.replaceThis(thisScope)( taskKey.scope )
|
|
|
|
|
for( t <- structure.data.get(resolvedScope, taskKey.key)) yield
|
2011-01-26 04:22:11 +01:00
|
|
|
(t, nodeView(structure, state))
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
2011-01-26 04:22:11 +01:00
|
|
|
def nodeView(structure: BuildStructure, state: State): Execute.NodeView[Task] =
|
|
|
|
|
transform(structure, dummyStreams, dummyState, state)
|
2011-01-19 00:24:11 +01:00
|
|
|
|
2011-01-26 04:22:11 +01:00
|
|
|
def runTask[Task[_] <: AnyRef, T](root: Task[T], checkCycles: Boolean = false, maxWorkers: Int = SystemProcessors)(implicit taskToNode: Execute.NodeView[Task]): Result[T] =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
|
|
|
|
val (service, shutdown) = CompletionService[Task[_], Completed](maxWorkers)
|
|
|
|
|
|
|
|
|
|
val x = new Execute[Task](checkCycles)(taskToNode)
|
|
|
|
|
try { x.run(root)(service) } finally { shutdown() }
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-21 23:22:18 +01:00
|
|
|
def transform(structure: BuildStructure, streamsDummy: Task[TaskStreams], stateDummy: Task[State], state: State) =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
|
|
|
|
val dummies = new Transform.Dummies(stateDummy :^: KNil, streamsDummy)
|
2011-01-21 23:22:18 +01:00
|
|
|
val inject = new Transform.Injected(state :+: HNil, structure.streams)
|
2011-01-19 00:24:11 +01:00
|
|
|
Transform(dummies, inject)(structure.index.taskToKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def processResult[T](result: Result[T], log: Logger): T =
|
|
|
|
|
result match
|
|
|
|
|
{
|
|
|
|
|
case Value(v) => v
|
|
|
|
|
case Inc(inc) =>
|
|
|
|
|
log.error(Incomplete.show(inc, true))
|
|
|
|
|
error("Task did not complete successfully")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
object Index
|
|
|
|
|
{
|
|
|
|
|
def taskToKeyMap(data: Settings[Scope]): Map[Task[_], ScopedKey[Task[_]]] =
|
|
|
|
|
{
|
|
|
|
|
// AttributeEntry + the checked type test 'value: Task[_]' ensures that the cast is correct.
|
|
|
|
|
// (scalac couldn't determine that 'key' is of type AttributeKey[Task[_]] on its own and a type match didn't still required the cast)
|
|
|
|
|
val pairs = for( scope <- data.scopes; AttributeEntry(key, value: Task[_]) <- data.data(scope).entries ) yield
|
|
|
|
|
(value, ScopedKey(scope, key.asInstanceOf[AttributeKey[Task[_]]])) // unclear why this cast is needed even with a type test in the above filter
|
|
|
|
|
pairs.toMap[Task[_], ScopedKey[Task[_]]]
|
|
|
|
|
}
|
|
|
|
|
def stringToKeyMap(settings: Settings[Scope]): Map[String, AttributeKey[_]] =
|
|
|
|
|
{
|
|
|
|
|
val multiMap = settings.data.values.flatMap(_.keys).toList.removeDuplicates.groupBy(_.label)
|
2011-01-27 01:49:54 +01:00
|
|
|
val duplicates = multiMap collect { case (k, x1 :: x2 :: _) => k }
|
2011-01-19 00:24:11 +01:00
|
|
|
if(duplicates.isEmpty)
|
|
|
|
|
multiMap.mapValues(_.head)
|
|
|
|
|
else
|
|
|
|
|
error(duplicates.mkString("AttributeKey ID collisions detected for '", "', '", "'"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
object Load
|
|
|
|
|
{
|
|
|
|
|
import BuildPaths._
|
2011-01-21 23:22:18 +01:00
|
|
|
import BuildStreams._
|
2011-01-19 00:24:11 +01:00
|
|
|
|
2011-02-05 04:02:39 +01:00
|
|
|
// note that there is State is passed in but not pulled out
|
2011-01-25 13:24:52 +01:00
|
|
|
def defaultLoad(state: State, log: Logger): (() => Eval, BuildStructure) =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-01-24 04:34:17 +01:00
|
|
|
val stagingDirectory = defaultStaging.getCanonicalFile // TODO: properly configurable
|
|
|
|
|
val base = state.configuration.baseDirectory.getCanonicalFile
|
2011-01-19 00:24:11 +01:00
|
|
|
val loader = getClass.getClassLoader
|
|
|
|
|
val provider = state.configuration.provider
|
|
|
|
|
val classpath = provider.mainClasspath ++ provider.scalaProvider.jars
|
|
|
|
|
val compilers = Compile.compilers(state.configuration, log)
|
2011-02-05 04:02:39 +01:00
|
|
|
val evalPluginDef = EvaluateTask.evalPluginDef(log) _
|
2011-01-26 04:14:02 +01:00
|
|
|
val delegates = memo(defaultDelegates)
|
2011-02-05 04:02:39 +01:00
|
|
|
val inject: Seq[Project.Setting[_]] = ((AppConfig in Scope.GlobalScope) :== state.configuration) +: EvaluateTask.injectSettings
|
2011-01-31 05:19:28 +01:00
|
|
|
val config = new LoadBuildConfiguration(stagingDirectory, classpath, loader, compilers, evalPluginDef, delegates, inject, log)
|
2011-02-05 04:02:39 +01:00
|
|
|
apply(base, state, config)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
def defaultDelegates: LoadedBuild => Scope => Seq[Scope] = (lb: LoadedBuild) => {
|
2011-01-26 04:14:02 +01:00
|
|
|
val rootProject = getRootProject(lb.units)
|
|
|
|
|
def resolveRef(project: ProjectRef) = Scope.resolveRef(lb.root, rootProject, project)
|
2011-01-19 00:24:11 +01:00
|
|
|
Scope.delegates(
|
|
|
|
|
project => projectInherit(lb, resolveRef(project)),
|
|
|
|
|
(project, config) => configInherit(lb, resolveRef(project), config),
|
|
|
|
|
(project, task) => Nil,
|
|
|
|
|
(project, extra) => Nil
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
def configInherit(lb: LoadedBuild, ref: (URI, String), config: ConfigKey): Seq[ConfigKey] =
|
|
|
|
|
getConfiguration(lb.units, ref._1, ref._2, config).extendsConfigs.map(c => ConfigKey(c.name))
|
|
|
|
|
|
|
|
|
|
def projectInherit(lb: LoadedBuild, ref: (URI, String)): Seq[ProjectRef] =
|
|
|
|
|
getProject(lb.units, ref._1, ref._2).inherits
|
|
|
|
|
|
|
|
|
|
// build, load, and evaluate all units.
|
|
|
|
|
// 1) Compile all plugin definitions
|
|
|
|
|
// 2) Evaluate plugin definitions to obtain and compile plugins and get the resulting classpath for the build definition
|
|
|
|
|
// 3) Instantiate Plugins on that classpath
|
|
|
|
|
// 4) Compile all build definitions using plugin classpath
|
|
|
|
|
// 5) Load build definitions.
|
|
|
|
|
// 6) Load all configurations using build definitions and plugins (their classpaths and loaded instances).
|
|
|
|
|
// 7) Combine settings from projects, plugins, and configurations
|
|
|
|
|
// 8) Evaluate settings
|
2011-02-05 04:02:39 +01:00
|
|
|
def apply(rootBase: File, s: State, config: LoadBuildConfiguration): (() => Eval, BuildStructure) =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-01-26 04:14:02 +01:00
|
|
|
// load, which includes some resolution, but can't fill in project IDs yet, so follow with full resolution
|
2011-02-05 04:02:39 +01:00
|
|
|
val loaded = resolveProjects(load(rootBase, s, config))
|
2011-01-19 00:24:11 +01:00
|
|
|
val projects = loaded.units
|
2011-01-25 13:24:52 +01:00
|
|
|
lazy val rootEval = lazyEval(loaded.units(loaded.root).unit)
|
2011-01-31 05:19:28 +01:00
|
|
|
val settings = config.injectSettings ++ buildConfigurations(loaded, getRootProject(projects), rootEval)
|
2011-01-25 13:24:52 +01:00
|
|
|
val delegates = config.delegates(loaded)
|
2011-02-01 00:16:25 +01:00
|
|
|
val data = Project.makeSettings(settings, delegates)
|
2011-01-19 00:24:11 +01:00
|
|
|
val index = structureIndex(data)
|
2011-01-21 23:22:18 +01:00
|
|
|
val streams = mkStreams(projects, loaded.root, data)
|
2011-01-25 13:24:52 +01:00
|
|
|
(rootEval, new BuildStructure(projects, loaded.root, settings, data, index, streams, delegates))
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def structureIndex(settings: Settings[Scope]): StructureIndex =
|
2011-01-26 04:22:11 +01:00
|
|
|
new StructureIndex(Index.stringToKeyMap(settings), Index.taskToKeyMap(settings), KeyIndex(settings.allKeys( (s,k) => ScopedKey(s,k))))
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
// Reevaluates settings after modifying them. Does not recompile or reload any build components.
|
2011-01-25 13:24:52 +01:00
|
|
|
def reapply(newSettings: Seq[Setting[_]], structure: BuildStructure): BuildStructure =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-02-01 00:16:25 +01:00
|
|
|
val newData = Project.makeSettings(newSettings, structure.delegates)
|
2011-01-19 00:24:11 +01:00
|
|
|
val newIndex = structureIndex(newData)
|
2011-01-21 23:22:18 +01:00
|
|
|
val newStreams = mkStreams(structure.units, structure.root, newData)
|
2011-01-25 13:24:52 +01:00
|
|
|
new BuildStructure(units = structure.units, root = structure.root, settings = newSettings, data = newData, index = newIndex, streams = newStreams, delegates = structure.delegates)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def isProjectThis(s: Setting[_]) = s.key.scope.project == This
|
2011-01-31 05:19:28 +01:00
|
|
|
def buildConfigurations(loaded: LoadedBuild, rootProject: URI => String, rootEval: () => Eval): Seq[Setting[_]] =
|
2011-01-19 00:24:11 +01:00
|
|
|
loaded.units.toSeq flatMap { case (uri, build) =>
|
2011-01-25 13:24:52 +01:00
|
|
|
val eval = if(uri == loaded.root) rootEval else lazyEval(build.unit)
|
2011-01-19 00:24:11 +01:00
|
|
|
val pluginSettings = build.unit.plugins.plugins
|
|
|
|
|
val (pluginThisProject, pluginGlobal) = pluginSettings partition isProjectThis
|
|
|
|
|
val projectSettings = build.defined flatMap { case (id, project) =>
|
|
|
|
|
val srcs = configurationSources(project.base)
|
2011-02-01 00:15:15 +01:00
|
|
|
val ref = ProjectRef(Some(uri), Some(id))
|
2011-02-05 04:02:39 +01:00
|
|
|
val defineConfig = for(c <- project.configurations) yield ( (Config in (ref, ConfigKey(c.name))) :== c)
|
2011-01-31 05:19:28 +01:00
|
|
|
val settings =
|
|
|
|
|
(ThisProject :== project) +:
|
2011-02-01 00:15:15 +01:00
|
|
|
(ThisProjectRef :== ref) +:
|
|
|
|
|
(defineConfig ++ project.settings ++ pluginThisProject ++ configurations(srcs, eval, build.imports))
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
// map This to thisScope, Select(p) to mapRef(uri, rootProject, p)
|
2011-01-25 13:24:52 +01:00
|
|
|
transformSettings(projectScope(uri, id), uri, rootProject, settings)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
pluginGlobal ++ projectSettings
|
|
|
|
|
}
|
2011-01-25 13:24:52 +01:00
|
|
|
def transformSettings(thisScope: Scope, uri: URI, rootProject: URI => String, settings: Seq[Setting[_]]): Seq[Setting[_]] =
|
|
|
|
|
Project.transform(Scope.resolveScope(thisScope, uri, rootProject), settings)
|
|
|
|
|
def projectScope(uri: URI, id: String): Scope = projectScope(ProjectRef(uri, id))
|
|
|
|
|
def projectScope(project: ProjectRef): Scope = Scope(Select(project), Global, Global, Global)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lazyEval(unit: BuildUnit): () => Eval =
|
|
|
|
|
{
|
|
|
|
|
lazy val eval = mkEval(unit)
|
|
|
|
|
() => eval
|
|
|
|
|
}
|
|
|
|
|
def mkEval(unit: BuildUnit): Eval = mkEval(unit.definitions, unit.plugins, Nil)
|
2011-01-19 00:24:11 +01:00
|
|
|
def mkEval(defs: LoadedDefinitions, plugs: LoadedPlugins, options: Seq[String]): Eval =
|
2011-02-03 01:38:41 +01:00
|
|
|
new Eval(options, defs.target +: plugs.classpath, s => new ConsoleReporter(s), defs.loader, Some(evalOutputDirectory(defs.base)))
|
|
|
|
|
|
2011-01-27 01:49:54 +01:00
|
|
|
def configurations(srcs: Seq[File], eval: () => Eval, imports: Seq[String]): Seq[Setting[_]] =
|
|
|
|
|
if(srcs.isEmpty) Nil else EvaluateConfigurations(eval(), srcs, imports)
|
2011-01-19 00:24:11 +01:00
|
|
|
|
2011-02-05 04:02:39 +01:00
|
|
|
def load(file: File, s: State, config: LoadBuildConfiguration): LoadedBuild =
|
|
|
|
|
load(file, uri => loadUnit(uri, RetrieveUnit(config.stagingDirectory, uri), s, config) )
|
2011-01-24 04:34:17 +01:00
|
|
|
def load(file: File, loader: URI => BuildUnit): LoadedBuild = loadURI(IO.directoryURI(file), loader)
|
2011-01-19 00:24:11 +01:00
|
|
|
def loadURI(uri: URI, loader: URI => BuildUnit): LoadedBuild =
|
|
|
|
|
{
|
2011-01-24 04:34:17 +01:00
|
|
|
IO.assertAbsolute(uri)
|
2011-01-19 00:24:11 +01:00
|
|
|
val (referenced, map) = loadAll(uri :: Nil, Map.empty, loader, Map.empty)
|
|
|
|
|
checkAll(referenced, map)
|
|
|
|
|
new LoadedBuild(uri, map)
|
|
|
|
|
}
|
|
|
|
|
def loaded(unit: BuildUnit): (LoadedBuildUnit, List[ProjectRef]) =
|
|
|
|
|
{
|
|
|
|
|
val defined = projects(unit)
|
2011-01-24 04:34:17 +01:00
|
|
|
if(defined.isEmpty) error("No projects defined in build unit " + unit)
|
2011-01-26 04:14:02 +01:00
|
|
|
|
|
|
|
|
// since base directories are resolved at this point (after 'projects'),
|
|
|
|
|
// we can compare Files instead of converting to URIs
|
|
|
|
|
def isRoot(p: Project) = p.base == unit.localBase
|
|
|
|
|
|
2011-01-19 00:24:11 +01:00
|
|
|
val externals = referenced(defined).toList
|
2011-01-24 04:34:17 +01:00
|
|
|
val projectsInRoot = defined.filter(isRoot).map(_.id)
|
|
|
|
|
val rootProjects = if(projectsInRoot.isEmpty) defined.head.id :: Nil else projectsInRoot
|
2011-01-19 00:24:11 +01:00
|
|
|
(new LoadedBuildUnit(unit, defined.map(d => (d.id, d)).toMap, rootProjects), externals)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@tailrec def loadAll(bases: List[URI], references: Map[URI, List[ProjectRef]], externalLoader: URI => BuildUnit, builds: Map[URI, LoadedBuildUnit]): (Map[URI, List[ProjectRef]], Map[URI, LoadedBuildUnit]) =
|
|
|
|
|
bases match
|
|
|
|
|
{
|
|
|
|
|
case b :: bs =>
|
|
|
|
|
if(builds contains b)
|
|
|
|
|
loadAll(bs, references, externalLoader, builds)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
val (loadedBuild, refs) = loaded(externalLoader(b))
|
2011-01-24 04:34:17 +01:00
|
|
|
checkBuildBase(loadedBuild.localBase)
|
2011-01-19 00:24:11 +01:00
|
|
|
loadAll(refs.flatMap(_.uri) reverse_::: bs, references.updated(b, refs), externalLoader, builds.updated(b, loadedBuild))
|
|
|
|
|
}
|
|
|
|
|
case Nil => (references, builds)
|
|
|
|
|
}
|
2011-01-24 04:34:17 +01:00
|
|
|
def checkProjectBase(buildBase: File, projectBase: File)
|
|
|
|
|
{
|
|
|
|
|
checkDirectory(projectBase)
|
|
|
|
|
assert(buildBase == projectBase || IO.relativize(buildBase, projectBase).isDefined, "Directory " + projectBase + " is not contained in build root " + buildBase)
|
|
|
|
|
}
|
|
|
|
|
def checkBuildBase(base: File) = checkDirectory(base)
|
|
|
|
|
def checkDirectory(base: File)
|
|
|
|
|
{
|
|
|
|
|
assert(base.isDirectory, "Not an existing directory: " + base)
|
|
|
|
|
assert(base.isAbsolute, "Not absolute: " + base)
|
|
|
|
|
}
|
2011-01-19 00:24:11 +01:00
|
|
|
def checkAll(referenced: Map[URI, List[ProjectRef]], builds: Map[URI, LoadedBuildUnit])
|
|
|
|
|
{
|
|
|
|
|
val rootProject = getRootProject(builds)
|
|
|
|
|
for( (uri, refs) <- referenced; ref <- refs)
|
|
|
|
|
{
|
2011-01-26 04:14:02 +01:00
|
|
|
val (refURI, refID) = Scope.resolveRef(uri, rootProject, ref)
|
2011-01-19 00:24:11 +01:00
|
|
|
val loadedUnit = builds(refURI)
|
|
|
|
|
if(! (loadedUnit.defined contains refID) )
|
|
|
|
|
error("No project '" + refID + "' in '" + refURI + "'")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-26 04:14:02 +01:00
|
|
|
def resolveBase(against: File): Project => Project =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-01-24 04:34:17 +01:00
|
|
|
def resolve(f: File) =
|
|
|
|
|
{
|
|
|
|
|
val fResolved = new File(IO.directoryURI(IO.resolve(against, f)))
|
|
|
|
|
checkProjectBase(against, fResolved)
|
|
|
|
|
fResolved
|
|
|
|
|
}
|
2011-01-26 04:14:02 +01:00
|
|
|
p => p.copy(base = resolve(p.base))
|
|
|
|
|
}
|
|
|
|
|
def resolveProjects(loaded: LoadedBuild): LoadedBuild =
|
|
|
|
|
{
|
|
|
|
|
val rootProject = getRootProject(loaded.units)
|
|
|
|
|
new LoadedBuild(loaded.root, loaded.units.map { case (uri, unit) =>
|
|
|
|
|
IO.assertAbsolute(uri)
|
|
|
|
|
(uri, resolveProjects(uri, unit, rootProject))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
def resolveProjects(uri: URI, unit: LoadedBuildUnit, rootProject: URI => String): LoadedBuildUnit =
|
|
|
|
|
{
|
|
|
|
|
IO.assertAbsolute(uri)
|
|
|
|
|
val resolve = resolveProject(ref => Scope.mapRef(uri, rootProject, ref))
|
|
|
|
|
new LoadedBuildUnit(unit.unit, unit.defined mapValues resolve, unit.rootProjects)
|
|
|
|
|
}
|
|
|
|
|
def resolveProject(resolveRef: ProjectRef => ProjectRef): Project => Project =
|
|
|
|
|
{
|
|
|
|
|
def resolveRefs(prs: Seq[ProjectRef]) = prs map resolveRef
|
|
|
|
|
def resolveDeps(ds: Seq[Project.ClasspathDependency]) = ds map resolveDep
|
|
|
|
|
def resolveDep(d: Project.ClasspathDependency) = d.copy(project = resolveRef(d.project))
|
|
|
|
|
p => p.copy(aggregate = resolveRefs(p.aggregate), dependencies = resolveDeps(p.dependencies), inherits = resolveRefs(p.inherits))
|
2011-01-24 04:34:17 +01:00
|
|
|
}
|
|
|
|
|
def projects(unit: BuildUnit): Seq[Project] =
|
|
|
|
|
{
|
2011-01-26 04:14:02 +01:00
|
|
|
// we don't have the complete build graph loaded, so we don't have the rootProject function yet.
|
|
|
|
|
// Therefore, we use mapRefBuild instead of mapRef. After all builds are loaded, we can fully resolve ProjectRefs.
|
|
|
|
|
val resolve = resolveProject(ref => Scope.mapRefBuild(unit.uri, ref)) compose resolveBase(unit.localBase)
|
2011-01-24 04:34:17 +01:00
|
|
|
unit.definitions.builds.flatMap(_.projects map resolve)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
def getRootProject(map: Map[URI, LoadedBuildUnit]): URI => String =
|
|
|
|
|
uri => getBuild(map, uri).rootProjects.headOption getOrElse emptyBuild(uri)
|
|
|
|
|
def getConfiguration(map: Map[URI, LoadedBuildUnit], uri: URI, id: String, conf: ConfigKey): Configuration =
|
|
|
|
|
getProject(map, uri, id).configurations.find(_.name == conf.name) getOrElse noConfiguration(uri, id, conf.name)
|
|
|
|
|
|
|
|
|
|
def getProject(map: Map[URI, LoadedBuildUnit], uri: URI, id: String): Project =
|
|
|
|
|
getBuild(map, uri).defined.getOrElse(id, noProject(uri, id))
|
|
|
|
|
def getBuild(map: Map[URI, LoadedBuildUnit], uri: URI): LoadedBuildUnit =
|
|
|
|
|
map.getOrElse(uri, noBuild(uri))
|
|
|
|
|
|
|
|
|
|
def emptyBuild(uri: URI) = error("No root project defined for build unit '" + uri + "'")
|
|
|
|
|
def noBuild(uri: URI) = error("Build unit '" + uri + "' not defined.")
|
|
|
|
|
def noProject(uri: URI, id: String) = error("No project '" + id + "' defined in '" + uri + "'.")
|
|
|
|
|
def noConfiguration(uri: URI, id: String, conf: String) = error("No configuration '" + conf + "' defined in project '" + id + "' in '" + uri +"'")
|
|
|
|
|
|
2011-02-05 04:02:39 +01:00
|
|
|
def loadUnit(uri: URI, localBase: File, s: State, config: LoadBuildConfiguration): BuildUnit =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-01-24 04:34:17 +01:00
|
|
|
val normBase = localBase.getCanonicalFile
|
|
|
|
|
val defDir = selectProjectDir(normBase)
|
2011-01-19 00:24:11 +01:00
|
|
|
val pluginDir = pluginDirectory(defDir)
|
2011-02-05 04:02:39 +01:00
|
|
|
val plugs = plugins(pluginDir, s, config)
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
val defs = definitionSources(defDir)
|
2011-02-03 01:34:52 +01:00
|
|
|
val target = buildOutputDirectory(defDir, config.compilers)
|
|
|
|
|
IO.createDirectory(target)
|
2011-01-19 00:24:11 +01:00
|
|
|
val loadedDefs =
|
|
|
|
|
if(defs.isEmpty)
|
2011-02-03 01:34:52 +01:00
|
|
|
new LoadedDefinitions(defDir, target, plugs.loader, Build.default(normBase) :: Nil, Nil)
|
2011-01-19 00:24:11 +01:00
|
|
|
else
|
2011-02-03 01:34:52 +01:00
|
|
|
definitions(defDir, target, defs, plugs, config.compilers, config.log, normBase)
|
2011-01-19 00:24:11 +01:00
|
|
|
|
2011-01-24 04:34:17 +01:00
|
|
|
new BuildUnit(uri, normBase, loadedDefs, plugs)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-05 04:02:39 +01:00
|
|
|
def plugins(dir: File, s: State, config: LoadBuildConfiguration): LoadedPlugins = if(dir.exists) buildPlugins(dir, s, config) else noPlugins(config)
|
2011-01-27 01:49:54 +01:00
|
|
|
def noPlugins(config: LoadBuildConfiguration): LoadedPlugins = new LoadedPlugins(config.classpath, config.loader, Nil, Nil)
|
2011-02-05 04:02:39 +01:00
|
|
|
def buildPlugins(dir: File, s: State, config: LoadBuildConfiguration): LoadedPlugins =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-02-05 04:02:39 +01:00
|
|
|
val (eval,pluginDef) = apply(dir, s, config)
|
|
|
|
|
val pluginState = Project.setProject(Load.initialSession(pluginDef, eval), pluginDef, s)
|
|
|
|
|
|
|
|
|
|
val (pluginClasspath, pluginAnalysis) = config.evalPluginDef(pluginDef, pluginState)
|
|
|
|
|
val definitionClasspath = (pluginClasspath ++ config.classpath).distinct
|
|
|
|
|
val pluginLoader = ClasspathUtilities.toLoader(definitionClasspath, config.loader)
|
|
|
|
|
loadPlugins(definitionClasspath, pluginLoader, pluginAnalysis)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-03 01:34:52 +01:00
|
|
|
def definitions(base: File, targetBase: File, srcs: Seq[File], plugins: LoadedPlugins, compilers: Compilers, log: Logger, buildBase: File): LoadedDefinitions =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
2011-02-03 01:34:52 +01:00
|
|
|
val (inputs, defAnalysis) = build(plugins.classpath, srcs, targetBase, compilers, log)
|
2011-01-19 00:24:11 +01:00
|
|
|
val target = inputs.config.classesDirectory
|
|
|
|
|
val definitionLoader = ClasspathUtilities.toLoader(target :: Nil, plugins.loader)
|
2011-01-27 01:49:54 +01:00
|
|
|
val defNames = findDefinitions(defAnalysis)
|
2011-02-03 01:34:52 +01:00
|
|
|
val defs = if(defNames.isEmpty) Build.default(buildBase) :: Nil else loadDefinitions(definitionLoader, defNames)
|
2011-01-27 01:49:54 +01:00
|
|
|
new LoadedDefinitions(base, target, definitionLoader, defs, defNames)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def loadDefinitions(loader: ClassLoader, defs: Seq[String]): Seq[Build] =
|
|
|
|
|
defs map { definition => loadDefinition(loader, definition) }
|
|
|
|
|
def loadDefinition(loader: ClassLoader, definition: String): Build =
|
|
|
|
|
ModuleUtilities.getObject(definition, loader).asInstanceOf[Build]
|
|
|
|
|
|
2011-02-03 01:34:52 +01:00
|
|
|
def build(classpath: Seq[File], sources: Seq[File], target: File, compilers: Compilers, log: Logger): (Inputs, Analysis) =
|
2011-01-19 00:24:11 +01:00
|
|
|
{
|
|
|
|
|
val inputs = Compile.inputs(classpath, sources, target, Nil, Nil, Nil, Compile.DefaultMaxErrors)(compilers, log)
|
|
|
|
|
val analysis = Compile(inputs, log)
|
|
|
|
|
(inputs, analysis)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def loadPlugins(classpath: Seq[File], loader: ClassLoader, analysis: Analysis): LoadedPlugins =
|
2011-01-27 01:49:54 +01:00
|
|
|
{
|
|
|
|
|
val (pluginNames, plugins) = if(classpath.isEmpty) (Nil, Nil) else {
|
|
|
|
|
val names = findPlugins(analysis)
|
|
|
|
|
(names, loadPlugins(loader, names) )
|
|
|
|
|
}
|
|
|
|
|
new LoadedPlugins(classpath, loader, plugins, pluginNames)
|
|
|
|
|
}
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
def loadPlugins(loader: ClassLoader, pluginNames: Seq[String]): Seq[Setting[_]] =
|
|
|
|
|
pluginNames.flatMap(pluginName => loadPlugin(pluginName, loader))
|
|
|
|
|
|
|
|
|
|
def loadPlugin(pluginName: String, loader: ClassLoader): Seq[Setting[_]] =
|
|
|
|
|
ModuleUtilities.getObject(pluginName, loader).asInstanceOf[Plugin].settings
|
|
|
|
|
|
2011-01-27 01:49:54 +01:00
|
|
|
def importAll(values: Seq[String]) = if(values.isEmpty) Nil else values.map( _ + "._" ).mkString("import ", ", ", "") :: Nil
|
|
|
|
|
|
2011-01-19 00:24:11 +01:00
|
|
|
def findPlugins(analysis: Analysis): Seq[String] = discover(analysis, "sbt.Plugin")
|
|
|
|
|
def findDefinitions(analysis: Analysis): Seq[String] = discover(analysis, "sbt.Build")
|
|
|
|
|
def discover(analysis: Analysis, subclasses: String*): Seq[String] =
|
|
|
|
|
{
|
2011-02-03 01:25:18 +01:00
|
|
|
val subclassSet = subclasses.toSet
|
|
|
|
|
val ds = Discovery(subclassSet, Set.empty)(Test.allDefs(analysis))
|
|
|
|
|
ds.flatMap { case (definition, Discovered(subs,_,_,true)) =>
|
|
|
|
|
if((subs ** subclassSet).isEmpty) Nil else definition.name :: Nil
|
|
|
|
|
}
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-25 13:24:52 +01:00
|
|
|
def initialSession(structure: BuildStructure, rootEval: () => Eval): SessionSettings =
|
|
|
|
|
new SessionSettings(structure.root, rootProjectMap(structure.units), structure.settings, Map.empty, Map.empty, rootEval)
|
2011-01-27 01:49:54 +01:00
|
|
|
|
2011-01-19 00:24:11 +01:00
|
|
|
def rootProjectMap(units: Map[URI, LoadedBuildUnit]): Map[URI, String] =
|
|
|
|
|
{
|
|
|
|
|
val getRoot = getRootProject(units)
|
|
|
|
|
units.keys.map(uri => (uri, getRoot(uri))).toMap
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 01:49:54 +01:00
|
|
|
def baseImports = "import sbt._, Process._, java.io.File, java.net.URI" :: Nil
|
|
|
|
|
|
2011-01-19 00:24:11 +01:00
|
|
|
final class EvaluatedConfigurations(val eval: Eval, val settings: Seq[Setting[_]])
|
2011-01-27 01:49:54 +01:00
|
|
|
final class LoadedDefinitions(val base: File, val target: File, val loader: ClassLoader, val builds: Seq[Build], val buildNames: Seq[String])
|
|
|
|
|
final class LoadedPlugins(val classpath: Seq[File], val loader: ClassLoader, val plugins: Seq[Setting[_]], val pluginNames: Seq[String])
|
2011-01-19 00:24:11 +01:00
|
|
|
object LoadedPlugins {
|
2011-01-27 01:49:54 +01:00
|
|
|
def empty(loader: ClassLoader) = new LoadedPlugins(Nil, loader, Nil, Nil)
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
2011-01-24 04:34:17 +01:00
|
|
|
final class BuildUnit(val uri: URI, val localBase: File, val definitions: LoadedDefinitions, val plugins: LoadedPlugins)
|
|
|
|
|
{
|
|
|
|
|
override def toString = if(uri.getScheme == "file") localBase.toString else (uri + " (locally: " + localBase +")")
|
|
|
|
|
}
|
2011-01-19 00:24:11 +01:00
|
|
|
|
|
|
|
|
final class LoadedBuild(val root: URI, val units: Map[URI, LoadedBuildUnit])
|
|
|
|
|
final class LoadedBuildUnit(val unit: BuildUnit, val defined: Map[String, Project], val rootProjects: Seq[String])
|
|
|
|
|
{
|
2011-01-24 04:34:17 +01:00
|
|
|
assert(!rootProjects.isEmpty, "No root projects defined for build unit " + unit)
|
|
|
|
|
def localBase = unit.localBase
|
2011-01-19 00:24:11 +01:00
|
|
|
def classpath = unit.definitions.target +: unit.plugins.classpath
|
2011-01-27 01:49:54 +01:00
|
|
|
def loader = unit.definitions.loader
|
|
|
|
|
def imports = baseImports ++ importAll(unit.plugins.pluginNames ++ unit.definitions.buildNames)
|
2011-01-24 04:34:17 +01:00
|
|
|
override def toString = unit.toString
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// these are unresolved references
|
|
|
|
|
def referenced(definitions: Seq[Project]): Seq[ProjectRef] = definitions flatMap referenced
|
|
|
|
|
def referenced(definition: Project): Seq[ProjectRef] = definition.inherits ++ definition.aggregate ++ definition.dependencies.map(_.project)
|
|
|
|
|
|
|
|
|
|
|
2011-01-25 13:24:52 +01:00
|
|
|
final class BuildStructure(val units: Map[URI, LoadedBuildUnit], val root: URI, val settings: Seq[Setting[_]], val data: Settings[Scope], val index: StructureIndex, val streams: Streams, val delegates: Scope => Seq[Scope])
|
2011-02-05 04:02:39 +01:00
|
|
|
final class LoadBuildConfiguration(val stagingDirectory: File, val classpath: Seq[File], val loader: ClassLoader, val compilers: Compilers, val evalPluginDef: (BuildStructure, State) => (Seq[File], Analysis), val delegates: LoadedBuild => Scope => Seq[Scope], val injectSettings: Seq[Setting[_]], val log: Logger)
|
2011-01-19 00:24:11 +01:00
|
|
|
// information that is not original, but can be reconstructed from the rest of BuildStructure
|
2011-01-26 04:22:11 +01:00
|
|
|
final class StructureIndex(val keyMap: Map[String, AttributeKey[_]], val taskToKey: Map[Task[_], ScopedKey[Task[_]]], val keyIndex: KeyIndex)
|
2011-01-26 04:14:02 +01:00
|
|
|
|
|
|
|
|
private[this] def memo[A,B](implicit f: A => B): A => B =
|
|
|
|
|
{
|
|
|
|
|
val dcache = new mutable.HashMap[A,B]
|
|
|
|
|
(a: A) => dcache.getOrElseUpdate(a, f(a))
|
|
|
|
|
}
|
2011-01-19 00:24:11 +01:00
|
|
|
}
|
2011-01-21 23:22:18 +01:00
|
|
|
object BuildStreams
|
|
|
|
|
{
|
|
|
|
|
import Load.{BuildStructure, LoadedBuildUnit}
|
|
|
|
|
import Project.display
|
|
|
|
|
import std.{TaskExtra,Transform}
|
|
|
|
|
|
|
|
|
|
type Streams = std.Streams[ScopedKey[Task[_]]]
|
|
|
|
|
type TaskStreams = std.TaskStreams[ScopedKey[Task[_]]]
|
|
|
|
|
val GlobalPath = "$global"
|
|
|
|
|
|
|
|
|
|
def mkStreams(units: Map[URI, LoadedBuildUnit], root: URI, data: Settings[Scope], logRelativePath: Seq[String] = defaultLogPath): Streams =
|
|
|
|
|
std.Streams( path(units, root, logRelativePath), display, LogManager.construct(data) )
|
|
|
|
|
|
|
|
|
|
def defaultLogPath = "target" :: "streams" :: Nil
|
|
|
|
|
|
|
|
|
|
def path(units: Map[URI, LoadedBuildUnit], root: URI, sep: Seq[String])(scoped: ScopedKey[_]): File =
|
|
|
|
|
{
|
|
|
|
|
val (base, sub) = projectPath(units, root, scoped)
|
|
|
|
|
resolvePath(base, sep ++ sub ++ nonProjectPath(scoped) )
|
|
|
|
|
}
|
|
|
|
|
def resolvePath(base: File, components: Seq[String]): File =
|
|
|
|
|
(base /: components)( (b,p) => new File(b,p) )
|
|
|
|
|
|
|
|
|
|
def pathComponent[T](axis: ScopeAxis[T], scoped: ScopedKey[_], label: String)(show: T => String): String =
|
|
|
|
|
axis match
|
|
|
|
|
{
|
|
|
|
|
case Global => GlobalPath
|
|
|
|
|
case This => error("Unresolved This reference for " + label + " in " + display(scoped))
|
|
|
|
|
case Select(t) => show(t)
|
|
|
|
|
}
|
|
|
|
|
def nonProjectPath[T](scoped: ScopedKey[T]): Seq[String] =
|
|
|
|
|
{
|
|
|
|
|
val scope = scoped.scope
|
|
|
|
|
pathComponent(scope.config, scoped, "config")(_.name) ::
|
|
|
|
|
pathComponent(scope.task, scoped, "task")(_.label) ::
|
|
|
|
|
pathComponent(scope.extra, scoped, "extra")(_ => error("Unimplemented")) ::
|
|
|
|
|
Nil
|
|
|
|
|
}
|
|
|
|
|
def projectPath(units: Map[URI, LoadedBuildUnit], root: URI, scoped: ScopedKey[_]): (File, Seq[String]) =
|
|
|
|
|
scoped.scope.project match
|
|
|
|
|
{
|
2011-01-24 04:34:17 +01:00
|
|
|
case Global => (units(root).localBase, GlobalPath :: Nil)
|
2011-01-21 23:22:18 +01:00
|
|
|
case Select(ProjectRef(Some(uri), Some(id))) => (units(uri).defined(id).base, Nil)
|
|
|
|
|
case Select(pr) => error("Unresolved project reference (" + pr + ") in " + display(scoped))
|
|
|
|
|
case This => error("Unresolved project reference (This) in " + display(scoped))
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-19 00:24:11 +01:00
|
|
|
object BuildPaths
|
|
|
|
|
{
|
|
|
|
|
import Path._
|
|
|
|
|
import GlobFilter._
|
|
|
|
|
|
|
|
|
|
def defaultStaging = Path.userHome / ".ivy2" / "staging"
|
|
|
|
|
|
|
|
|
|
def definitionSources(base: File): Seq[File] = (base * "*.scala").getFiles.toSeq
|
|
|
|
|
def configurationSources(base: File): Seq[File] = (base * "*.sbt").getFiles.toSeq
|
|
|
|
|
def pluginDirectory(definitionBase: Path) = definitionBase / "plugins"
|
|
|
|
|
|
2011-02-03 01:34:52 +01:00
|
|
|
def evalOutputDirectory(base: Path) = outputDirectory(base) / "config-classes"
|
2011-01-19 00:24:11 +01:00
|
|
|
def outputDirectory(base: Path) = base / "target"
|
2011-02-03 01:34:52 +01:00
|
|
|
def buildOutputDirectory(base: Path, compilers: Compilers) = crossPath(outputDirectory(base), compilers.scalac.scalaInstance)
|
|
|
|
|
|
2011-01-19 00:24:11 +01:00
|
|
|
def projectStandard(base: Path) = base / "project"
|
|
|
|
|
def projectHidden(base: Path) = base / ".sbt"
|
|
|
|
|
def selectProjectDir(base: Path) =
|
|
|
|
|
{
|
|
|
|
|
val a = projectHidden(base)
|
|
|
|
|
val b = projectStandard(base)
|
|
|
|
|
if(a.exists) a else b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def crossPath(base: File, instance: ScalaInstance): File = base / ("scala_" + instance.version)
|
|
|
|
|
}
|