Skip to content

Commit 9f412f5

Browse files
committed
support test scope by ignoring repeated pipelining flags
1 parent f5e822a commit 9f412f5

File tree

7 files changed

+73
-16
lines changed

7 files changed

+73
-16
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private sealed trait YSettings:
441441
val YdebugMacros: Setting[Boolean] = BooleanSetting("-Ydebug-macros", "Show debug info when quote pattern match fails")
442442

443443
// Pipeline compilation options
444-
val YjavaTasty: Setting[Boolean] = BooleanSetting("-Yjava-tasty", "Pickler phase should compute pickles for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"))
445-
val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting("-Yearly-tasty-output", "directory|jar", "Destination for generated .tasty files containing possibly outline type signatures.", NoAbstractFile, aliases = List("-Ypickle-write"))
444+
val YjavaTasty: Setting[Boolean] = BooleanSetting("-Yjava-tasty", "Pickler phase should compute pickles for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true)
445+
val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting("-Yearly-tasty-output", "directory|jar", "Destination for generated .tasty files containing possibly outline type signatures.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true)
446446
val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting("-Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.")
447447
end YSettings

compiler/src/dotty/tools/dotc/config/Settings.scala

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object Settings:
6363
aliases: List[String] = Nil,
6464
depends: List[(Setting[?], Any)] = Nil,
6565
ignoreInvalidArgs: Boolean = false,
66+
preferPrevious: Boolean = false,
6667
propertyClass: Option[Class[?]] = None)(private[Settings] val idx: Int) {
6768

6869
private var changed: Boolean = false
@@ -96,12 +97,17 @@ object Settings:
9697
value0.filter(current.contains).foreach(s => dangers :+= s"Setting $name set to $s redundantly")
9798
current ++ value0
9899
else
99-
if changed then dangers :+= s"Flag $name set repeatedly"
100+
if changed then
101+
assert(!preferPrevious, "should have shortcutted with ignoreValue, side-effect may be present!")
102+
dangers :+= s"Flag $name set repeatedly"
100103
value
101104
changed = true
102105
ArgsSummary(updateIn(sstate, value1), args, errors, dangers)
103106
end update
104107

108+
def ignoreValue(args: List[String]): ArgsSummary =
109+
ArgsSummary(sstate, args, errors, warnings)
110+
105111
def fail(msg: String, args: List[String]) =
106112
ArgsSummary(sstate, args, errors :+ msg, warnings)
107113

@@ -143,7 +149,8 @@ object Settings:
143149

144150
def doSet(argRest: String) = ((summon[ClassTag[T]], args): @unchecked) match {
145151
case (BooleanTag, _) =>
146-
setBoolean(argRest, args)
152+
if changed && preferPrevious then ignoreValue(args)
153+
else setBoolean(argRest, args)
147154
case (OptionTag, _) =>
148155
update(Some(propertyClass.get.getConstructor().newInstance()), args)
149156
case (ListTag, _) =>
@@ -161,14 +168,16 @@ object Settings:
161168
if (arg2 startsWith "-") missingArg
162169
else setString(arg2, args2)
163170
case (OutputTag, arg :: args) =>
164-
val path = Directory(arg)
165-
val isJar = path.ext.isJar
166-
if (!isJar && !path.isDirectory)
167-
fail(s"'$arg' does not exist or is not a directory or .jar file", args)
168-
else {
169-
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
170-
update(output, args)
171-
}
171+
if changed && preferPrevious then ignoreValue(args) // do not risk side effects such as overwriting a jar
172+
else
173+
val path = Directory(arg)
174+
val isJar = path.ext.isJar
175+
if (!isJar && !path.isDirectory)
176+
fail(s"'$arg' does not exist or is not a directory or .jar file", args)
177+
else {
178+
val output = if (isJar) JarArchive.create(path) else new PlainDirectory(path)
179+
update(output, args)
180+
}
172181
case (IntTag, args) if argRest.nonEmpty =>
173182
setInt(argRest, args)
174183
case (IntTag, arg2 :: args2) =>
@@ -281,8 +290,8 @@ object Settings:
281290
setting
282291
}
283292

284-
def BooleanSetting(name: String, descr: String, initialValue: Boolean = false, aliases: List[String] = Nil): Setting[Boolean] =
285-
publish(Setting(name, descr, initialValue, aliases = aliases))
293+
def BooleanSetting(name: String, descr: String, initialValue: Boolean = false, aliases: List[String] = Nil, preferPrevious: Boolean = false): Setting[Boolean] =
294+
publish(Setting(name, descr, initialValue, aliases = aliases, preferPrevious = preferPrevious))
286295

287296
def StringSetting(name: String, helpArg: String, descr: String, default: String, aliases: List[String] = Nil): Setting[String] =
288297
publish(Setting(name, descr, default, helpArg, aliases = aliases))
@@ -308,8 +317,8 @@ object Settings:
308317
def MultiStringSetting(name: String, helpArg: String, descr: String, default: List[String] = Nil, aliases: List[String] = Nil): Setting[List[String]] =
309318
publish(Setting(name, descr, default, helpArg, aliases = aliases))
310319

311-
def OutputSetting(name: String, helpArg: String, descr: String, default: AbstractFile, aliases: List[String] = Nil): Setting[AbstractFile] =
312-
publish(Setting(name, descr, default, helpArg, aliases = aliases))
320+
def OutputSetting(name: String, helpArg: String, descr: String, default: AbstractFile, aliases: List[String] = Nil, preferPrevious: Boolean = false): Setting[AbstractFile] =
321+
publish(Setting(name, descr, default, helpArg, aliases = aliases, preferPrevious = preferPrevious))
313322

314323
def PathSetting(name: String, descr: String, default: String, aliases: List[String] = Nil): Setting[String] =
315324
publish(Setting(name, descr, default, aliases = aliases))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package a
2+
3+
object A {
4+
val foo: (1,2,3) = (1,2,3)
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package a
2+
3+
import a.A
4+
5+
import org.junit.Test
6+
7+
class Hello {
8+
9+
@Test def test(): Unit = {
10+
assert(A.foo == (1,2,3))
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ThisBuild / usePipelining := true
2+
3+
lazy val a = project.in(file("a"))
4+
.settings(
5+
scalacOptions += "-Ycheck:all",
6+
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
7+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := sys.props("plugin.scalaVersion"),
10+
scalacOptions += "-source:3.0-migration"
11+
)
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# run the tests on a project with pipelining
2+
# exercises the fact that -Ypickle-java and -Ypickle-write
3+
# flags are set twice.
4+
# steps:
5+
# - Compile scope is compiled with flags `-Ypickle-java -Ypickle-write early/a-early-7423784.jar`
6+
# - sbt copies `early/a-early-7423784.jar` to `early/a-early.jar`
7+
# - Test scope is compiled with flags `-Ypickle-java -Ypickle-write early-test/a-early-963232.jar -Ypickle-java -Ypickle-write early/a-early.jar -classpath early/a-early.jar`
8+
# e.g. for some reason the classpath has the same `a-early.jar` that
9+
# is passed with `Ypickle-write`.
10+
# Therefore we MUST avoid even reading the second `-Ypickle-write` setting,
11+
# otherwise we will zero-out `a-early.jar`, causing type errors because its contents are blank.
12+
> a/test

0 commit comments

Comments
 (0)