diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 6a2f9a270e07..5c4df375bfa7 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -340,9 +340,9 @@ private sealed trait XSettings: val XdebugMacros: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xdebug-macros", "Show debug info when quote pattern match fails") /** Pipeline compilation options */ - val XjavaTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Xpickle-java"), preferPrevious = true) - val XearlyTastyOutput: Setting[AbstractFile] = OutputSetting(AdvancedSetting, "Xearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Xpickle-write"), preferPrevious = true) - val XallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.") + val XjavaTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Xpickle-java", "-Yjava-tasty", "-Ypickle-java"), preferPrevious = true) + val XearlyTastyOutput: Setting[AbstractFile] = OutputSetting(AdvancedSetting, "Xearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Xpickle-write", "-Yearly-tasty-output", "-Ypickle-write"), preferPrevious = true) + val XallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(AdvancedSetting, "Xallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", aliases = List("-Yallow-outline-from-tasty")) val XmixinForceForwarders = ChoiceSetting( AdvancedSetting, @@ -490,12 +490,13 @@ private sealed trait YSettings: val YnoEnrichErrorMessages: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-enrich-error-messages", "Show raw error messages, instead of enriching them with contextual information.", deprecation = Some(Deprecation("Use -Xno-enrich-error-messages instead.", "-Xno-enrich-error-messages"))) @deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0") val YdebugMacros: Setting[Boolean] = BooleanSetting(ForkSetting, "Ydebug-macros", "Show debug info when quote pattern match fails", deprecation = Some(Deprecation("Use -Xdebug-macros instead.", "-Xdebug-macros"))) - @deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0") - val YjavaTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xjava-tasty instead.", "-Xjava-tasty"))) - @deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0") - val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xearly-tasty-output instead.", "-Xearly-tasty-output"))) - @deprecated(message = "Lifted to -X, Scheduled for removal in 3.6.0", since = "3.5.0") - val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", deprecation = Some(Deprecation("Use -Xallow-outline-from-tasty instead.", "-Xallow-outline-from-tasty"))) + + // @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0") + // val YjavaTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yjava-tasty", "Pickler phase should compute TASTy for .java defined symbols for use by build tools", aliases = List("-Ypickle-java"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xjava-tasty instead.", "-Xjava-tasty"))) + // @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0") + // val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true, deprecation = Some(Deprecation("Use -Xearly-tasty-output instead.", "-Xearly-tasty-output"))) + // @deprecated(message = "Lifted to -X, Scheduled for removal in 3.8.0", since = "3.7.0") + // val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.", deprecation = Some(Deprecation("Use -Xallow-outline-from-tasty instead.", "-Xallow-outline-from-tasty"))) // Deprecated: lifted from -Y to -W @deprecated(message = "Lifted to -W, Scheduled for removal in 3.6.0", since = "3.5.0") diff --git a/compiler/test/dotty/tools/dotc/SettingsTests.scala b/compiler/test/dotty/tools/dotc/SettingsTests.scala index 8125a80f29f8..24c97dba60b1 100644 --- a/compiler/test/dotty/tools/dotc/SettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala @@ -7,14 +7,19 @@ import reporting.StoreReporter import vulpix.TestConfiguration import core.Contexts.{Context, ContextBase} -import dotty.tools.dotc.config.Settings._ -import dotty.tools.dotc.config.ScalaSettingCategories._ +import dotty.tools.dotc.config.Settings.* +import dotty.tools.dotc.config.Settings.Setting.ChoiceWithHelp +import dotty.tools.dotc.config.ScalaSettingCategories.* import dotty.tools.vulpix.TestConfiguration.mkClasspath +import dotty.tools.io.PlainDirectory +import dotty.tools.io.Directory +import dotty.tools.dotc.config.ScalaVersion import java.nio.file._ import org.junit.Test import org.junit.Assert._ +import scala.util.Using class SettingsTests { @@ -199,6 +204,125 @@ class SettingsTests { assertEquals(List("Flag -qux set repeatedly"), summary.warnings) } + @Test def `Output setting is overriding existing jar`: Unit = + val result = Using.resource(Files.createTempFile("myfile", ".jar").nn){ file => + object Settings extends SettingGroup: + val defaultDir = new PlainDirectory(Directory(".")) + val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir) + + import Settings._ + + val creationTime = Files.getLastModifiedTime(file) + val args = List(s"-testOutput:${file.toString}") + val summary = processArguments(args, processAll = true) + + val creationTimeAfterProcessing = Files.getLastModifiedTime(file) + + assert(creationTimeAfterProcessing.toMillis > creationTime.toMillis, "Jar should have been overriden") + + }(Files.deleteIfExists(_)) + + @Test def `Output setting is respecting previous setting`: Unit = + val result = Using.resources( + Files.createTempFile("myfile", ".jar").nn, Files.createTempFile("myfile2", ".jar").nn + ){ (file1, file2) => + object Settings extends SettingGroup: + val defaultDir = new PlainDirectory(Directory(".")) + val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true) + + import Settings._ + + Files.writeString(file1, "test1") + Files.writeString(file2, "test2") + + val file1StateBefore = Files.readString(file1) + val file2StateBefore = Files.readString(file2) + + val creationTime = Files.getLastModifiedTime(file1) + val args = List(s"-testOutput:${file1.toString}", s"-testOutput:${file2.toString}") + val summary = processArguments(args, processAll = true) + + // The output is a new filesystem without information of original path + // We can't check the `testOutput.value` as in other tests. + assertNotEquals(file1StateBefore, Files.readString(file1)) + assertEquals(file2StateBefore, Files.readString(file2)) + + }(Files.deleteIfExists(_), Files.deleteIfExists(_)) + + @Test def `Output side effect is not present when setting is deprecated`: Unit = + val result = Using.resource(Files.createTempFile("myfile", ".jar").nn){ file => + object Settings extends SettingGroup: + val defaultDir = new PlainDirectory(Directory(".")) + val testOutput = OutputSetting(RootSetting, "testOutput", "testOutput", "", defaultDir, preferPrevious = true, deprecation = Some(Deprecation("deprecated", "XtestOutput"))) + + import Settings._ + + val creationTime = Files.getLastModifiedTime(file) + val args = List(s"-testOutput:${file.toString}") + val summary = processArguments(args, processAll = true) + + val creationTimeAfterProcessing = Files.getLastModifiedTime(file) + + assertEquals(creationTimeAfterProcessing, creationTime) + + }(Files.deleteIfExists(_)) + + @Test def `Arguments of flags are correctly parsed with both ":" and " " separating`: Unit = + object Settings extends SettingGroup: + val booleanSetting = BooleanSetting(RootSetting, "booleanSetting", "booleanSetting", false) + val stringSetting = StringSetting(RootSetting, "stringSetting", "stringSetting", "", "test") + val choiceSetting = ChoiceSetting(RootSetting, "choiceSetting", "choiceSetting", "", List("a", "b"), "a") + val multiChoiceSetting= MultiChoiceSetting(RootSetting, "multiChoiceSetting", "multiChoiceSetting", "", List("a", "b"), List()) + val multiChoiceHelpSetting= MultiChoiceHelpSetting(RootSetting, "multiChoiceHelpSetting", "multiChoiceHelpSetting", "", List(ChoiceWithHelp("a", "a"), ChoiceWithHelp("b", "b")), List()) + val intSetting = IntSetting(RootSetting, "intSetting", "intSetting", 0) + val intChoiceSetting = IntChoiceSetting(RootSetting, "intChoiceSetting", "intChoiceSetting", List(1,2,3), 1) + val multiStringSetting = MultiStringSetting(RootSetting, "multiStringSetting", "multiStringSetting", "", List("a", "b"), List()) + val outputSetting = OutputSetting(RootSetting, "outputSetting", "outputSetting", "", new PlainDirectory(Directory("."))) + val pathSetting = PathSetting(RootSetting, "pathSetting", "pathSetting", ".") + val phasesSetting = PhasesSetting(RootSetting, "phasesSetting", "phasesSetting", "all") + val versionSetting= VersionSetting(RootSetting, "versionSetting", "versionSetting") + + import Settings._ + Using.resource(Files.createTempDirectory("testDir")) { dir => + + val args = List( + List("-booleanSetting", "true"), + List("-stringSetting", "newTest"), + List("-choiceSetting", "b"), + List("-multiChoiceSetting", "a,b"), + List("-multiChoiceHelpSetting", "a,b"), + List("-intSetting", "42"), + List("-intChoiceSetting", "2"), + List("-multiStringSetting", "a,b"), + List("-outputSetting", dir.toString), + List("-pathSetting", dir.toString), + List("-phasesSetting", "parser,typer"), + List("-versionSetting", "1.0.0"), + ) + + def testValues(summary: ArgsSummary) = + withProcessedArgs(summary) { + assertEquals(true, booleanSetting.value) + assertEquals("newTest", stringSetting.value) + assertEquals("b", choiceSetting.value) + assertEquals(List("a", "b"), multiChoiceSetting.value) + assertEquals(List("a", "b"), multiChoiceHelpSetting.value) + assertEquals(42, intSetting.value) + assertEquals(2, intChoiceSetting.value) + assertEquals(List("a", "b"), multiStringSetting.value) + assertEquals(dir.toString, outputSetting.value.path) + assertEquals(dir.toString, pathSetting.value) + assertEquals(List("parser", "typer"), phasesSetting.value) + assertEquals(ScalaVersion.parse("1.0.0").get, versionSetting.value) + } + + val summaryColon = processArguments(args.map(_.mkString(":")), processAll = true) + val summaryWhitespace = processArguments(args.flatten, processAll = true) + testValues(summary = summaryColon) + testValues(summary = summaryWhitespace) + + }(Files.deleteIfExists(_)) + private def withProcessedArgs(summary: ArgsSummary)(f: SettingsState ?=> Unit) = f(using summary.sstate) extension [T](setting: Setting[T]) diff --git a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala index c33002326609..9ebde841c50b 100644 --- a/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala +++ b/compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala @@ -108,9 +108,9 @@ class ScalaSettingsTests: createTestCase(settings.YnoDecodeStacktraces , settings.XnoDecodeStacktraces), createTestCase(settings.YnoEnrichErrorMessages, settings.XnoEnrichErrorMessages), createTestCase(settings.YdebugMacros , settings.XdebugMacros), - createTestCase(settings.YjavaTasty , settings.XjavaTasty), - createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"), - createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty), + // createTestCase(settings.YjavaTasty , settings.XjavaTasty), + // createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"), + // createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty), createTestCase(settings.YcheckInit , settings.WcheckInit), createTestCase(settings.Xlint , settings.Wshadow, ":all"), ).map: (deprecatedArgument, newSetting) => @@ -137,9 +137,9 @@ class ScalaSettingsTests: createTestCase(settings.YnoDecodeStacktraces , settings.XnoDecodeStacktraces), createTestCase(settings.YnoEnrichErrorMessages, settings.XnoEnrichErrorMessages), createTestCase(settings.YdebugMacros , settings.XdebugMacros), - createTestCase(settings.YjavaTasty , settings.XjavaTasty), - createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput), - createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty), + // createTestCase(settings.YjavaTasty , settings.XjavaTasty), + // createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput), + // createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty), createTestCase(settings.YcheckInit , settings.WcheckInit), createTestCase(settings.Xlint , settings.Wshadow), ).map: (deprecatedArgument, newSetting) => @@ -167,9 +167,9 @@ class ScalaSettingsTests: createTestCase(settings.YnoDecodeStacktraces , settings.XnoDecodeStacktraces), createTestCase(settings.YnoEnrichErrorMessages, settings.XnoEnrichErrorMessages), createTestCase(settings.YdebugMacros , settings.XdebugMacros), - createTestCase(settings.YjavaTasty , settings.XjavaTasty), - createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"), - createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty), + // createTestCase(settings.YjavaTasty , settings.XjavaTasty), + // createTestCase(settings.YearlyTastyOutput , settings.XearlyTastyOutput, ":./"), + // createTestCase(settings.YallowOutlineFromTasty, settings.XallowOutlineFromTasty), createTestCase(settings.YcheckInit , settings.WcheckInit), createTestCase(settings.Xlint , settings.Wshadow, ":all"), ).flatten.map: (deprecatedArgument, newSetting) =>