From 469fd20902dcb7e6fae72a2057fbf1837cc7bb80 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Tue, 19 Mar 2019 11:00:54 +0300 Subject: [PATCH] Warn about mistyped phase names in CLI --- .../kotlin/cli/common/createPhaseConfig.kt | 14 +++++++++++++- .../testData/cli/jvm/nonExistingPhaseName.args | 5 +++++ compiler/testData/cli/jvm/nonExistingPhaseName.out | 3 +++ .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/cli/jvm/nonExistingPhaseName.args create mode 100644 compiler/testData/cli/jvm/nonExistingPhaseName.out diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt index 740cd70bb2c..891cc0b8fa6 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt @@ -9,6 +9,8 @@ import org.jetbrains.kotlin.backend.common.phaser.AnyNamedPhase import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.CompilerConfigurationKey @@ -54,5 +56,15 @@ private fun phaseSetFromConfiguration( ): Set { val phaseNames = config.get(key) ?: emptySet() if ("ALL" in phaseNames) return phases.values.toSet() - return phaseNames.map { phases[it]!! }.toSet() + return phaseNames.mapNotNull { + phases[it] ?: run { + warn(config, "no phase named $it, ignoring") + null + } + }.toSet() +} + +private fun warn(config: CompilerConfiguration, message: String) { + val messageCollector = config.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) ?: MessageCollector.NONE + messageCollector.report(CompilerMessageSeverity.WARNING, message) } diff --git a/compiler/testData/cli/jvm/nonExistingPhaseName.args b/compiler/testData/cli/jvm/nonExistingPhaseName.args new file mode 100644 index 00000000000..573ff3c2ed7 --- /dev/null +++ b/compiler/testData/cli/jvm/nonExistingPhaseName.args @@ -0,0 +1,5 @@ +-d +$TEMP_DIR$ +-Xuse-ir +-Xverbose-phases=qz,qq +$TESTDATA_DIR$/simple.kt diff --git a/compiler/testData/cli/jvm/nonExistingPhaseName.out b/compiler/testData/cli/jvm/nonExistingPhaseName.out new file mode 100644 index 00000000000..51a1af33d94 --- /dev/null +++ b/compiler/testData/cli/jvm/nonExistingPhaseName.out @@ -0,0 +1,3 @@ +warning: no phase named qz, ignoring +warning: no phase named qq, ignoring +OK diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 42be0c1b10b..6f021169154 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -486,6 +486,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/nonExistingClassPathAndAnnotationsPath.args"); } + @TestMetadata("nonExistingPhaseName.args") + public void testNonExistingPhaseName() throws Exception { + runTest("compiler/testData/cli/jvm/nonExistingPhaseName.args"); + } + @TestMetadata("nonExistingSourcePath.args") public void testNonExistingSourcePath() throws Exception { runTest("compiler/testData/cli/jvm/nonExistingSourcePath.args");