Merge branch '1.0.x' into wip/fix-2551

This commit is contained in:
Eric K Richardson 2017-02-14 10:39:24 -05:00 committed by GitHub
commit 3c0257d11c
31 changed files with 131 additions and 103 deletions

View File

@ -1,7 +1,7 @@
Migration notes
===============
- Build definition is based on Scala 2.11.8
- Build definition is based on Scala 2.12.1
- Build.scala style builds are gone. Use multi-project `build.sbt`.
- `Project(...)` constructor is restricted down to two parameters. Use `project` instead.
- `sbt.Plugin` is also gone. Use auto plugins.
@ -13,10 +13,3 @@ Migration notes
- Renames early command feature from `--<command>` to `early(<command>)`.
- Log options `-error`, `-warn`, `-info`, `-debug` are added as shorthand for `"early(error)"` etc.
- `sbt.Process` and `sbt.ProcessExtra` are gone. Use `scala.sys.process` instead.
#### Additional import required
Implicit conversions are moved to `sbt.syntax`. Add the following imports to auto plugins
or `project/*.scala`.
import sbt._, syntax._, Keys._

View File

@ -4,6 +4,8 @@ import java.io.File
import Def.Classpath
import scala.annotation.implicitNotFound
import sbt.internal.util.Attributed
import Def.Initialize
import reflect.internal.annotations.compileTimeOnly
object Append {
@implicitNotFound(msg = "No implicit for Append.Value[${A}, ${B}] found,\n so ${B} cannot be appended to ${A}")
@ -24,6 +26,14 @@ object Append {
def appendValues(a: Seq[T], b: Seq[V]): Seq[T] = a ++ (b map { x => (x: T) })
def appendValue(a: Seq[T], b: V): Seq[T] = a :+ (b: T)
}
@compileTimeOnly("This can be used in += only.")
implicit def appendTaskValueSeq[T, V <: T]: Value[Seq[Task[T]], Initialize[Task[V]]] = new Value[Seq[Task[T]], Initialize[Task[V]]] {
def appendValue(a: Seq[Task[T]], b: Initialize[Task[V]]): Seq[Task[T]] = ???
}
@compileTimeOnly("This can be used in += only.")
implicit def appendTaskKeySeq[T, V <: T]: Value[Seq[Task[T]], TaskKey[V]] = new Value[Seq[Task[T]], TaskKey[V]] {
def appendValue(a: Seq[Task[T]], b: TaskKey[V]): Seq[Task[T]] = ???
}
implicit def appendList[T, V <: T]: Sequence[List[T], List[V], V] = new Sequence[List[T], List[V], V] {
def appendValues(a: List[T], b: List[V]): List[T] = a ::: b
def appendValue(a: List[T], b: V): List[T] = a :+ b

View File

@ -161,9 +161,23 @@ object TaskMacro {
/** Implementation of += macro for settings. */
def settingAppend1Impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: blackbox.Context)(v: c.Expr[U])(a: c.Expr[Append.Value[T, U]]): c.Expr[Setting[T]] =
{
val init = SettingMacro.settingMacroImpl[U](c)(v)
val append = appendMacroImpl(c)(init.tree, a.tree)(Append1InitName)
c.Expr[Setting[T]](append)
import c.universe._
val ttpe = c.weakTypeOf[T]
val typeArgs = ttpe.typeArgs
v.tree.tpe match {
// To allow Initialize[Task[A]] in the position of += RHS, we're going to call "taskValue" automatically.
case tpe if typeArgs.nonEmpty && (tpe weak_<:< c.weakTypeOf[Initialize[_]]) =>
c.macroApplication match {
case Apply(Apply(TypeApply(Select(preT, nmeT), targs), _), _) =>
val tree = Apply(TypeApply(Select(preT, TermName("+=").encodedName), TypeTree(typeArgs.head) :: Nil), Select(v.tree, TermName("taskValue").encodedName) :: Nil)
c.Expr[Setting[T]](tree)
case x => ContextUtil.unexpectedTree(x)
}
case _ =>
val init = SettingMacro.settingMacroImpl[U](c)(v)
val append = appendMacroImpl(c)(init.tree, a.tree)(Append1InitName)
c.Expr[Setting[T]](append)
}
}
/** Implementation of ++= macro for tasks. */
def taskAppendNImpl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: blackbox.Context)(vs: c.Expr[U])(a: c.Expr[Append.Values[T, U]]): c.Expr[Setting[Task[T]]] =
@ -179,7 +193,6 @@ object TaskMacro {
val append = appendMacroImpl(c)(init.tree, a.tree)(AppendNInitName)
c.Expr[Setting[T]](append)
}
/** Implementation of -= macro for tasks. */
def taskRemove1Impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: blackbox.Context)(v: c.Expr[U])(r: c.Expr[Remove.Value[T, U]]): c.Expr[Setting[Task[T]]] =
{
@ -213,8 +226,8 @@ object TaskMacro {
{
import c.universe._
c.macroApplication match {
case Apply(Apply(TypeApply(Select(preT, nmeT), targs), _), a) =>
Apply(Apply(TypeApply(Select(preT, TermName(newName).encodedName), targs), init :: sourcePosition(c).tree :: Nil), a)
case Apply(Apply(TypeApply(Select(preT, nmeT), targs), _), _) =>
Apply(Apply(TypeApply(Select(preT, TermName(newName).encodedName), targs), init :: sourcePosition(c).tree :: Nil), append :: Nil)
case x => ContextUtil.unexpectedTree(x)
}
}

View File

@ -262,7 +262,7 @@ object Defaults extends BuildCommon {
unmanagedResources := collectFiles(unmanagedResourceDirectories, includeFilter in unmanagedResources, excludeFilter in unmanagedResources).value,
watchSources in ConfigGlobal ++= unmanagedResources.value,
resourceGenerators :== Nil,
resourceGenerators += (Def.task { PluginDiscovery.writeDescriptors(discoveredSbtPlugins.value, resourceManaged.value) }).taskValue,
resourceGenerators += Def.task { PluginDiscovery.writeDescriptors(discoveredSbtPlugins.value, resourceManaged.value) },
managedResources := generate(resourceGenerators).value,
resources := Classpaths.concat(managedResources, unmanagedResources).value
)

View File

@ -323,7 +323,7 @@ object Keys {
val classpathConfiguration = TaskKey[Configuration]("classpath-configuration", "The configuration used to define the classpath.", CTask)
val ivyConfiguration = TaskKey[IvyConfiguration]("ivy-configuration", "General dependency management (Ivy) settings, such as the resolvers and paths to use.", DTask)
val ivyConfigurations = SettingKey[Seq[Configuration]]("ivy-configurations", "The defined configurations for dependency management. This may be different from the configurations for Project settings.", BSetting)
// This setting was created to workaround the limitation of derived tasks not being able to use task-scoped task: ivyConfiguration in updateSbtClassifiers
// This setting was created to work around the limitation of derived tasks not being able to use task-scoped task: ivyConfiguration in updateSbtClassifiers
val bootIvyConfiguration = TaskKey[IvyConfiguration]("boot-ivy-configuration", "General dependency management (Ivy) settings, configured to retrieve sbt's components.", DTask)
val moduleSettings = TaskKey[ModuleSettings]("module-settings", "Module settings, which configure dependency management for a specific module, such as a project.", DTask)
val unmanagedBase = SettingKey[File]("unmanaged-base", "The default directory for manually managed libraries.", ASetting)
@ -417,7 +417,7 @@ object Keys {
val managedScalaInstance = SettingKey[Boolean]("managed-scala-instance", "Automatically obtains Scala tools as managed dependencies if true.", BSetting)
val sbtResolver = SettingKey[Resolver]("sbt-resolver", "Provides a resolver for obtaining sbt as a dependency.", BMinusSetting)
val sbtDependency = SettingKey[ModuleID]("sbt-dependency", "Provides a definition for declaring the current version of sbt.", BMinusSetting)
val sbtVersion = SettingKey[String]("sbt-version", "Provides the version of sbt. This setting should be not be modified.", AMinusSetting)
val sbtVersion = SettingKey[String]("sbt-version", "Provides the version of sbt. This setting should not be modified.", AMinusSetting)
val sbtBinaryVersion = SettingKey[String]("sbt-binary-version", "Defines the binary compatibility version substring.", BPlusSetting)
val skip = TaskKey[Boolean]("skip", "For tasks that support it (currently only 'compile' and 'update'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.", BSetting)
val templateResolverInfos = SettingKey[Seq[TemplateResolverInfo]]("templateResolverInfos", "Template resolvers used for 'new'.", BSetting)

View File

@ -73,7 +73,7 @@ object BuildUtil {
}
}
def baseImports: Seq[String] = "import scala.xml.{TopScope=>$scope}" :: "import sbt._, Keys._, syntax._" :: Nil
def baseImports: Seq[String] = "import _root_.scala.xml.{TopScope=>$scope}" :: "import _root_.sbt._" :: "import _root_.sbt.Keys._" :: Nil
def getImports(unit: BuildUnit): Seq[String] = unit.plugins.detected.imports ++ unit.definitions.dslDefinitions.imports

View File

@ -0,0 +1,17 @@
package sbt
// Todo share this this io.syntax
private[sbt] trait IOSyntax0 extends IOSyntax1 {
implicit def alternative[A, B](f: A => Option[B]): Alternative[A, B] =
new Alternative[A, B] {
def |(g: A => Option[B]) =
(a: A) => f(a) orElse g(a)
}
}
private[sbt] trait Alternative[A, B] {
def |(g: A => Option[B]): A => Option[B]
}
private[sbt] trait IOSyntax1 {
implicit def singleFileFinder(file: File): sbt.io.PathFinder = sbt.io.PathFinder(file)
}

View File

@ -1,4 +1,48 @@
/* sbt -- Simple Build Tool
* Copyright 2010, 2011 Mark Harrah
*/
package object sbt extends Import
package object sbt extends sbt.IOSyntax0
with sbt.std.TaskExtra
with sbt.internal.util.Types
with sbt.internal.librarymanagement.impl.DependencyBuilders
with sbt.ProjectExtra
with sbt.internal.librarymanagement.DependencyFilterExtra
with sbt.BuildExtra
with sbt.TaskMacroExtra
with sbt.ScopeFilter.Make
with sbt.BuildSyntax
with sbt.Import {
// IO
def uri(s: String): URI = new URI(s)
def file(s: String): File = new File(s)
def url(s: String): URL = new URL(s)
implicit def fileToRichFile(file: File): sbt.io.RichFile = new sbt.io.RichFile(file)
implicit def filesToFinder(cc: Traversable[File]): sbt.io.PathFinder = sbt.io.PathFinder.strict(cc)
// others
object CompileOrder {
val JavaThenScala = xsbti.compile.CompileOrder.JavaThenScala
val ScalaThenJava = xsbti.compile.CompileOrder.ScalaThenJava
val Mixed = xsbti.compile.CompileOrder.Mixed
}
type CompileOrder = xsbti.compile.CompileOrder
implicit def maybeToOption[S](m: xsbti.Maybe[S]): Option[S] =
if (m.isDefined) Some(m.get) else None
final val ThisScope = Scope.ThisScope
final val GlobalScope = Scope.GlobalScope
import sbt.{ Configurations => C }
final val Compile = C.Compile
final val Test = C.Test
final val Runtime = C.Runtime
final val IntegrationTest = C.IntegrationTest
final val Default = C.Default
final val Provided = C.Provided
// java.lang.System is more important, so don't alias this one
// final val System = C.System
final val Optional = C.Optional
def config(s: String): Configuration = C.config(s)
}

View File

@ -1,60 +0,0 @@
package sbt
object syntax extends syntax
abstract class syntax extends IOSyntax0 with sbt.std.TaskExtra with sbt.internal.util.Types
with sbt.internal.librarymanagement.impl.DependencyBuilders with sbt.ProjectExtra
with sbt.internal.librarymanagement.DependencyFilterExtra with sbt.BuildExtra with sbt.TaskMacroExtra
with sbt.ScopeFilter.Make
with sbt.BuildSyntax {
// IO
def uri(s: String): URI = new URI(s)
def file(s: String): File = new File(s)
def url(s: String): URL = new URL(s)
implicit def fileToRichFile(file: File): sbt.io.RichFile = new sbt.io.RichFile(file)
implicit def filesToFinder(cc: Traversable[File]): sbt.io.PathFinder = sbt.io.PathFinder.strict(cc)
// others
object CompileOrder {
val JavaThenScala = xsbti.compile.CompileOrder.JavaThenScala
val ScalaThenJava = xsbti.compile.CompileOrder.ScalaThenJava
val Mixed = xsbti.compile.CompileOrder.Mixed
}
type CompileOrder = xsbti.compile.CompileOrder
implicit def maybeToOption[S](m: xsbti.Maybe[S]): Option[S] =
if (m.isDefined) Some(m.get) else None
final val ThisScope = Scope.ThisScope
final val GlobalScope = Scope.GlobalScope
import sbt.{ Configurations => C }
final val Compile = C.Compile
final val Test = C.Test
final val Runtime = C.Runtime
final val IntegrationTest = C.IntegrationTest
final val Default = C.Default
final val Provided = C.Provided
// java.lang.System is more important, so don't alias this one
// final val System = C.System
final val Optional = C.Optional
def config(s: String): Configuration = C.config(s)
}
// Todo share this this io.syntax
private[sbt] trait IOSyntax0 extends IOSyntax1 {
implicit def alternative[A, B](f: A => Option[B]): Alternative[A, B] =
new Alternative[A, B] {
def |(g: A => Option[B]) =
(a: A) => f(a) orElse g(a)
}
}
private[sbt] trait Alternative[A, B] {
def |(g: A => Option[B]): A => Option[B]
}
private[sbt] trait IOSyntax1 {
implicit def singleFileFinder(file: File): sbt.io.PathFinder = sbt.io.PathFinder(file)
}

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
import Def.Initialize
object Marker extends AutoPlugin {

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
import Def.Initialize
import complete.{DefaultParsers, Parser}

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
import Def.Initialize
import complete.{DefaultParsers, Parser}

View File

@ -1,5 +1,4 @@
import sbt._
import syntax._
object FooPlugin extends AutoPlugin {
override def trigger = noTrigger

View File

@ -0,0 +1,13 @@
lazy val buildInfo = taskKey[Seq[File]]("The task that generates the build info.")
lazy val root = (project in file("."))
.settings(
scalaVersion := "2.11.8",
buildInfo := {
val x = sourceManaged.value / "BuildInfo.scala"
IO.write(x, """object BuildInfo""")
x :: Nil
},
sourceGenerators in Compile += buildInfo,
sourceGenerators in Compile += Def.task { Nil }
)

View File

@ -0,0 +1,2 @@
> compile
$ exists target/scala-2.11/src_managed/BuildInfo.scala

View File

@ -1,6 +1,5 @@
package sbt
import sbt.syntax._
import sbt.Keys._
import xsbti.{Position, Severity}

View File

@ -1,4 +1,4 @@
import sbt._, syntax._
import sbt._
object Q extends AutoPlugin {
override val requires = plugins.JvmPlugin

View File

@ -1,8 +1,8 @@
val test123 = project in file(".") enablePlugins TestP settings(
resourceGenerators in Compile += (Def.task {
resourceGenerators in Compile += Def.task {
streams.value.log info "resource generated in settings"
Nil
}).taskValue
}
)
TaskKey[Unit]("check") := {

View File

@ -1,10 +1,10 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
object TestP extends AutoPlugin {
override def projectSettings: Seq[Setting[_]] = Seq(
resourceGenerators in Compile += (Def.task {
resourceGenerators in Compile += Def.task {
streams.value.log info "resource generated in plugin"
Nil
}).taskValue
}
)
}

View File

@ -1,5 +1,5 @@
package sbttest
import sbt._, syntax._, Keys._
import sbt._, Keys._
object Imports {
object A extends AutoPlugin

View File

@ -1,7 +1,7 @@
// no package
// plugins declared within no package should be visible to other plugins in the _root_ package
import sbt._, syntax._, Keys._
import sbt._, Keys._
object TopLevelImports {
lazy val topLevelDemo = settingKey[String]("A top level demo setting.")

View File

@ -1,6 +1,6 @@
package sbttest // you need package http://stackoverflow.com/questions/9822008/
import sbt._, syntax._, Keys._
import sbt._, Keys._
import java.util.concurrent.atomic.{AtomicInteger => AInt}
object A extends AutoPlugin { override def requires: Plugins = empty }

View File

@ -1,6 +1,6 @@
package sbttest // you need package http://stackoverflow.com/questions/9822008/
import sbt._, syntax._, Keys._
import sbt._, Keys._
object C extends AutoPlugin {
object autoImport {

View File

@ -1,6 +1,6 @@
// no package declaration
import sbt._, syntax._, Keys._
import sbt._, Keys._
object D extends AutoPlugin {
object autoImport {

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
object DatabasePlugin extends AutoPlugin {
override def requires: Plugins = sbt.plugins.JvmPlugin

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
object ExtraProjectPluginExample extends AutoPlugin {
override def extraProjects: Seq[Project] =

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
object ExtraProjectPluginExample2 extends AutoPlugin {
// Enable this plugin by default

View File

@ -1,6 +1,6 @@
package test
import sbt._, syntax._, Keys._
import sbt._, Keys._
object Global {
val x = 3

View File

@ -1,4 +1,4 @@
lazy val project = (sbt.syntax.project in file(".")).
lazy val project = (sbt.project in file(".")).
settings(
name := "project",
scalaVersion := "2.11.7",

View File

@ -1,4 +1,4 @@
import sbt._, syntax._, Keys._
import sbt._, Keys._
import sbt.internal.SessionSettings

View File

@ -10,8 +10,6 @@ import sbt.internal.inc.classpath.ClasspathUtilities
import sbt.internal.inc.ModuleUtilities
import java.lang.reflect.Method
import sbt.syntax._
object ScriptedPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements