diff --git a/compile/ClasspathOptions.scala b/compile/ClasspathOptions.scala index 5f803ef13..edbf1a3d3 100644 --- a/compile/ClasspathOptions.scala +++ b/compile/ClasspathOptions.scala @@ -3,9 +3,12 @@ */ package sbt -final case class ClasspathOptions(bootLibrary: Boolean, compiler: Boolean, extra: Boolean, autoBoot: Boolean) +final case class ClasspathOptions(bootLibrary: Boolean, compiler: Boolean, extra: Boolean, autoBoot: Boolean, filterLibrary: Boolean) object ClasspathOptions { - def manual = ClasspathOptions(false, false, false, true) - def auto = ClasspathOptions(true, true, true, true) + def manual = ClasspathOptions(false, false, false, true, false) + def boot = ClasspathOptions(true, false, false, true, true) + def repl = auto + def javac(compiler: Boolean) = new ClasspathOptions(false, compiler, false, false, false) + def auto = ClasspathOptions(true, true, true, true, true) } \ No newline at end of file diff --git a/compile/CompilerArguments.scala b/compile/CompilerArguments.scala index 15b55f58b..6afc2c956 100644 --- a/compile/CompilerArguments.scala +++ b/compile/CompilerArguments.scala @@ -23,7 +23,7 @@ final class CompilerArguments(scalaInstance: ScalaInstance, cp: ClasspathOptions options ++ outputOption ++ bootClasspathOption ++ classpathOption ++ abs(sources) } def finishClasspath(classpath: Seq[File]): Seq[File] = - classpath ++ include(cp.compiler, scalaInstance.compilerJar) ++ include(cp.extra, scalaInstance.extraJars : _*) + filterLibrary(classpath) ++ include(cp.compiler, scalaInstance.compilerJar) ++ include(cp.extra, scalaInstance.extraJars : _*) private def include(flag: Boolean, jars: File*) = if(flag) jars else Nil protected def abs(files: Seq[File]) = files.map(_.getAbsolutePath).sortWith(_ < _) protected def checkScalaHomeUnset() @@ -43,6 +43,8 @@ final class CompilerArguments(scalaInstance: ScalaInstance, cp: ClasspathOptions else originalBoot } + def filterLibrary(classpath: Seq[File]) = + if(cp.filterLibrary) classpath.filterNot(_.getName contains ScalaArtifacts.LibraryID) else classpath def bootClasspathOption = if(cp.autoBoot) Seq("-bootclasspath", createBootClasspath) else Nil def bootClasspath = if(cp.autoBoot) sbt.IO.pathSplit(createBootClasspath).map(new File(_)).toSeq else Nil } diff --git a/compile/JavaCompiler.scala b/compile/JavaCompiler.scala index 0b7137687..421b0fc30 100644 --- a/compile/JavaCompiler.scala +++ b/compile/JavaCompiler.scala @@ -18,7 +18,7 @@ object JavaCompiler new JavaCompiler { def apply(sources: Seq[File], classpath: Seq[File], outputDirectory: File, options: Seq[String])(implicit log: Logger) { val augmentedClasspath = if(cp.autoBoot) classpath ++ Seq(scalaInstance.libraryJar) else classpath - val javaCp = new ClasspathOptions(false, cp.compiler, false, false) + val javaCp = ClasspathOptions.javac(cp.compiler) val arguments = (new CompilerArguments(scalaInstance, javaCp))(sources, augmentedClasspath, outputDirectory, options) log.debug("running javac with arguments:\n\t" + arguments.mkString("\n\t")) val code: Int = f(arguments, log) diff --git a/compile/src/test/scala/CompileTest.scala b/compile/src/test/scala/CompileTest.scala index 9abda2df7..a27dd7d6a 100644 --- a/compile/src/test/scala/CompileTest.scala +++ b/compile/src/test/scala/CompileTest.scala @@ -58,7 +58,7 @@ object CompileTest extends Specification private def testClasspath(scalaVersion: String) = WithCompiler.launcher { (launch, log) => def compiler(bootLibrary: Boolean, compilerOnClasspath: Boolean): RawCompiler = - new RawCompiler(ScalaInstance(scalaVersion, launch), new ClasspathOptions(bootLibrary, compilerOnClasspath, true, true), log) + new RawCompiler(ScalaInstance(scalaVersion, launch), new ClasspathOptions(bootLibrary, compilerOnClasspath, true, true, true), log) val callback = new xsbti.TestCallback diff --git a/ivy/IvyScala.scala b/ivy/IvyScala.scala index 1e0406138..e5f946be5 100644 --- a/ivy/IvyScala.scala +++ b/ivy/IvyScala.scala @@ -17,6 +17,7 @@ object ScalaArtifacts val Organization = "org.scala-lang" val LibraryID = "scala-library" val CompilerID = "scala-compiler" + def libraryDependency(version: String): ModuleID = ModuleID(Organization, LibraryID, version) } import ScalaArtifacts._ diff --git a/main/ConsoleProject.scala b/main/ConsoleProject.scala index 9fe5db563..7c0688c73 100644 --- a/main/ConsoleProject.scala +++ b/main/ConsoleProject.scala @@ -13,7 +13,7 @@ object ConsoleProject val extracted = Project extract state val bindings = ("currentState" -> state) :: ("extracted" -> extracted ) :: Nil val unit = extracted.currentUnit - val compiler = Compiler.compilers(state.configuration, log).scalac + val compiler = Compiler.compilers(ClasspathOptions.repl)(state.configuration, log).scalac val imports = Load.getImports(unit.unit) ++ Load.importAll(bindings.map(_._1)) val importString = imports.mkString("", ";\n", ";\n\n") val initCommands = importString + extra diff --git a/main/Defaults.scala b/main/Defaults.scala index a115a6987..20453ff4e 100644 --- a/main/Defaults.scala +++ b/main/Defaults.scala @@ -47,13 +47,13 @@ object Defaults extends BuildCommon sbtVersion in GlobalScope <<= appConfiguration { _.provider.id.version }, pollInterval :== 500, logBuffered :== false, + autoScalaLibrary :== true, trapExit :== false, trapExit in run :== true, logBuffered in testOnly :== true, logBuffered in test :== true, traceLevel in console :== Int.MaxValue, traceLevel in consoleProject :== Int.MaxValue, - traceLevel in consoleQuick :== Int.MaxValue, autoCompilerPlugins :== true, internalConfigurationMap :== Configurations.internalMap _, initialize :== (), @@ -137,10 +137,11 @@ object Defaults extends BuildCommon } ) - def compileBase = Seq( - classpathOptions in GlobalScope :== ClasspathOptions.auto, + def compileBase = inTask(console)(compilersSetting :: Nil) ++ Seq( + classpathOptions in GlobalScope :== ClasspathOptions.boot, + classpathOptions in GlobalScope in console :== ClasspathOptions.repl, compileOrder in GlobalScope :== CompileOrder.Mixed, - compilers <<= (scalaInstance, appConfiguration, streams, classpathOptions, javaHome) map { (si, app, s, co, jh) => Compiler.compilers(si, co, jh)(app, s.log) }, + compilersSetting, javacOptions in GlobalScope :== Nil, scalacOptions in GlobalScope :== Nil, scalaInstance <<= scalaInstanceSetting, @@ -149,6 +150,7 @@ object Defaults extends BuildCommon crossTarget <<= (target, scalaInstance, crossPaths)( (t,si,cross) => if(cross) t / ("scala-" + si.actualVersion) else t ), cacheDirectory <<= crossTarget / "cache" ) + def compilersSetting = compilers <<= (scalaInstance, appConfiguration, streams, classpathOptions, javaHome) map { (si, app, s, co, jh) => Compiler.compilers(si, co, jh)(app, s.log) } lazy val configTasks = Seq( initialCommands in GlobalScope :== "", @@ -388,7 +390,7 @@ object Defaults extends BuildCommon def consoleProjectTask = (state, streams, initialCommands in consoleProject) map { (state, s, extra) => ConsoleProject(state, extra)(s.log); println() } def consoleTask: Initialize[Task[Unit]] = consoleTask(fullClasspath, console) def consoleQuickTask = consoleTask(externalDependencyClasspath, consoleQuick) - def consoleTask(classpath: TaskKey[Classpath], task: TaskKey[_]): Initialize[Task[Unit]] = (compilers, classpath, scalacOptions in task, initialCommands in task, streams) map { + def consoleTask(classpath: TaskKey[Classpath], task: TaskKey[_]): Initialize[Task[Unit]] = (compilers in task, classpath, scalacOptions in task, initialCommands in task, streams) map { (cs, cp, options, initCommands, s) => (new Console(cs.scalac))(data(cp), options, initCommands, s.log).foreach(msg => error(msg)) println() @@ -568,6 +570,7 @@ object Classpaths projectResolver <<= projectResolverTask, projectDependencies <<= projectDependenciesTask, libraryDependencies in GlobalScope :== Nil, + libraryDependencies <++= (autoScalaLibrary, scalaVersion) { (auto, sv) => if(auto) ScalaArtifacts.libraryDependency(sv) :: Nil else Nil}, allDependencies <<= (projectDependencies,libraryDependencies,sbtPlugin,sbtDependency) map { (projDeps, libDeps, isPlugin, sbtDep) => val base = projDeps ++ libDeps if(isPlugin) sbtDep +: base else base diff --git a/main/Keys.scala b/main/Keys.scala index 1c619e77b..2dab01ab8 100644 --- a/main/Keys.scala +++ b/main/Keys.scala @@ -115,7 +115,7 @@ object Keys val clean = TaskKey[Unit]("clean", "Deletes files produced by the build, such as generated sources, compiled classes, and task caches.") val console = TaskKey[Unit]("console", "Starts the Scala interpreter with the project classes on the classpath.") - val consoleQuick = TaskKey[Unit]("console-quick", "Starts the Scala interpreter with the project dependencies on the classpath.") + val consoleQuick = TaskKey[Unit]("console-quick", "Starts the Scala interpreter with the project dependencies on the classpath.", console) val consoleProject = TaskKey[Unit]("console-project", "Starts the Scala interpreter with the sbt and the build definition on the classpath and useful imports.") val compile = TaskKey[Analysis]("compile", "Compiles sources.") val compilers = TaskKey[Compiler.Compilers]("compilers", "Defines the Scala and Java compilers to use for compilation.") @@ -245,6 +245,7 @@ object Keys val packagedArtifact = TaskKey[(Artifact, File)]("packaged-artifact", "Generates a packaged artifact, returning the Artifact and the produced File.") val checksums = SettingKey[Seq[String]]("checksums", "The list of checksums to generate and to verify for dependencies.") + val autoScalaLibrary = SettingKey[Boolean]("auto-scala-library", "Adds a dependency on scala-library if true.") val sbtResolver = SettingKey[Resolver]("sbt-resolver", "Provides a resolver for obtaining sbt as a dependency.") val sbtDependency = SettingKey[ModuleID]("sbt-dependency", "Provides a definition for declaring the current version of sbt.") val sbtVersion = SettingKey[String]("sbt-version", "Provides the version of sbt. This setting should be not be modified.") diff --git a/main/Load.scala b/main/Load.scala index db5b00631..7632cfefe 100644 --- a/main/Load.scala +++ b/main/Load.scala @@ -31,7 +31,7 @@ object Load val base = baseDirectory.getCanonicalFile val loader = getClass.getClassLoader val classpath = provider.mainClasspath ++ scalaProvider.jars - val compilers = Compiler.compilers(state.configuration, log) + val compilers = Compiler.compilers(ClasspathOptions.boot)(state.configuration, log) val evalPluginDef = EvaluateTask.evalPluginDef(log) _ val delegates = defaultDelegates val inject: Seq[Project.Setting[_]] = ((appConfiguration in GlobalScope) :== state.configuration) +: EvaluateTask.injectSettings diff --git a/main/actions/Compiler.scala b/main/actions/Compiler.scala index cd45376e5..d1c9e5c7a 100644 --- a/main/actions/Compiler.scala +++ b/main/actions/Compiler.scala @@ -42,17 +42,14 @@ object Compiler new IncSetup(analysisMap, cacheDirectory) ) - def compilers(implicit app: AppConfiguration, log: Logger): Compilers = + def compilers(cpOptions: ClasspathOptions)(implicit app: AppConfiguration, log: Logger): Compilers = { val scalaProvider = app.provider.scalaProvider - compilers(ScalaInstance(scalaProvider.version, scalaProvider.launcher)) + compilers(ScalaInstance(scalaProvider.version, scalaProvider.launcher), cpOptions) } - def compilers(instance: ScalaInstance)(implicit app: AppConfiguration, log: Logger): Compilers = - compilers(instance, ClasspathOptions.auto, None) - - def compilers(instance: ScalaInstance, javac: (Seq[String], Logger) => Int)(implicit app: AppConfiguration, log: Logger): Compilers = - compilers(instance, ClasspathOptions.auto, javac) + def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions)(implicit app: AppConfiguration, log: Logger): Compilers = + compilers(instance, cpOptions, None) def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions, javaHome: Option[File])(implicit app: AppConfiguration, log: Logger): Compilers = {