Skip to content

Commit

Permalink
Revert "scalacOptions, javacOptions in Compile in project/plugins/ af…
Browse files Browse the repository at this point in the history
…fect build definitions"

This reverts commit 5793a3c66cd47087562072b69fb21d262cbbd0bc in favor of migrating project/plugins/
  to project/, which makes project/ a proper project.

Conflicts:

	main/Load.scala
  • Loading branch information
harrah committed Sep 3, 2011
1 parent a824aa9 commit 14bf088
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
25 changes: 7 additions & 18 deletions main/EvaluateTask.scala
Expand Up @@ -12,8 +12,8 @@ package sbt

object EvaluateTask
{
import Load.{BuildStructure, PluginData}
import Project.{display, Initialize}
import Load.BuildStructure
import Project.display
import std.{TaskExtra,Transform}
import TaskExtra._
import Keys.state
Expand All @@ -25,24 +25,13 @@ object EvaluateTask
(streamsManager in GlobalScope) ::= dummyStreamsManager
)

def evalPluginDef(log: Logger)(pluginDef: BuildStructure, state: State): PluginData =
def evalPluginDef(log: Logger)(pluginDef: BuildStructure, state: State): Seq[Attributed[File]] =
{
import Keys.{fullClasspath, javacOptions, scalacOptions}
import Configurations.{Compile, Runtime}
import Scoped._

val root = ProjectRef(pluginDef.root, Load.getRootProject(pluginDef.units)(pluginDef.root))
val init = (fullClasspath in Runtime, scalacOptions in Compile, javacOptions in Compile) map { (cp, so, jo) => new PluginData(cp, so, jo) }
processResult(evaluateInitTask(pluginDef, init, state, root), log)
}
def evaluateInitTask[T](structure: BuildStructure, init: Initialize[Task[T]], state: State, ref: ProjectRef, checkCycles: Boolean = false, maxWorkers: Int = SystemProcessors): Result[T] =
{
val resolveThis = Project.mapScope( Scope.replaceThis(Load.projectScope(ref)) )
val task = init mapReferenced resolveThis evaluate structure.data
withStreams(structure) { str =>
val toNode = nodeView(state, str)
runTask(task, str, structure.index.triggers, checkCycles, maxWorkers)(toNode)
}
val pluginKey = Keys.fullClasspath in Configurations.Runtime
val evaluated = evaluateTask(pluginDef, ScopedKey(pluginKey.scope, pluginKey.key), state, root)
val result = evaluated getOrElse error("Plugin classpath does not exist for plugin definition at " + pluginDef.root)
processResult(result, log)
}
def evaluateTask[T](structure: BuildStructure, taskKey: ScopedKey[Task[T]], state: State, ref: ProjectRef, checkCycles: Boolean = false, maxWorkers: Int = SystemProcessors): Option[Result[T]] =
withStreams(structure) { str =>
Expand Down
2 changes: 1 addition & 1 deletion main/Keys.scala
Expand Up @@ -116,7 +116,7 @@ object Keys
val maxErrors = SettingKey[Int]("max-errors", "The maximum number of errors, such as compile errors, to list.")
val scaladocOptions = TaskKey[Seq[String]]("scaladoc-options", "Options for Scaladoc.")
val scalacOptions = TaskKey[Seq[String]]("scalac-options", "Options for the Scala compiler.")
val javacOptions = TaskKey[Seq[String]]("javac-options", "Options for the Java compiler.")
val javacOptions = SettingKey[Seq[String]]("javac-options", "Options for the Java compiler.")
val compileOrder = SettingKey[CompileOrder.Value]("compile-order", "Configures the order in which Java and sources within a single compilation are compiled. Valid values are: JavaThenScala, ScalaThenJava, or Mixed.")
val initialCommands = SettingKey[String]("initial-commands", "Initial commands to execute when starting up the Scala interpreter.")
val compileInputs = TaskKey[Compiler.Inputs]("compile-inputs", "Collects all inputs needed for compilation.")
Expand Down
31 changes: 15 additions & 16 deletions main/Load.scala
Expand Up @@ -416,27 +416,28 @@ object Load
buildPlugins(dir, s, enableSbtPlugin(activateGlobalPlugin(config)))
else
noPlugins(dir, config)

def hasDefinition(dir: File) =
{
import Path._
!(dir * -GlobFilter(DefaultTargetName)).get.isEmpty
}
def noPlugins(dir: File, config: LoadBuildConfiguration): LoadedPlugins = loadPluginDefinition(dir, config, new PluginData(config.globalPluginClasspath, Nil, Nil))
def noPlugins(dir: File, config: LoadBuildConfiguration): LoadedPlugins = loadPluginDefinition(dir, config, config.globalPluginClasspath)
def buildPlugins(dir: File, s: State, config: LoadBuildConfiguration): LoadedPlugins =
loadPluginDefinition(dir, config, buildPluginDefinition(dir, s, config))

def loadPluginDefinition(dir: File, config: LoadBuildConfiguration, data: PluginData): LoadedPlugins =
def loadPluginDefinition(dir: File, config: LoadBuildConfiguration, pluginClasspath: Seq[Attributed[File]]): LoadedPlugins =
{
val (definitionClasspath, pluginLoader) = pluginDefinitionLoader(config, data.classpath)
loadPlugins(dir, data.copy(classpath = definitionClasspath), pluginLoader)
val (definitionClasspath, pluginLoader) = pluginDefinitionLoader(config, pluginClasspath)
loadPlugins(dir, definitionClasspath, pluginLoader)
}
def pluginDefinitionLoader(config: LoadBuildConfiguration, pluginClasspath: Seq[Attributed[File]]): (Seq[Attributed[File]], ClassLoader) =
{
val definitionClasspath = if(pluginClasspath.isEmpty) config.classpath else (pluginClasspath ++ config.classpath).distinct
val pluginLoader = if(pluginClasspath.isEmpty) config.loader else ClasspathUtilities.toLoader(data(pluginClasspath), config.loader)
(definitionClasspath, pluginLoader)
}
def buildPluginDefinition(dir: File, s: State, config: LoadBuildConfiguration): PluginData =
def buildPluginDefinition(dir: File, s: State, config: LoadBuildConfiguration): Seq[Attributed[File]] =
{
val (eval,pluginDef) = apply(dir, s, config)
val pluginState = Project.setProject(Load.initialSession(pluginDef, eval), pluginDef, s)
Expand All @@ -445,7 +446,7 @@ object Load

def definitions(base: File, targetBase: File, srcs: Seq[File], plugins: LoadedPlugins, definesClass: DefinesClass, compilers: Compilers, log: Logger): LoadedDefinitions =
{
val (inputs, defAnalysis) = build(plugins.pluginData, srcs, targetBase, compilers, definesClass, log)
val (inputs, defAnalysis) = build(plugins.fullClasspath, srcs, targetBase, compilers, definesClass, log)
val target = inputs.config.classesDirectory
val definitionLoader = ClasspathUtilities.toLoader(target :: Nil, plugins.loader)
val defNames = findDefinitions(defAnalysis)
Expand All @@ -458,23 +459,23 @@ object Load
def loadDefinition(loader: ClassLoader, definition: String): Build =
ModuleUtilities.getObject(definition, loader).asInstanceOf[Build]

def build(pd: PluginData, sources: Seq[File], target: File, compilers: Compilers, definesClass: DefinesClass, log: Logger): (Inputs, inc.Analysis) =
def build(classpath: Seq[Attributed[File]], sources: Seq[File], target: File, compilers: Compilers, definesClass: DefinesClass, log: Logger): (Inputs, inc.Analysis) =
{
// TODO: make used of classpath metadata for recompilation
val inputs = Compiler.inputs(data(pd.classpath), sources, target, pd.scalacOptions, pd.javacOptions, definesClass, Compiler.DefaultMaxErrors, CompileOrder.Mixed)(compilers, log)
val inputs = Compiler.inputs(data(classpath), sources, target, Nil, Nil, definesClass, Compiler.DefaultMaxErrors, CompileOrder.Mixed)(compilers, log)
val analysis =
try { Compiler(inputs, log) }
catch { case _: xsbti.CompileFailed => throw new NoMessageException } // compiler already logged errors
(inputs, analysis)
}

def loadPlugins(dir: File, data: PluginData, loader: ClassLoader): LoadedPlugins =
def loadPlugins(dir: File, classpath: Seq[Attributed[File]], loader: ClassLoader): LoadedPlugins =
{
val (pluginNames, plugins) = if(data.classpath.isEmpty) (Nil, Nil) else {
val names = getPluginNames(data.classpath, loader)
val (pluginNames, plugins) = if(classpath.isEmpty) (Nil, Nil) else {
val names = getPluginNames(classpath, loader)
(names, loadPlugins(loader, names) )
}
new LoadedPlugins(dir, data, loader, plugins, pluginNames)
new LoadedPlugins(dir, classpath, loader, plugins, pluginNames)
}
def getPluginNames(classpath: Seq[Attributed[File]], loader: ClassLoader): Seq[String] =
( binaryPlugins(loader) ++ (analyzed(classpath) flatMap findPlugins) ).distinct
Expand Down Expand Up @@ -520,9 +521,8 @@ object Load

final class EvaluatedConfigurations(val eval: Eval, val settings: Seq[Setting[_]])
final class LoadedDefinitions(val base: File, val target: Seq[File], val loader: ClassLoader, val builds: Seq[Build], val buildNames: Seq[String])
final class LoadedPlugins(val base: File, val pluginData: PluginData, val loader: ClassLoader, val plugins: Seq[Setting[_]], val pluginNames: Seq[String])
final class LoadedPlugins(val base: File, val fullClasspath: Seq[Attributed[File]], val loader: ClassLoader, val plugins: Seq[Setting[_]], val pluginNames: Seq[String])
{
def fullClasspath: Seq[Attributed[File]] = pluginData.classpath
def classpath = data(fullClasspath)
}
final class BuildUnit(val uri: URI, val localBase: File, val definitions: LoadedDefinitions, val plugins: LoadedPlugins)
Expand Down Expand Up @@ -575,13 +575,12 @@ object Load
def allProjectRefs(build: URI): Seq[ProjectRef] = refs(build, allProjects(build))
private[this] def refs(build: URI, projects: Seq[ResolvedProject]): Seq[ProjectRef] = projects.map { p => ProjectRef(build, p.id) }
}
final case class LoadBuildConfiguration(stagingDirectory: File, classpath: Seq[Attributed[File]], loader: ClassLoader, compilers: Compilers, evalPluginDef: (BuildStructure, State) => PluginData, definesClass: DefinesClass, delegates: LoadedBuild => Scope => Seq[Scope], scopeLocal: ScopeLocal, injectSettings: InjectSettings, globalPlugin: Option[GlobalPlugin], log: Logger)
final case class LoadBuildConfiguration(stagingDirectory: File, classpath: Seq[Attributed[File]], loader: ClassLoader, compilers: Compilers, evalPluginDef: (BuildStructure, State) => Seq[Attributed[File]], definesClass: DefinesClass, delegates: LoadedBuild => Scope => Seq[Scope], scopeLocal: ScopeLocal, injectSettings: InjectSettings, globalPlugin: Option[GlobalPlugin], log: Logger)
{
lazy val (globalPluginClasspath, globalPluginLoader) = pluginDefinitionLoader(this, Load.globalPluginClasspath(globalPlugin))
lazy val globalPluginNames = if(globalPluginClasspath.isEmpty) Nil else getPluginNames(globalPluginClasspath, globalPluginLoader)
}
final case class InjectSettings(global: Seq[Setting[_]], project: Seq[Setting[_]], projectLoaded: ClassLoader => Seq[Setting[_]])
final case class PluginData(classpath: Seq[Attributed[File]], scalacOptions: Seq[String], javacOptions: Seq[String])

// information that is not original, but can be reconstructed from the rest of BuildStructure
final class StructureIndex(val keyMap: Map[String, AttributeKey[_]], val taskToKey: Map[Task[_], ScopedKey[Task[_]]], val triggers: Triggers[Task], val keyIndex: KeyIndex)
Expand Down

0 comments on commit 14bf088

Please sign in to comment.