From 96e9d690a6c078e3de4ffe7987733728a20dfdfd Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 29 Mar 2023 10:44:28 +0300 Subject: [PATCH] [CLI] Prohibit passing HMPP module structure with CLI arguments to metadata compiler ^KT-57644 Fixed --- .../kotlin/cli/metadata/K2MetadataCompiler.kt | 6 +++++- .../metadata/{successfulHmpp.args => hmppModules.args} | 0 .../metadata/{successfulHmpp.out => hmppModules.out} | 3 ++- .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 10 +++++----- 4 files changed, 12 insertions(+), 7 deletions(-) rename compiler/testData/cli/metadata/{successfulHmpp.args => hmppModules.args} (100%) rename compiler/testData/cli/metadata/{successfulHmpp.out => hmppModules.out} (73%) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt index 7c2be4d129f..0dadfa2be1f 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/metadata/K2MetadataCompiler.kt @@ -66,8 +66,12 @@ class K2MetadataCompiler : CLICompiler() { val commonSources = arguments.commonSources?.toSet() ?: emptySet() val hmppCliModuleStructure = configuration.get(CommonConfigurationKeys.HMPP_MODULE_STRUCTURE) + if (hmppCliModuleStructure != null) { + collector.report(ERROR, "HMPP module structure should not be passed during metadata compilation. Please remove `-Xfragments` and related flags") + return ExitCode.COMPILATION_ERROR + } for (arg in arguments.freeArgs) { - configuration.addKotlinSourceRoot(arg, isCommon = arg in commonSources, hmppCliModuleStructure?.getModuleNameForSource(arg)) + configuration.addKotlinSourceRoot(arg, isCommon = arg in commonSources, hmppModuleName = null) } if (arguments.classpath != null) { configuration.addJvmClasspathRoots(arguments.classpath!!.split(File.pathSeparatorChar).map(::File)) diff --git a/compiler/testData/cli/metadata/successfulHmpp.args b/compiler/testData/cli/metadata/hmppModules.args similarity index 100% rename from compiler/testData/cli/metadata/successfulHmpp.args rename to compiler/testData/cli/metadata/hmppModules.args diff --git a/compiler/testData/cli/metadata/successfulHmpp.out b/compiler/testData/cli/metadata/hmppModules.out similarity index 73% rename from compiler/testData/cli/metadata/successfulHmpp.out rename to compiler/testData/cli/metadata/hmppModules.out index 0afdba6a4b9..f96d1e5daf3 100644 --- a/compiler/testData/cli/metadata/successfulHmpp.out +++ b/compiler/testData/cli/metadata/hmppModules.out @@ -8,4 +8,5 @@ as no stability/compatibility guarantees are given on compiler or generated code. Use it at your own risk! warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features -OK +error: HMPP module structure should not be passed during metadata compilation. Please remove `-Xfragments` and related flags +COMPILATION_ERROR diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 60851eb1b78..01e9381d752 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -1594,6 +1594,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/metadata/anonymousObjectTypeWithFir.args"); } + @TestMetadata("hmppModules.args") + public void testHmppModules() throws Exception { + runTest("compiler/testData/cli/metadata/hmppModules.args"); + } + @TestMetadata("inheritorOfExpectSealedClass.args") public void testInheritorOfExpectSealedClass() throws Exception { runTest("compiler/testData/cli/metadata/inheritorOfExpectSealedClass.args"); @@ -1653,10 +1658,5 @@ public class CliTestGenerated extends AbstractCliTest { public void testOptionalExpectationUsageWithFir() throws Exception { runTest("compiler/testData/cli/metadata/optionalExpectationUsageWithFir.args"); } - - @TestMetadata("successfulHmpp.args") - public void testSuccessfulHmpp() throws Exception { - runTest("compiler/testData/cli/metadata/successfulHmpp.args"); - } } }