mirror of https://github.com/sbt/sbt.git
settle scala-library situation
This commit is contained in:
parent
e840d66622
commit
85a55c25bf
|
|
@ -3,9 +3,12 @@
|
||||||
*/
|
*/
|
||||||
package sbt
|
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
|
object ClasspathOptions
|
||||||
{
|
{
|
||||||
def manual = ClasspathOptions(false, false, false, true)
|
def manual = ClasspathOptions(false, false, false, true, false)
|
||||||
def auto = ClasspathOptions(true, true, true, true)
|
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)
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ final class CompilerArguments(scalaInstance: ScalaInstance, cp: ClasspathOptions
|
||||||
options ++ outputOption ++ bootClasspathOption ++ classpathOption ++ abs(sources)
|
options ++ outputOption ++ bootClasspathOption ++ classpathOption ++ abs(sources)
|
||||||
}
|
}
|
||||||
def finishClasspath(classpath: Seq[File]): Seq[File] =
|
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
|
private def include(flag: Boolean, jars: File*) = if(flag) jars else Nil
|
||||||
protected def abs(files: Seq[File]) = files.map(_.getAbsolutePath).sortWith(_ < _)
|
protected def abs(files: Seq[File]) = files.map(_.getAbsolutePath).sortWith(_ < _)
|
||||||
protected def checkScalaHomeUnset()
|
protected def checkScalaHomeUnset()
|
||||||
|
|
@ -43,6 +43,8 @@ final class CompilerArguments(scalaInstance: ScalaInstance, cp: ClasspathOptions
|
||||||
else
|
else
|
||||||
originalBoot
|
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 bootClasspathOption = if(cp.autoBoot) Seq("-bootclasspath", createBootClasspath) else Nil
|
||||||
def bootClasspath = if(cp.autoBoot) sbt.IO.pathSplit(createBootClasspath).map(new File(_)).toSeq else Nil
|
def bootClasspath = if(cp.autoBoot) sbt.IO.pathSplit(createBootClasspath).map(new File(_)).toSeq else Nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ object JavaCompiler
|
||||||
new JavaCompiler {
|
new JavaCompiler {
|
||||||
def apply(sources: Seq[File], classpath: Seq[File], outputDirectory: File, options: Seq[String])(implicit log: Logger) {
|
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 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)
|
val arguments = (new CompilerArguments(scalaInstance, javaCp))(sources, augmentedClasspath, outputDirectory, options)
|
||||||
log.debug("running javac with arguments:\n\t" + arguments.mkString("\n\t"))
|
log.debug("running javac with arguments:\n\t" + arguments.mkString("\n\t"))
|
||||||
val code: Int = f(arguments, log)
|
val code: Int = f(arguments, log)
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ object CompileTest extends Specification
|
||||||
private def testClasspath(scalaVersion: String) =
|
private def testClasspath(scalaVersion: String) =
|
||||||
WithCompiler.launcher { (launch, log) =>
|
WithCompiler.launcher { (launch, log) =>
|
||||||
def compiler(bootLibrary: Boolean, compilerOnClasspath: Boolean): RawCompiler =
|
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
|
val callback = new xsbti.TestCallback
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ object ScalaArtifacts
|
||||||
val Organization = "org.scala-lang"
|
val Organization = "org.scala-lang"
|
||||||
val LibraryID = "scala-library"
|
val LibraryID = "scala-library"
|
||||||
val CompilerID = "scala-compiler"
|
val CompilerID = "scala-compiler"
|
||||||
|
def libraryDependency(version: String): ModuleID = ModuleID(Organization, LibraryID, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
import ScalaArtifacts._
|
import ScalaArtifacts._
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ object ConsoleProject
|
||||||
val extracted = Project extract state
|
val extracted = Project extract state
|
||||||
val bindings = ("currentState" -> state) :: ("extracted" -> extracted ) :: Nil
|
val bindings = ("currentState" -> state) :: ("extracted" -> extracted ) :: Nil
|
||||||
val unit = extracted.currentUnit
|
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 imports = Load.getImports(unit.unit) ++ Load.importAll(bindings.map(_._1))
|
||||||
val importString = imports.mkString("", ";\n", ";\n\n")
|
val importString = imports.mkString("", ";\n", ";\n\n")
|
||||||
val initCommands = importString + extra
|
val initCommands = importString + extra
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,13 @@ object Defaults extends BuildCommon
|
||||||
sbtVersion in GlobalScope <<= appConfiguration { _.provider.id.version },
|
sbtVersion in GlobalScope <<= appConfiguration { _.provider.id.version },
|
||||||
pollInterval :== 500,
|
pollInterval :== 500,
|
||||||
logBuffered :== false,
|
logBuffered :== false,
|
||||||
|
autoScalaLibrary :== true,
|
||||||
trapExit :== false,
|
trapExit :== false,
|
||||||
trapExit in run :== true,
|
trapExit in run :== true,
|
||||||
logBuffered in testOnly :== true,
|
logBuffered in testOnly :== true,
|
||||||
logBuffered in test :== true,
|
logBuffered in test :== true,
|
||||||
traceLevel in console :== Int.MaxValue,
|
traceLevel in console :== Int.MaxValue,
|
||||||
traceLevel in consoleProject :== Int.MaxValue,
|
traceLevel in consoleProject :== Int.MaxValue,
|
||||||
traceLevel in consoleQuick :== Int.MaxValue,
|
|
||||||
autoCompilerPlugins :== true,
|
autoCompilerPlugins :== true,
|
||||||
internalConfigurationMap :== Configurations.internalMap _,
|
internalConfigurationMap :== Configurations.internalMap _,
|
||||||
initialize :== (),
|
initialize :== (),
|
||||||
|
|
@ -137,10 +137,11 @@ object Defaults extends BuildCommon
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def compileBase = Seq(
|
def compileBase = inTask(console)(compilersSetting :: Nil) ++ Seq(
|
||||||
classpathOptions in GlobalScope :== ClasspathOptions.auto,
|
classpathOptions in GlobalScope :== ClasspathOptions.boot,
|
||||||
|
classpathOptions in GlobalScope in console :== ClasspathOptions.repl,
|
||||||
compileOrder in GlobalScope :== CompileOrder.Mixed,
|
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,
|
javacOptions in GlobalScope :== Nil,
|
||||||
scalacOptions in GlobalScope :== Nil,
|
scalacOptions in GlobalScope :== Nil,
|
||||||
scalaInstance <<= scalaInstanceSetting,
|
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 ),
|
crossTarget <<= (target, scalaInstance, crossPaths)( (t,si,cross) => if(cross) t / ("scala-" + si.actualVersion) else t ),
|
||||||
cacheDirectory <<= crossTarget / "cache"
|
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(
|
lazy val configTasks = Seq(
|
||||||
initialCommands in GlobalScope :== "",
|
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 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 consoleTask: Initialize[Task[Unit]] = consoleTask(fullClasspath, console)
|
||||||
def consoleQuickTask = consoleTask(externalDependencyClasspath, consoleQuick)
|
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) =>
|
(cs, cp, options, initCommands, s) =>
|
||||||
(new Console(cs.scalac))(data(cp), options, initCommands, s.log).foreach(msg => error(msg))
|
(new Console(cs.scalac))(data(cp), options, initCommands, s.log).foreach(msg => error(msg))
|
||||||
println()
|
println()
|
||||||
|
|
@ -568,6 +570,7 @@ object Classpaths
|
||||||
projectResolver <<= projectResolverTask,
|
projectResolver <<= projectResolverTask,
|
||||||
projectDependencies <<= projectDependenciesTask,
|
projectDependencies <<= projectDependenciesTask,
|
||||||
libraryDependencies in GlobalScope :== Nil,
|
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) =>
|
allDependencies <<= (projectDependencies,libraryDependencies,sbtPlugin,sbtDependency) map { (projDeps, libDeps, isPlugin, sbtDep) =>
|
||||||
val base = projDeps ++ libDeps
|
val base = projDeps ++ libDeps
|
||||||
if(isPlugin) sbtDep +: base else base
|
if(isPlugin) sbtDep +: base else base
|
||||||
|
|
|
||||||
|
|
@ -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 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 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 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 compile = TaskKey[Analysis]("compile", "Compiles sources.")
|
||||||
val compilers = TaskKey[Compiler.Compilers]("compilers", "Defines the Scala and Java compilers to use for compilation.")
|
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 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 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 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 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.")
|
val sbtVersion = SettingKey[String]("sbt-version", "Provides the version of sbt. This setting should be not be modified.")
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ object Load
|
||||||
val base = baseDirectory.getCanonicalFile
|
val base = baseDirectory.getCanonicalFile
|
||||||
val loader = getClass.getClassLoader
|
val loader = getClass.getClassLoader
|
||||||
val classpath = provider.mainClasspath ++ scalaProvider.jars
|
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 evalPluginDef = EvaluateTask.evalPluginDef(log) _
|
||||||
val delegates = defaultDelegates
|
val delegates = defaultDelegates
|
||||||
val inject: Seq[Project.Setting[_]] = ((appConfiguration in GlobalScope) :== state.configuration) +: EvaluateTask.injectSettings
|
val inject: Seq[Project.Setting[_]] = ((appConfiguration in GlobalScope) :== state.configuration) +: EvaluateTask.injectSettings
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,14 @@ object Compiler
|
||||||
new IncSetup(analysisMap, cacheDirectory)
|
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
|
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 =
|
def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions)(implicit app: AppConfiguration, log: Logger): Compilers =
|
||||||
compilers(instance, ClasspathOptions.auto, None)
|
compilers(instance, cpOptions, 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, javaHome: Option[File])(implicit app: AppConfiguration, log: Logger): Compilers =
|
def compilers(instance: ScalaInstance, cpOptions: ClasspathOptions, javaHome: Option[File])(implicit app: AppConfiguration, log: Logger): Compilers =
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue