mirror of https://github.com/sbt/sbt.git
make scalaInstance a task. fixes #127
This commit is contained in:
parent
f52726c221
commit
e75628c81b
|
|
@ -98,7 +98,7 @@ object Defaults extends BuildCommon
|
||||||
def projectCore: Seq[Setting[_]] = Seq(
|
def projectCore: Seq[Setting[_]] = Seq(
|
||||||
name <<= thisProject(_.id),
|
name <<= thisProject(_.id),
|
||||||
logManager <<= extraLoggers(LogManager.defaults),
|
logManager <<= extraLoggers(LogManager.defaults),
|
||||||
runnerSetting
|
runnerTask
|
||||||
)
|
)
|
||||||
def paths = Seq(
|
def paths = Seq(
|
||||||
baseDirectory <<= thisProject(_.base),
|
baseDirectory <<= thisProject(_.base),
|
||||||
|
|
@ -159,7 +159,7 @@ object Defaults extends BuildCommon
|
||||||
scalaInstance <<= scalaInstanceSetting,
|
scalaInstance <<= scalaInstanceSetting,
|
||||||
scalaVersion in GlobalScope <<= appConfiguration( _.provider.scalaProvider.version),
|
scalaVersion in GlobalScope <<= appConfiguration( _.provider.scalaProvider.version),
|
||||||
crossScalaVersions in GlobalScope <<= Seq(scalaVersion).join,
|
crossScalaVersions in GlobalScope <<= Seq(scalaVersion).join,
|
||||||
crossTarget <<= (target, scalaInstance, crossPaths)( (t,si,cross) => if(cross) t / ("scala-" + si.actualVersion) else t ),
|
crossTarget <<= (target, scalaVersion, crossPaths)( (t,sv,cross) => if(cross) t / ("scala-" + sv) 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) }
|
def compilersSetting = compilers <<= (scalaInstance, appConfiguration, streams, classpathOptions, javaHome) map { (si, app, s, co, jh) => Compiler.compilers(si, co, jh)(app, s.log) }
|
||||||
|
|
@ -173,7 +173,7 @@ object Defaults extends BuildCommon
|
||||||
consoleQuick <<= consoleQuickTask,
|
consoleQuick <<= consoleQuickTask,
|
||||||
discoveredMainClasses <<= TaskData.write(compile map discoverMainClasses) triggeredBy compile,
|
discoveredMainClasses <<= TaskData.write(compile map discoverMainClasses) triggeredBy compile,
|
||||||
definedSbtPlugins <<= discoverPlugins,
|
definedSbtPlugins <<= discoverPlugins,
|
||||||
inTask(run)(runnerSetting :: Nil).head,
|
inTask(run)(runnerTask :: Nil).head,
|
||||||
selectMainClass <<= discoveredMainClasses map selectRunMain,
|
selectMainClass <<= discoveredMainClasses map selectRunMain,
|
||||||
mainClass in run <<= (selectMainClass in run).identity,
|
mainClass in run <<= (selectMainClass in run).identity,
|
||||||
mainClass <<= discoveredMainClasses map selectPackageMain,
|
mainClass <<= discoveredMainClasses map selectPackageMain,
|
||||||
|
|
@ -222,7 +222,7 @@ object Defaults extends BuildCommon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def scalaInstanceSetting = (appConfiguration, scalaVersion, scalaHome){ (app, version, home) =>
|
def scalaInstanceSetting = (appConfiguration, scalaVersion, scalaHome) map { (app, version, home) =>
|
||||||
val launcher = app.provider.scalaProvider.launcher
|
val launcher = app.provider.scalaProvider.launcher
|
||||||
home match {
|
home match {
|
||||||
case None => ScalaInstance(version, launcher)
|
case None => ScalaInstance(version, launcher)
|
||||||
|
|
@ -371,7 +371,7 @@ object Defaults extends BuildCommon
|
||||||
IO.delete(clean)
|
IO.delete(clean)
|
||||||
IO.move(mappings.map(_.swap))
|
IO.move(mappings.map(_.swap))
|
||||||
}
|
}
|
||||||
def runMainTask(classpath: ScopedTask[Classpath], scalaRun: ScopedSetting[ScalaRun]): Initialize[InputTask[Unit]] =
|
def runMainTask(classpath: ScopedTask[Classpath], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] =
|
||||||
{
|
{
|
||||||
import DefaultParsers._
|
import DefaultParsers._
|
||||||
InputTask( TaskData(discoveredMainClasses)(runMainParser)(Nil) ) { result =>
|
InputTask( TaskData(discoveredMainClasses)(runMainParser)(Nil) ) { result =>
|
||||||
|
|
@ -381,7 +381,7 @@ object Defaults extends BuildCommon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def runTask(classpath: ScopedTask[Classpath], mainClassTask: ScopedTask[Option[String]], scalaRun: ScopedSetting[ScalaRun]): Initialize[InputTask[Unit]] =
|
def runTask(classpath: ScopedTask[Classpath], mainClassTask: ScopedTask[Option[String]], scalaRun: ScopedTask[ScalaRun]): Initialize[InputTask[Unit]] =
|
||||||
inputTask { result =>
|
inputTask { result =>
|
||||||
(classpath, mainClassTask, scalaRun, streams, result) map { (cp, main, runner, s, args) =>
|
(classpath, mainClassTask, scalaRun, streams, result) map { (cp, main, runner, s, args) =>
|
||||||
val mainClass = main getOrElse error("No main class detected.")
|
val mainClass = main getOrElse error("No main class detected.")
|
||||||
|
|
@ -389,8 +389,8 @@ object Defaults extends BuildCommon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def runnerSetting = runner <<= runnerInit
|
def runnerTask = runner <<= runnerInit
|
||||||
def runnerInit: Initialize[ScalaRun] = (scalaInstance, baseDirectory, javaOptions, outputStrategy, fork, javaHome, trapExit) { (si, base, options, strategy, forkRun, javaHomeDir, trap) =>
|
def runnerInit: Initialize[Task[ScalaRun]] = (scalaInstance, baseDirectory, javaOptions, outputStrategy, fork, javaHome, trapExit) map { (si, base, options, strategy, forkRun, javaHomeDir, trap) =>
|
||||||
if(forkRun) {
|
if(forkRun) {
|
||||||
new ForkRun( ForkOptions(scalaJars = si.jars, javaHome = javaHomeDir, outputStrategy = strategy,
|
new ForkRun( ForkOptions(scalaJars = si.jars, javaHome = javaHomeDir, outputStrategy = strategy,
|
||||||
runJVMOptions = options, workingDirectory = Some(base)) )
|
runJVMOptions = options, workingDirectory = Some(base)) )
|
||||||
|
|
@ -1014,17 +1014,17 @@ trait BuildExtra extends BuildCommon
|
||||||
|
|
||||||
def fullRunInputTask(scoped: ScopedInput[Unit], config: Configuration, mainClass: String, baseArguments: String*): Setting[InputTask[Unit]] =
|
def fullRunInputTask(scoped: ScopedInput[Unit], config: Configuration, mainClass: String, baseArguments: String*): Setting[InputTask[Unit]] =
|
||||||
scoped <<= inputTask { result =>
|
scoped <<= inputTask { result =>
|
||||||
( initScoped(scoped.scoped, runnerInit) zipWith (fullClasspath in config, streams, result).identityMap) { (r, t) =>
|
( initScoped(scoped.scoped, runnerInit) zipWith (fullClasspath in config, streams, result).identityMap) { (rTask, t) =>
|
||||||
t map { case (cp, s, args) =>
|
t map { case (cp, s, args) => rTask map { r =>
|
||||||
toError(r.run(mainClass, data(cp), baseArguments ++ args, s.log))
|
toError(r.run(mainClass, data(cp), baseArguments ++ args, s.log))
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def fullRunTask(scoped: ScopedTask[Unit], config: Configuration, mainClass: String, arguments: String*): Setting[Task[Unit]] =
|
def fullRunTask(scoped: ScopedTask[Unit], config: Configuration, mainClass: String, arguments: String*): Setting[Task[Unit]] =
|
||||||
scoped <<= ( initScoped(scoped.scoped, runnerInit) zipWith (fullClasspath in config, streams).identityMap ) { case (r, t) =>
|
scoped <<= ( initScoped(scoped.scoped, runnerInit) zipWith (fullClasspath in config, streams).identityMap ) { case (rTask, t) =>
|
||||||
t map { case (cp, s) =>
|
t map { case (cp, s) => rTask map { r =>
|
||||||
toError(r.run(mainClass, data(cp), arguments, s.log))
|
toError(r.run(mainClass, data(cp), arguments, s.log))
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
def initScoped[T](sk: ScopedKey[_], i: Initialize[T]): Initialize[T] = initScope(fillTaskAxis(sk.scope, sk.key), i)
|
def initScoped[T](sk: ScopedKey[_], i: Initialize[T]): Initialize[T] = initScope(fillTaskAxis(sk.scope, sk.key), i)
|
||||||
def initScope[T](s: Scope, i: Initialize[T]): Initialize[T] = i mapReferenced Project.mapScope(Scope.replaceThis(s))
|
def initScope[T](s: Scope, i: Initialize[T]): Initialize[T] = i mapReferenced Project.mapScope(Scope.replaceThis(s))
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ object Keys
|
||||||
val initialCommands = SettingKey[String]("initial-commands", "Initial commands to execute when starting up the Scala interpreter.")
|
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.")
|
val compileInputs = TaskKey[Compiler.Inputs]("compile-inputs", "Collects all inputs needed for compilation.")
|
||||||
val scalaHome = SettingKey[Option[File]]("scala-home", "If Some, defines the local Scala installation to use for compilation, running, and testing.")
|
val scalaHome = SettingKey[Option[File]]("scala-home", "If Some, defines the local Scala installation to use for compilation, running, and testing.")
|
||||||
val scalaInstance = SettingKey[ScalaInstance]("scala-instance", "Defines the Scala instance to use for compilation, running, and testing.")
|
val scalaInstance = TaskKey[ScalaInstance]("scala-instance", "Defines the Scala instance to use for compilation, running, and testing.")
|
||||||
val scalaVersion = SettingKey[String]("scala-version", "The version of Scala used for building.")
|
val scalaVersion = SettingKey[String]("scala-version", "The version of Scala used for building.")
|
||||||
val crossScalaVersions = SettingKey[Seq[String]]("cross-scala-versions", "The versions of Scala used when cross-building.")
|
val crossScalaVersions = SettingKey[Seq[String]]("cross-scala-versions", "The versions of Scala used when cross-building.")
|
||||||
val classpathOptions = SettingKey[ClasspathOptions]("classpath-options", "Configures handling of Scala classpaths.")
|
val classpathOptions = SettingKey[ClasspathOptions]("classpath-options", "Configures handling of Scala classpaths.")
|
||||||
|
|
@ -148,7 +148,7 @@ object Keys
|
||||||
val run = InputKey[Unit]("run", "Runs a main class, passing along arguments provided on the command line.")
|
val run = InputKey[Unit]("run", "Runs a main class, passing along arguments provided on the command line.")
|
||||||
val runMain = InputKey[Unit]("run-main", "Runs the main class selected by the first argument, passing the remaining arguments to the main method.")
|
val runMain = InputKey[Unit]("run-main", "Runs the main class selected by the first argument, passing the remaining arguments to the main method.")
|
||||||
val discoveredMainClasses = TaskKey[Seq[String]]("discovered-main-classes", "Auto-detects main classes.")
|
val discoveredMainClasses = TaskKey[Seq[String]]("discovered-main-classes", "Auto-detects main classes.")
|
||||||
val runner = SettingKey[ScalaRun]("runner", "Implementation used to run a main class.")
|
val runner = TaskKey[ScalaRun]("runner", "Implementation used to run a main class.")
|
||||||
val trapExit = SettingKey[Boolean]("trap-exit", "If true, enables exit trapping and thread management for 'run'-like tasks. This is currently only suitable for serially-executed 'run'-like tasks.")
|
val trapExit = SettingKey[Boolean]("trap-exit", "If true, enables exit trapping and thread management for 'run'-like tasks. This is currently only suitable for serially-executed 'run'-like tasks.")
|
||||||
|
|
||||||
val fork = SettingKey[Boolean]("fork", "If true, forks a new JVM when running. If false, runs in the same JVM as the build.")
|
val fork = SettingKey[Boolean]("fork", "If true, forks a new JVM when running. If false, runs in the same JVM as the build.")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue