-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: queriable slash syntax (sbt query)
**Problem** We want a more flexible way of aggregating subprojects. **Solution** This implements a subproject filtering as a replacement of the subproject axis in the act command.
- Loading branch information
Showing
5 changed files
with
180 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package sbt | ||
package internal | ||
|
||
import sbt.internal.util.complete.{ DefaultParsers, Parser } | ||
import sbt.Keys.scalaBinaryVersion | ||
import DefaultParsers.* | ||
import scala.annotation.nowarn | ||
import scala.util.matching.Regex | ||
import sbt.internal.util.AttributeKey | ||
|
||
private[sbt] case class ProjectQuery( | ||
projectName: String, | ||
params: Map[AttributeKey[?], String], | ||
): | ||
import ProjectQuery.* | ||
private lazy val pattern: Regex = Regex("^" + projectName.replace(wildcard, ".*") + "$") | ||
|
||
@nowarn | ||
def buildQuery(structure: BuildStructure): ProjectRef => Boolean = | ||
(p: ProjectRef) => | ||
val projectMatches = | ||
if projectName == wildcard then true | ||
else pattern.matches(p.project) | ||
val scalaMatches = | ||
params.get(Keys.scalaBinaryVersion.key) match | ||
case Some(expected) => | ||
val actualSbv = structure.data.get(Scope.ThisScope.in(p), scalaBinaryVersion.key) | ||
actualSbv match | ||
case Some(sbv) => sbv == expected | ||
case None => true | ||
case None => true | ||
projectMatches && scalaMatches | ||
end ProjectQuery | ||
|
||
object ProjectQuery: | ||
private val wildcard = "..." | ||
|
||
// make sure @ doesn't match on this one | ||
def projectName: Parser[String] = | ||
charClass(c => c.isLetter || c.isDigit || c == '_' || c == '.').+.string | ||
.examples(wildcard) | ||
|
||
def parser: Parser[ProjectQuery] = | ||
(projectName ~ | ||
token("@scalaBinaryVersion=" ~> StringBasic.map((scalaBinaryVersion.key, _))) | ||
.examples("@scalaBinaryVersion=3") | ||
.?) | ||
.map { case (proj, params) => | ||
ProjectQuery(proj, Map(params.toSeq: _*)) | ||
} | ||
.filter( | ||
(q) => q.projectName.contains("...") || q.params.nonEmpty, | ||
(msg) => s"$msg isn't a query" | ||
) | ||
end ProjectQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
scalaVersion := "3.3.3" | ||
|
||
lazy val someTask = taskKey[Unit]("") | ||
|
||
lazy val root = (project in file(".")) | ||
.aggregate(foo, bar, baz) | ||
.settings( | ||
name := "root", | ||
) | ||
|
||
lazy val foo = project | ||
lazy val bar = project | ||
lazy val baz = project | ||
.settings( | ||
scalaVersion := "2.12.19", | ||
) | ||
|
||
someTask := { | ||
val x = target.value / (name.value + ".txt") | ||
val s = streams.value | ||
s.log.info(s"writing $x") | ||
IO.touch(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
> ... / someTask | ||
|
||
$ exists target/out/jvm/scala-3.3.3/root/root.txt | ||
$ exists target/out/jvm/scala-3.3.3/foo/foo.txt | ||
$ exists target/out/jvm/scala-3.3.3/bar/bar.txt | ||
$ exists target/out/jvm/scala-2.12.19/baz/baz.txt | ||
|
||
> clean | ||
|
||
> b... / someTask | ||
|
||
$ absent target/out/jvm/scala-3.3.3/root/root.txt | ||
$ absent target/out/jvm/scala-3.3.3/foo/foo.txt | ||
$ exists target/out/jvm/scala-3.3.3/bar/bar.txt | ||
$ exists target/out/jvm/scala-2.12.19/baz/baz.txt | ||
|
||
> clean | ||
|
||
> ...@scalaBinaryVersion=3 / someTask | ||
|
||
$ exists target/out/jvm/scala-3.3.3/root/root.txt | ||
$ exists target/out/jvm/scala-3.3.3/foo/foo.txt | ||
$ exists target/out/jvm/scala-3.3.3/bar/bar.txt | ||
$ absent target/out/jvm/scala-2.12.19/baz/baz.txt |