Resolve conflict between BuildSyntax.dependsOn and Scoped.dependsOn

This commit is contained in:
Adrien Piquerez 2024-09-25 14:31:35 +02:00
parent 860f462f2f
commit eda3a87e76
13 changed files with 69 additions and 82 deletions

View File

@ -29,8 +29,32 @@ import xsbti.{ HashedVirtualFileRef, VirtualFile, VirtualFileRef }
import sjsonnew.JsonFormat
import scala.reflect.ClassTag
trait BuildSyntax:
inline def settingKey[A1](inline description: String): SettingKey[A1] =
${ std.KeyMacro.settingKeyImpl[A1]('description) }
inline def taskKey[A1](inline description: String): TaskKey[A1] =
${ std.KeyMacro.taskKeyImpl[A1]('description) }
inline def inputKey[A1](inline description: String): InputKey[A1] =
${ std.KeyMacro.inputKeyImpl[A1]('description) }
import sbt.std.ParserInput
extension [A1](inline in: Task[A1])
inline def value: A1 = std.InputWrapper.`wrapTask_\u2603\u2603`[A1](in)
// implicit def macroValueIn[T](@deprecated("unused", "") in: InputTask[T]): std.InputEvaluated[T] =
// ???
extension [A1](inline in: Parser[A1])
inline def parsed: A1 = ParserInput.`parser_\u2603\u2603`[A1](Def.toSParser(in))
extension [A1](inline in: State => Parser[A1])
inline def parsed: A1 = ParserInput.`parser_\u2603\u2603`[A1](in)
end BuildSyntax
/** A concrete settings system that uses `sbt.Scope` for the scope type. */
object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits:
object Def extends BuildSyntax with Init[Scope] with InitializeImplicits:
type Classpath = Seq[Attributed[HashedVirtualFileRef]]
def settings(ss: SettingsDefinition*): Seq[Setting[_]] = ss.flatMap(_.settings)
@ -404,15 +428,6 @@ object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits:
)
)
inline def settingKey[A1](inline description: String): SettingKey[A1] =
${ std.KeyMacro.settingKeyImpl[A1]('description) }
inline def taskKey[A1](inline description: String): TaskKey[A1] =
${ std.KeyMacro.taskKeyImpl[A1]('description) }
inline def inputKey[A1](inline description: String): InputKey[A1] =
${ std.KeyMacro.inputKeyImpl[A1]('description) }
class InitOps[T](private val x: Initialize[T]) extends AnyVal {
def toTaskable: Taskable[T] = x
}
@ -449,28 +464,9 @@ object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits:
t.info.attributes.get(isDummyTask) getOrElse false
end Def
// these need to be mixed into the sbt package object
// because the target doesn't involve Initialize or anything in Def
trait TaskMacroExtra:
import sbt.std.ParserInput
extension [A1](inline in: Task[A1])
inline def value: A1 = std.InputWrapper.`wrapTask_\u2603\u2603`[A1](in)
// implicit def macroValueIn[T](@deprecated("unused", "") in: InputTask[T]): std.InputEvaluated[T] =
// ???
extension [A1](inline in: Parser[A1])
inline def parsed: A1 = ParserInput.`parser_\u2603\u2603`[A1](Def.toSParser(in))
extension [A1](inline in: State => Parser[A1])
inline def parsed: A1 = ParserInput.`parser_\u2603\u2603`[A1](in)
end TaskMacroExtra
sealed trait InitializeImplicits0 { self: Def.type =>
sealed trait InitializeImplicits { self: Def.type =>
implicit def initOps[T](x: Def.Initialize[T]): Def.InitOps[T] = new Def.InitOps(x)
}
sealed trait InitializeImplicits extends InitializeImplicits0 { self: Def.type =>
implicit def initTaskOps[T](x: Def.Initialize[Task[T]]): Def.InitTaskOps[T] =
new Def.InitTaskOps(x)
}

View File

@ -0,0 +1,23 @@
/*
* sbt
* Copyright 2023, Scala center
* Copyright 2011 - 2022, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt
import sbt.internal.DslEntry
import sbt.librarymanagement.Configuration
trait BareBuildSyntax:
def enablePlugins(ps: AutoPlugin*): DslEntry = DslEntry.DslEnablePlugins(ps)
def disablePlugins(ps: AutoPlugin*): DslEntry = DslEntry.DslDisablePlugins(ps)
def configs(cs: Configuration*): DslEntry = DslEntry.DslConfigs(cs)
def dependsOn(deps: ClasspathDep[ProjectReference]*): DslEntry = DslEntry.DslDependsOn(deps)
// avoid conflict with `sbt.Keys.aggregate`
def aggregateProjects(refs: ProjectReference*): DslEntry = DslEntry.DslAggregate(refs)
end BareBuildSyntax
object BareBuildSyntax extends BareBuildSyntax

View File

@ -1,41 +0,0 @@
/*
* sbt
* Copyright 2023, Scala center
* Copyright 2011 - 2022, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt
import sbt.internal.DslEntry
import sbt.librarymanagement.Configuration
private[sbt] trait BuildSyntax:
import scala.language.experimental.macros
/**
* Creates a new Project. This is a macro that expects to be assigned directly to a val.
* The name of the val is used as the project ID and the name of the base directory of the project.
*/
inline def project: Project = ${ std.KeyMacro.projectImpl }
inline def projectMatrix: ProjectMatrix = ${ ProjectMatrix.projectMatrixImpl }
inline def settingKey[A1](inline description: String): SettingKey[A1] =
${ std.KeyMacro.settingKeyImpl[A1]('description) }
inline def taskKey[A1](inline description: String): TaskKey[A1] =
${ std.KeyMacro.taskKeyImpl[A1]('description) }
inline def inputKey[A1](inline description: String): InputKey[A1] =
${ std.KeyMacro.inputKeyImpl[A1]('description) }
def enablePlugins(ps: AutoPlugin*): DslEntry = DslEntry.DslEnablePlugins(ps)
def disablePlugins(ps: AutoPlugin*): DslEntry = DslEntry.DslDisablePlugins(ps)
def configs(cs: Configuration*): DslEntry = DslEntry.DslConfigs(cs)
def dependsOn(deps: ClasspathDep[ProjectReference]*): DslEntry = DslEntry.DslDependsOn(deps)
// avoid conflict with `sbt.Keys.aggregate`
def aggregateProjects(refs: ProjectReference*): DslEntry = DslEntry.DslAggregate(refs)
implicit def sbtStateToUpperStateOps(s: State): UpperStateOps =
new UpperStateOps.UpperStateOpsImpl(s)
end BuildSyntax
private[sbt] object BuildSyntax extends BuildSyntax

View File

@ -4779,11 +4779,18 @@ object Classpaths {
}
}
private[sbt] object Build0 extends BuildExtra
private[sbt] object BuildExtra extends BuildExtra
trait BuildExtra extends BuildCommon with DefExtra {
import Defaults._
/**
* Creates a new Project. This is a macro that expects to be assigned directly to a val.
* The name of the val is used as the project ID and the name of the base directory of the project.
*/
inline def project: Project = ${ std.KeyMacro.projectImpl }
inline def projectMatrix: ProjectMatrix = ${ ProjectMatrix.projectMatrixImpl }
/**
* Defines an alias given by `name` that expands to `value`.
* This alias is defined globally after projects are loaded.
@ -5054,6 +5061,9 @@ trait BuildExtra extends BuildCommon with DefExtra {
f: ScopedKey[_] => Boolean
): Seq[Setting[_]] =
ss filter (s => f(s.key) && (!transitive || s.dependencies.forall(f)))
implicit def sbtStateToUpperStateOps(s: State): UpperStateOps =
new UpperStateOps.UpperStateOpsImpl(s)
}
trait DefExtra {

View File

@ -13,6 +13,7 @@ import java.util.concurrent.atomic.AtomicReference
import sbt.Def.{ ScopedKey, Setting, dummyState }
import sbt.Keys.{ TaskProgress => _, name => _, _ }
import sbt.BuildExtra.*
import sbt.ProjectExtra.*
import sbt.Scope.Global
import sbt.SlashSyntax0._
@ -24,7 +25,6 @@ import sbt.internal.util.{ Terminal => ITerminal, _ }
import sbt.librarymanagement.{ Resolver, UpdateReport }
import sbt.std.Transform.DummyTaskMap
import sbt.util.{ Logger, Show }
import sbt.BuildSyntax._
import sbt.internal.bsp.BuildTargetIdentifier
import scala.annotation.nowarn

View File

@ -16,8 +16,7 @@ import lmcoursier.{ CoursierConfiguration, FallbackDependency }
import org.apache.ivy.core.module.descriptor.ModuleDescriptor
import org.apache.ivy.core.module.id.ModuleRevisionId
import org.apache.logging.log4j.core.{ Appender => XAppender }
import sbt.BuildSyntax._
import sbt.Def.ScopedKey
import sbt.Def.*
import sbt.KeyRanks._
import sbt.internal.InMemoryCacheStore.CacheStoreFactoryFactory
import sbt.internal._

View File

@ -94,6 +94,7 @@ object BuildUtil {
("import _root_.scala.xml.{TopScope=>$scope}"
:: "import _root_.sbt.*"
:: "import _root_.sbt.given"
:: "import _root_.sbt.BareBuildSyntax.*"
:: "import _root_.sbt.Keys.*"
:: "import _root_.sbt.nio.Keys.*"
:: Nil)

View File

@ -11,8 +11,8 @@ package internal
package server
import java.net.URI
import sbt.BuildExtra.*
import sbt.BuildPaths.{ configurationSources, projectStandard }
import sbt.BuildSyntax._
import sbt.Def._
import sbt.Keys._
import sbt.Project._

View File

@ -12,7 +12,7 @@ import java.io.InputStream
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicBoolean
import sbt.BuildSyntax.{ settingKey, taskKey }
import sbt.Def.{ settingKey, taskKey }
import sbt.KeyRanks.{ BMinusSetting, DSetting, Invisible }
import sbt.internal.DynamicInput
import sbt.internal.nio.FileTreeRepository

View File

@ -12,7 +12,7 @@ package plugins
import java.io.File
import java.net.URI
import sbt.internal.graph._
import sbt.BuildSyntax._
import sbt.Def._
import sbt.librarymanagement.{ ModuleID, UpdateReport }
trait MiniDependencyTreeKeys {

View File

@ -39,7 +39,7 @@ object SemanticdbPlugin extends AutoPlugin {
val sdb = semanticdbEnabled.value
val m = semanticdbCompilerPlugin.value
val sv = scalaVersion.value
if (sdb && !ScalaInstance.isDotty(sv)) List(Build0.compilerPlugin(m))
if (sdb && !ScalaInstance.isDotty(sv)) List(BuildExtra.compilerPlugin(m))
else Nil
},
semanticdbOptions += {

View File

@ -11,7 +11,7 @@ package sbt
import scala.util.control.NonFatal
import org.scalacheck._
import Prop._
import sbt.BuildSyntax.project
import sbt.BuildExtra.project
import java.io.File
class ProjectDefs {

View File

@ -23,9 +23,8 @@ package object sbt
with sbt.librarymanagement.DependencyFilterExtra
with sbt.librarymanagement.LibraryManagementSyntax
with sbt.BuildExtra
with sbt.TaskMacroExtra
with sbt.ScopeFilter.Make
with sbt.BuildSyntax
with sbt.ScopeFilter.Make
with sbt.OptionSyntax
with sbt.SlashSyntax
with sbt.Import: