Skip to content

Commit e790867

Browse files
authored
Merge pull request #3154 from tgodzik/fix-deduplicate2
bugfix: Also deduplicate if options split by space
2 parents 932866d + 2663a98 commit e790867

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

modules/build/src/test/scala/scala/build/tests/BuildTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
625625
}
626626

627627
test("cli scalac options shadowing using directives") {
628-
val cliScalacOptions = Seq("-Xmaxwarns", "4", "-g:source", "-language:no2AutoTupling")
628+
val cliScalacOptions =
629+
Seq("-Xmaxwarns", "4", "-g:source", "-language:no2AutoTupling", "-language", "no2AutoTupling")
629630
val usingDirectiveScalacOptions = Seq(
630631
"-nobootcp",
631632
"-Xmaxwarns",

modules/options/src/main/scala/scala/build/Positioned.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object Positioned {
6161
underlying: ShadowingSeq.KeyOf[T]
6262
): ShadowingSeq.KeyOf[Positioned[T]] =
6363
ShadowingSeq.KeyOf(
64-
p => underlying.get(p.value),
64+
pSeq => underlying.makeKey(pSeq.map(_.value)),
6565
seq => underlying.groups(seq.map(_.value))
6666
)
6767
}

modules/options/src/main/scala/scala/build/options/JavaOpt.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final case class JavaOpt(value: String) {
1010
else if (value.startsWith("@")) Some("@")
1111
else None
1212
}
13+
1314
}
1415

1516
object JavaOpt {
@@ -29,7 +30,7 @@ object JavaOpt {
2930
}
3031
implicit val keyOf: ShadowingSeq.KeyOf[JavaOpt] =
3132
ShadowingSeq.KeyOf(
32-
_.key,
33+
opts => opts.headOption.flatMap(_.key).orElse(Some(opts.map(_.value).mkString(":"))),
3334
seq => ScalacOpt.groupCliOptions(seq.map(_.value))
3435
)
3536
}

modules/options/src/main/scala/scala/build/options/ScalacOpt.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@ final case class ScalacOpt(value: String) {
99

1010
/** @return raw key for the option (only if the key can be shadowed from the CLI) */
1111
private[options] def shadowableKey: Option[String] = key match
12-
case Some(key) if ScalacOpt.repeatingKeys.exists(_.startsWith(key)) => Some(value)
13-
case otherwise => otherwise
12+
case Some(key)
13+
if ScalacOpt.repeatingKeys.exists(rKey => rKey.startsWith(key + ":") || rKey == key) => None
14+
case otherwise => otherwise
1415
}
1516

1617
object ScalacOpt {
1718
private val repeatingKeys = Set(
18-
"-Xplugin:",
19+
"-Xplugin",
1920
"-P", // plugin options
20-
"-language:"
21+
"-language"
2122
)
2223

2324
implicit val hashedType: HashedType[ScalacOpt] = {
2425
opt => opt.value
2526
}
2627
implicit val keyOf: ShadowingSeq.KeyOf[ScalacOpt] =
2728
ShadowingSeq.KeyOf(
28-
_.shadowableKey,
29+
opts =>
30+
opts.headOption.flatMap(_.shadowableKey).orElse(Some(opts.map(_.value).mkString(":"))),
2931
seq => groupCliOptions(seq.map(_.value))
3032
)
3133

modules/options/src/main/scala/scala/build/options/ShadowingSeq.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ final case class ShadowingSeq[T] private (values: Seq[Seq[T]]) {
2828
else {
2929
val l = new mutable.ListBuffer[Seq[T]]
3030
val seen = new mutable.HashSet[String]
31-
3231
for (group <- values.iterator ++ other.iterator) {
3332
assert(group.nonEmpty)
34-
val keyOpt = key.get(group.head)
33+
val keyOpt = key.makeKey(group)
3534
if (!keyOpt.exists(seen.contains)) {
3635
l += group
3736
for (key <- keyOpt)
@@ -58,13 +57,13 @@ final case class ShadowingSeq[T] private (values: Seq[Seq[T]]) {
5857
object ShadowingSeq {
5958

6059
final case class KeyOf[T](
61-
get: T => Option[String],
60+
makeKey: Seq[T] => Option[String],
6261
/** The indices at which sub-groups of values start */
6362
groups: Seq[T] => Seq[Int]
6463
)
6564
object KeyOf {
6665
implicit val keyOfAnyDependency: KeyOf[AnyDependency] =
67-
KeyOf(dep => Some(dep.module.render), _.indices)
66+
KeyOf(deps => deps.headOption.map(_.module.render), _.indices)
6867
}
6968

7069
implicit def monoid[T](implicit key: KeyOf[T]): ConfigMonoid[ShadowingSeq[T]] =

0 commit comments

Comments
 (0)