refactor: Remove old sbt 0.13 shell syntax

This commit is contained in:
Eugene Yokota 2024-09-28 02:05:46 -04:00
parent 5ffd2f20c3
commit a6b4cfef12
23 changed files with 58 additions and 88 deletions

View File

@ -27,7 +27,7 @@ trait TestResultLogger {
* *
* @param log The target logger to write output to. * @param log The target logger to write output to.
* @param results The test results about which to log. * @param results The test results about which to log.
* @param taskName The task about which we are logging. Eg. "my-module-b/test:test" * @param taskName The task about which we are logging. Eg. "my-module-b/Test/test"
*/ */
def run(log: Logger, results: Output, taskName: String): Unit def run(log: Logger, results: Output, taskName: String): Unit

View File

@ -5049,7 +5049,7 @@ trait BuildExtra extends BuildCommon with DefExtra {
/** /**
* Disables post-compilation hook for determining tests for tab-completion (such as for 'test-only'). * Disables post-compilation hook for determining tests for tab-completion (such as for 'test-only').
* This is useful for reducing test:compile time when not running test. * This is useful for reducing Test/compile time when not running test.
*/ */
def noTestCompletion(config: Configuration = Test): Setting[_] = def noTestCompletion(config: Configuration = Test): Setting[_] =
inConfig(config)(Seq(definedTests := detectTests.value)).head inConfig(config)(Seq(definedTests := detectTests.value)).head

View File

@ -36,7 +36,6 @@ final class ParsedKey(val key: ScopedKey[_], val mask: ScopeMask, val separaters
end ParsedKey end ParsedKey
object Act { object Act {
val ZeroString = "*"
private[sbt] val GlobalIdent = "Global" private[sbt] val GlobalIdent = "Global"
private[sbt] val ZeroIdent = "Zero" private[sbt] val ZeroIdent = "Zero"
private[sbt] val ThisBuildIdent = "ThisBuild" private[sbt] val ThisBuildIdent = "ThisBuild"
@ -46,8 +45,6 @@ object Act {
token(OptSpace ~> '/' <~ OptSpace).examples("/").map(_ => ()) token(OptSpace ~> '/' <~ OptSpace).examples("/").map(_ => ())
private[sbt] val slashSeq: Seq[String] = Seq("/") private[sbt] val slashSeq: Seq[String] = Seq("/")
private[sbt] val colonSeq: Seq[String] = Seq(":")
private[sbt] val colonColonSeq: Seq[String] = Seq("::")
// this does not take aggregation into account // this does not take aggregation into account
def scopedKey( def scopedKey(
@ -242,26 +239,15 @@ object Act {
def toAxis[T](opt: Option[T], ifNone: ScopeAxis[T]): ScopeAxis[T] = def toAxis[T](opt: Option[T], ifNone: ScopeAxis[T]): ScopeAxis[T] =
opt match { case Some(t) => Select(t); case None => ifNone } opt match { case Some(t) => Select(t); case None => ifNone }
def config(confs: Set[String]): Parser[ParsedAxis[String]] = {
val sep = ':' !!! "Expected ':' (if selecting a configuration)"
token(
(ZeroString ^^^ ParsedZero | value(examples(ID, confs, "configuration"))) <~ sep
) ?? Omitted
}
// New configuration parser that's able to parse configuration ident trailed by slash. // New configuration parser that's able to parse configuration ident trailed by slash.
private[sbt] def configIdent( private[sbt] def configIdent(
confs: Set[String], confs: Set[String],
idents: Set[String], idents: Set[String],
fromIdent: String => String fromIdent: String => String
): Parser[(ParsedAxis[String], Seq[String])] = { ): Parser[(ParsedAxis[String], Seq[String])] = {
val oldSep: Parser[Char] = ':'
val sep: Parser[Unit] = spacedSlash !!! "Expected '/'" val sep: Parser[Unit] = spacedSlash !!! "Expected '/'"
token( token(
((ZeroString ^^^ (ParsedZero -> colonSeq)) <~ oldSep) ((ZeroIdent ^^^ (ParsedZero -> slashSeq)) <~ sep)
| ((ZeroString ^^^ (ParsedZero -> slashSeq)) <~ sep)
| ((ZeroIdent ^^^ (ParsedZero -> slashSeq)) <~ sep)
| (value(examples(ID, confs, "configuration")).map(_ -> colonSeq) <~ oldSep)
| (value(examples(CapitalizedID, idents, "configuration ident").map(fromIdent)) | (value(examples(CapitalizedID, idents, "configuration ident").map(fromIdent))
.map(_ -> slashSeq) <~ sep) .map(_ -> slashSeq) <~ sep)
) ?? (Omitted -> Nil) ) ?? (Omitted -> Nil)
@ -358,16 +344,10 @@ object Act {
val suggested = normKeys.map(_._1).toSet val suggested = normKeys.map(_._1).toSet
val keyP = filterStrings(examples(ID, suggested, "key"), valid.keySet, "key").map(valid) val keyP = filterStrings(examples(ID, suggested, "key"), valid.keySet, "key").map(valid)
((token( (token(
value(keyP).map(_ -> slashSeq) value(keyP).map(_ -> slashSeq)
| ZeroString ^^^ (ParsedZero -> slashSeq)
| ZeroIdent ^^^ (ParsedZero -> slashSeq) | ZeroIdent ^^^ (ParsedZero -> slashSeq)
) <~ spacedSlash) | ) <~ spacedSlash) ?? (Omitted -> Nil)
(token(
value(keyP).map(_ -> colonColonSeq)
| ZeroString ^^^ (ParsedZero -> colonColonSeq)
| ZeroIdent ^^^ (ParsedZero -> colonColonSeq)
) <~ token("::".id))) ?? (Omitted -> Nil)
} }
def resolveTask(task: ParsedAxis[AttributeKey[_]]): Option[AttributeKey[_]] = def resolveTask(task: ParsedAxis[AttributeKey[_]]): Option[AttributeKey[_]] =
@ -411,11 +391,10 @@ object Act {
} }
def projectRef(index: KeyIndex, currentBuild: URI): Parser[ParsedAxis[ResolvedReference]] = { def projectRef(index: KeyIndex, currentBuild: URI): Parser[ParsedAxis[ResolvedReference]] = {
val global = token(ZeroString ~ spacedSlash) ^^^ ParsedZero
val zeroIdent = token(ZeroIdent ~ spacedSlash) ^^^ ParsedZero val zeroIdent = token(ZeroIdent ~ spacedSlash) ^^^ ParsedZero
val thisBuildIdent = value(token(ThisBuildIdent ~ spacedSlash) ^^^ BuildRef(currentBuild)) val thisBuildIdent = value(token(ThisBuildIdent ~ spacedSlash) ^^^ BuildRef(currentBuild))
val trailing = spacedSlash !!! "Expected '/' (if selecting a project)" val trailing = spacedSlash !!! "Expected '/' (if selecting a project)"
global | zeroIdent | thisBuildIdent | zeroIdent | thisBuildIdent |
value(resolvedReferenceIdent(index, currentBuild, trailing)) | value(resolvedReferenceIdent(index, currentBuild, trailing)) |
value(resolvedReference(index, currentBuild, trailing)) value(resolvedReference(index, currentBuild, trailing))
} }
@ -491,12 +470,6 @@ object Act {
import Aggregation.evaluatingParser import Aggregation.evaluatingParser
actionParser.flatMap { action => actionParser.flatMap { action =>
val akp = aggregatedKeyParserSep(extracted) val akp = aggregatedKeyParserSep(extracted)
def warnOldShellSyntax(seps: Seq[String], keyStrings: String): Unit =
if (seps.contains(":") || seps.contains("::")) {
state.log.warn(
s"sbt 0.13 shell syntax is deprecated; use slash syntax instead: $keyStrings"
)
} else ()
def evaluate(pairs: Seq[(ScopedKey[_], Seq[String])]): Parser[() => State] = { def evaluate(pairs: Seq[(ScopedKey[_], Seq[String])]): Parser[() => State] = {
val kvs = pairs.map(_._1) val kvs = pairs.map(_._1)
val seps = pairs.headOption.map(_._2).getOrElse(Nil) val seps = pairs.headOption.map(_._2).getOrElse(Nil)
@ -510,7 +483,6 @@ object Act {
{ {
val keyStrings = preparedPairs.map(pp => showKey.show(pp.key)).mkString(", ") val keyStrings = preparedPairs.map(pp => showKey.show(pp.key)).mkString(", ")
state.log.debug("Evaluating tasks: " + keyStrings) state.log.debug("Evaluating tasks: " + keyStrings)
warnOldShellSyntax(seps, keyStrings)
evaluate() evaluate()
} }
} }

View File

@ -82,7 +82,7 @@ $PrintCommand <task>
Displays lines from the logging of previous commands that match `pattern`. Displays lines from the logging of previous commands that match `pattern`.
$LastGrepCommand <pattern> [key] $LastGrepCommand <pattern> [key]
Displays lines from logging associated with `key` that match `pattern`. The key typically refers to a task (for example, test:compile). The logging that is displayed is restricted to the logging for that particular task. Displays lines from logging associated with `key` that match `pattern`. The key typically refers to a task (for example, Test/compile). The logging that is displayed is restricted to the logging for that particular task.
<pattern> is a regular expression interpreted by java.util.Pattern. Matching text is highlighted (when highlighting is supported and enabled). <pattern> is a regular expression interpreted by java.util.Pattern. Matching text is highlighted (when highlighting is supported and enabled).
See also '$LastCommand'.""" See also '$LastCommand'."""
@ -94,7 +94,7 @@ $LastGrepCommand <pattern> [key]
Prints the logging for the previous command, typically at a more verbose level. Prints the logging for the previous command, typically at a more verbose level.
$LastCommand <key> $LastCommand <key>
Prints the logging associated with the provided key. The key typically refers to a task (for example, test:compile). The logging that is displayed is restricted to the logging for that particular task. Prints the logging associated with the provided key. The key typically refers to a task (for example, Test/compile). The logging that is displayed is restricted to the logging for that particular task.
See also '$LastGrepCommand'.""" See also '$LastGrepCommand'."""

View File

@ -36,7 +36,7 @@ object SettingQuery {
index: KeyIndex, index: KeyIndex,
currentBuild: URI currentBuild: URI
): Parser[ParsedExplicitAxis[ResolvedReference]] = { ): Parser[ParsedExplicitAxis[ResolvedReference]] = {
val global = token(Act.ZeroString ~ '/') ^^^ ParsedExplicitGlobal val global = token(Act.GlobalIdent ~ '/') ^^^ ParsedExplicitGlobal
val trailing = '/' !!! "Expected '/' (if selecting a project)" val trailing = '/' !!! "Expected '/' (if selecting a project)"
global | explicitValue(Act.resolvedReference(index, currentBuild, trailing)) global | explicitValue(Act.resolvedReference(index, currentBuild, trailing))
} }
@ -56,7 +56,12 @@ object SettingQuery {
for { for {
rawProject <- projectRef(index, currentBuild) rawProject <- projectRef(index, currentBuild)
proj = resolveProject(rawProject) proj = resolveProject(rawProject)
confAmb <- Act.config(index configs proj) confPair <- Act.configIdent(
index.configs(proj),
index.configIdents(proj),
index.fromConfigIdent(proj)
)
(confAmb, seps) = confPair
partialMask = ScopeMask(true, confAmb.isExplicit, false, false) partialMask = ScopeMask(true, confAmb.isExplicit, false, false)
} yield Act.taskKeyExtra(index, defaultConfigs, keyMap, proj, confAmb, partialMask, Nil) } yield Act.taskKeyExtra(index, defaultConfigs, keyMap, proj, confAmb, partialMask, Nil)
} }

View File

@ -6,5 +6,5 @@
> checkNext 1 2 > checkNext 1 2
> checkScopes 0 0 > checkScopes 0 0
> all x compile:y::x runtime:y::x y > all x Compile/y/x Runtime/y/x y
> checkScopes 21 91 > checkScopes 21 91

View File

@ -1,9 +1,7 @@
ThisBuild / scalaVersion := "2.12.19" scalaVersion := "2.12.19"
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"com.novocode" % "junit-interface" % "0.5" % Test, "com.novocode" % "junit-interface" % "0.5" % Test,
"junit" % "junit" % "4.13.1" % Test, "junit" % "junit" % "4.13.1" % Test,
"commons-io" % "commons-io" % "2.5" % Runtime, "commons-io" % "commons-io" % "2.5" % Runtime,
) )
libraryDependencies += scalaVersion("org.scala-lang" % "scala-compiler" % _ ).value libraryDependencies += scalaVersion("org.scala-lang" % "scala-compiler" % _ ).value

View File

@ -3,13 +3,11 @@ package foo.bar
import org.junit._ import org.junit._
import org.junit.Assert._ import org.junit.Assert._
class Basic class Basic {
{ val foo = new Foo
val foo = new Foo @Test
@Test def checkBind(): Unit = {
def checkBind(): Unit = try { assertTrue( foo.eval("3") == 3) }
{ catch { case e => e.printStackTrace; throw e}
try { assertTrue( foo.eval("3") == 3) } }
catch { case e => e.printStackTrace; throw e}
}
} }

View File

@ -1,10 +1,10 @@
> run 1 > run 1
> test:test > test
> clean > clean
> run 2 > run 2
> test:test > test
> clean > clean
> run -1 > run -1
> test:test > test

View File

@ -1,7 +1,7 @@
> a/publish > a/publish
$ copy-file changes/B.scala b/B.scala $ copy-file changes/B.scala b/B.scala
-> b/test:compile -> b/Test/compile
# Need to sleep 3s because the check depends on last modified time and typical resolution is 1s. # Need to sleep 3s because the check depends on last modified time and typical resolution is 1s.
$ sleep 3000 $ sleep 3000
@ -9,4 +9,4 @@ $ sleep 3000
$ copy-file changes/A.scala a/src/test/scala/A.scala $ copy-file changes/A.scala a/src/test/scala/A.scala
> a/publish > a/publish
> b/test:compile > b/Test/compile

View File

@ -1,3 +1,3 @@
> export compile:dependencyClasspath > export Compile/dependencyClasspath
> export test:dependencyClasspath > export Test/dependencyClasspath
> test:compile > Test/compile

View File

@ -8,4 +8,4 @@ $ copy-file changes/scalacheck-ivy.xml ivy.xml
$ copy-file changes/scala-tools-ivysettings.xml ivysettings.xml $ copy-file changes/scala-tools-ivysettings.xml ivysettings.xml
> check > check
> test:compile > Test/compile

View File

@ -1,3 +1,3 @@
> show pluginCrossBuild::sbtDependency > show pluginCrossBuild::sbtDependency
> compile > compile
-> test:compile -> Test/compile

View File

@ -3,20 +3,20 @@
> compile > compile
> test > test
> test:run > Test/run
# This part verifies that the package-src action works properly under a flattened/merged source hierarchy # This part verifies that the package-src action works properly under a flattened/merged source hierarchy
> packageSrc > packageSrc
> test:packageSrc > Test/packageSrc
$ delete src $ delete src
$ delete test-src $ delete test-src
-> test:run -> Test/run
> unpackage > unpackage
> test:unpackage > Test/unpackage
> test:test > Test/test
> test:run > Test/run

View File

@ -1,16 +1,16 @@
> compile > compile
$ exists target/scala-2.12/classes/META-INF/semanticdb/src/main/scala/foo/Compile.scala.semanticdb $ exists target/scala-2.12/classes/META-INF/semanticdb/src/main/scala/foo/Compile.scala.semanticdb
> test:compile > Test/compile
$ exists target/scala-2.12/test-classes/META-INF/semanticdb/src/test/scala/foo/Test.scala.semanticdb $ exists target/scala-2.12/test-classes/META-INF/semanticdb/src/test/scala/foo/Test.scala.semanticdb
> it:compile > IntegrationTest/compile
$ exists target/scala-2.12/it-classes/META-INF/semanticdb/src/it/scala/foo/IntegrationTest.scala.semanticdb $ exists target/scala-2.12/it-classes/META-INF/semanticdb/src/it/scala/foo/IntegrationTest.scala.semanticdb
> custom:compile > Custom/compile
$ exists target/scala-2.12/custom-classes/META-INF/semanticdb/src/custom/scala/foo/Custom.scala.semanticdb $ exists target/scala-2.12/custom-classes/META-INF/semanticdb/src/custom/scala/foo/Custom.scala.semanticdb
> st:compile > SystemTest/compile
$ exists target/scala-2.12/st-classes/META-INF/semanticdb/src/st/scala/foo/SystemTest.scala.semanticdb $ exists target/scala-2.12/st-classes/META-INF/semanticdb/src/st/scala/foo/SystemTest.scala.semanticdb
> check > check

View File

@ -1,4 +1,4 @@
# should fail because it should run all test:tests, some of which are expected to fail (1 and 4) # should fail because it should run all tests, some of which are expected to fail (1 and 4)
-> testQuick -> testQuick
$ touch success1 $ touch success1

View File

@ -1,28 +1,27 @@
> clean > clean
$ delete src/ $ delete src/
$ copy-file changes/ClassFailModuleSuccess.scala src/it/scala/Test.scala $ copy-file changes/ClassFailModuleSuccess.scala src/it/scala/Test.scala
-> it:test -> IntegrationTest/test
> clean > clean
$ delete src/ $ delete src/
$ copy-file changes/ClassFailModuleFail.scala src/it/scala/Test.scala $ copy-file changes/ClassFailModuleFail.scala src/it/scala/Test.scala
-> it:test -> IntegrationTest/test
> clean > clean
$ delete src/ $ delete src/
$ copy-file changes/ClassSuccessModuleFail.scala src/it/scala/Test.scala $ copy-file changes/ClassSuccessModuleFail.scala src/it/scala/Test.scala
-> it:test -> IntegrationTest/test
> clean > clean
$ delete src/ $ delete src/
$ copy-file changes/ClassSuccessModuleSuccess.scala src/it/scala/Test.scala $ copy-file changes/ClassSuccessModuleSuccess.scala src/it/scala/Test.scala
> it:test > IntegrationTest/test
# verify that a failing normal test fails when run directly # verify that a failing normal test fails when run directly
$ copy-file changes/AlwaysFail.scala src/test/scala/AlwaysFail.scala $ copy-file changes/AlwaysFail.scala src/test/scala/AlwaysFail.scala
-> test:test -> Test/test
# but that it does not affect the result of it:test (#539)
> it:test
# but that it does not affect the result of IntegrationTest/test (#539)
> IntegrationTest/test

View File

@ -1,3 +1,3 @@
scalaVersion := "2.12.19"
val specs = "org.specs2" %% "specs2-core" % "4.3.4" val specs = "org.specs2" %% "specs2-core" % "4.3.4"
ThisBuild / scalaVersion := "2.12.19"
libraryDependencies += specs % Test libraryDependencies += specs % Test

View File

@ -1 +1 @@
> test:test > test

View File

@ -1,7 +1,7 @@
Global / cacheStores := Seq.empty Global / cacheStores := Seq.empty
val scalatest = "org.scalatest" %% "scalatest" % "3.0.5" val scalatest = "org.scalatest" %% "scalatest" % "3.0.5"
ThisBuild / scalaVersion := "2.12.19" scalaVersion := "2.12.19"
lazy val root = (project in file(".")) lazy val root = (project in file("."))
.settings( .settings(

View File

@ -27,7 +27,7 @@ $ sleep 2000
# src/test compilation group change. # src/test compilation group change.
$ copy-file changed/Base.scala src/test/scala/Base.scala $ copy-file changed/Base.scala src/test/scala/Base.scala
> test:compile > Test/compile
$ sleep 2000 $ sleep 2000
-> testQuick Create -> testQuick Create
> testQuick Delete > testQuick Delete

View File

@ -112,7 +112,6 @@ class ClientTest extends AbstractServerTest {
test("compi completions") { test("compi completions") {
val expected = Vector( val expected = Vector(
"compile", "compile",
"compile:",
"compileAnalysisFile", "compileAnalysisFile",
"compileAnalysisFilename", "compileAnalysisFilename",
"compileAnalysisTargetRoot", "compileAnalysisTargetRoot",
@ -135,7 +134,6 @@ class ClientTest extends AbstractServerTest {
val testOnlyExpected = Vector( val testOnlyExpected = Vector(
"testOnly", "testOnly",
"testOnly/", "testOnly/",
"testOnly::",
"testOnly;", "testOnly;",
) )
assert(complete("testOnly") == testOnlyExpected) assert(complete("testOnly") == testOnlyExpected)

View File

@ -22,8 +22,8 @@ import sbt.util._
// no longer specific to Tasks, so 'TaskStreams' should be renamed // no longer specific to Tasks, so 'TaskStreams' should be renamed
/** /**
* Represents a set of streams associated with a context. In sbt, this is a named set of streams for * Represents a set of streams associated with a context. In sbt, this is a named set of streams for
* a particular scoped key. For example, logging for test:compile is by default sent to the "out" * a particular scoped key. For example, logging for Test/compile is by default sent to the "out"
* stream in the test:compile context. * stream in the Test/compile context.
*/ */
sealed trait TaskStreams[Key] { sealed trait TaskStreams[Key] {