Support "-module-name" argument for common code compiler
#KT-20892 Fixed
This commit is contained in:
+3
@@ -31,4 +31,7 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() {
|
|||||||
description = "Paths where to find library .kotlin_metadata files"
|
description = "Paths where to find library .kotlin_metadata files"
|
||||||
)
|
)
|
||||||
var classpath: String? by FreezableVar(null)
|
var classpath: String? by FreezableVar(null)
|
||||||
|
|
||||||
|
@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file")
|
||||||
|
var moduleName: String? by FreezableVar(null)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
|
|||||||
configuration.addJvmClasspathRoots(arguments.classpath!!.split(File.pathSeparatorChar).map(::File))
|
configuration.addJvmClasspathRoots(arguments.classpath!!.split(File.pathSeparatorChar).map(::File))
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
|
configuration.put(CommonConfigurationKeys.MODULE_NAME, arguments.moduleName ?: JvmAbi.DEFAULT_MODULE_NAME)
|
||||||
|
|
||||||
val destination = arguments.destination
|
val destination = arguments.destination
|
||||||
if (destination != null) {
|
if (destination != null) {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
$TESTDATA_DIR$/moduleName.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-module-name
|
||||||
|
foo
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
expect fun bar()
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: META-INF/foo.kotlin_module
|
||||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.cli.common.ExitCode;
|
|||||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
||||||
import org.jetbrains.kotlin.cli.js.dce.K2JSDce;
|
import org.jetbrains.kotlin.cli.js.dce.K2JSDce;
|
||||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||||
|
import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler;
|
||||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion;
|
import org.jetbrains.kotlin.config.KotlinCompilerVersion;
|
||||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
|
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
|
||||||
import org.jetbrains.kotlin.test.CompilerTestUtil;
|
import org.jetbrains.kotlin.test.CompilerTestUtil;
|
||||||
@@ -195,6 +196,10 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
|||||||
doTest(fileName, new K2JSDce());
|
doTest(fileName, new K2JSDce());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void doMetadataTest(@NotNull String fileName) {
|
||||||
|
doTest(fileName, new K2MetadataCompiler());
|
||||||
|
}
|
||||||
|
|
||||||
public static String removePerfOutput(String output) {
|
public static String removePerfOutput(String output) {
|
||||||
String[] lines = StringUtil.splitByLinesKeepSeparators(output);
|
String[] lines = StringUtil.splitByLinesKeepSeparators(output);
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
|||||||
@@ -818,4 +818,19 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
doJsDceTest(fileName);
|
doJsDceTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/cli/metadata")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Metadata extends AbstractCliTest {
|
||||||
|
public void testAllFilesPresentInMetadata() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cli/metadata"), Pattern.compile("^(.+)\\.args$"), TargetBackend.ANY, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("moduleName.args")
|
||||||
|
public void testModuleName() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/metadata/moduleName.args");
|
||||||
|
doMetadataTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,6 +284,7 @@ fun main(args: Array<String>) {
|
|||||||
model("cli/jvm", extension = "args", testMethod = "doJvmTest", recursive = false)
|
model("cli/jvm", extension = "args", testMethod = "doJvmTest", recursive = false)
|
||||||
model("cli/js", extension = "args", testMethod = "doJsTest", recursive = false)
|
model("cli/js", extension = "args", testMethod = "doJsTest", recursive = false)
|
||||||
model("cli/js-dce", extension = "args", testMethod = "doJsDceTest", recursive = false)
|
model("cli/js-dce", extension = "args", testMethod = "doJsDceTest", recursive = false)
|
||||||
|
model("cli/metadata", extension = "args", testMethod = "doMetadataTest", recursive = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass<AbstractReplInterpreterTest> {
|
testClass<AbstractReplInterpreterTest> {
|
||||||
|
|||||||
Reference in New Issue
Block a user