Support "-d" option in kotlinc-jvm
The intent is to unify "-output" and "-jar" options into the one "-d" (destination)
This commit is contained in:
+4
@@ -24,6 +24,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@Argument(value = "d", description = "Destination for generated class files")
|
||||
@ValueDescription("<directory|jar>")
|
||||
public String destination;
|
||||
|
||||
@Argument(value = "jar", description = "Resulting .jar file path")
|
||||
@ValueDescription("<path>")
|
||||
public String jar;
|
||||
|
||||
@@ -117,8 +117,19 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
try {
|
||||
configureEnvironment(configuration, arguments);
|
||||
|
||||
File jar = arguments.jar != null ? new File(arguments.jar) : null;
|
||||
File outputDir = arguments.outputDir != null ? new File(arguments.outputDir) : null;
|
||||
String destination = arguments.destination;
|
||||
|
||||
File jar;
|
||||
File outputDir;
|
||||
if (destination != null) {
|
||||
boolean isJar = destination.endsWith(".jar");
|
||||
jar = isJar ? new File(destination) : null;
|
||||
outputDir = isJar ? null : new File(destination);
|
||||
}
|
||||
else {
|
||||
jar = arguments.jar != null ? new File(arguments.jar) : null;
|
||||
outputDir = arguments.outputDir != null ? new File(arguments.outputDir) : null;
|
||||
}
|
||||
|
||||
if (arguments.module != null) {
|
||||
MessageCollector sanitizedCollector = new FilteringMessageCollector(messageCollector, in(CompilerMessageSeverity.VERBOSE));
|
||||
@@ -129,14 +140,15 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
}
|
||||
|
||||
if (outputDir != null) {
|
||||
messageCollector.report(CompilerMessageSeverity.WARNING, "The '-output' option is ignored because '-module' is specified",
|
||||
messageCollector.report(CompilerMessageSeverity.WARNING,
|
||||
"The '-d' option with a directory destination is ignored because '-module' is specified",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
}
|
||||
|
||||
File directory = new File(arguments.module).getAbsoluteFile().getParentFile();
|
||||
KotlinToJVMBytecodeCompiler.compileModules(configuration, moduleScript.getModules(),
|
||||
directory, jar,
|
||||
arguments.includeRuntime);
|
||||
KotlinToJVMBytecodeCompiler.compileModules(
|
||||
configuration, moduleScript.getModules(), directory, jar, arguments.includeRuntime
|
||||
);
|
||||
}
|
||||
else if (arguments.script) {
|
||||
List<String> scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size());
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
public void compileAndRunHelloApp() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-jar", jar));
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-d", jar));
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
public void compileAndRunHelloAppFQMain() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-jar", jar));
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-d", jar));
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
public void compileAndRunHelloAppVarargMain() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-jar", jar));
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-includeRuntime", "hello.kt", "-d", jar));
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
public void compileAndRunModule() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("Smoke.compile", "-module", "Smoke.ktm", "-jar", jar));
|
||||
assertEquals("compilation failed", 0, runCompiler("Smoke.compile", "-module", "Smoke.ktm", "-d", jar));
|
||||
runJava("Smoke.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "Smoke.SmokePackage", "1", "2", "3");
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
public void compilationFailed() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
runCompiler("hello.compile", "hello.kt", "-jar", jar);
|
||||
runCompiler("hello.compile", "hello.kt", "-d", jar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syntaxErrors() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
runCompiler("test.compile", "test.kt", "-jar", jar);
|
||||
runCompiler("test.compile", "test.kt", "-d", jar);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
$TESTDATA_DIR$/classpath.kt
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
$TESTDATA_DIR$/conflictingOverloads.kt
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$TESTDATA_DIR$/diagnosticsOrder1.kt
|
||||
$TESTDATA_DIR$/diagnosticsOrder2.kt
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1 +1 @@
|
||||
-help
|
||||
-help
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Usage: kotlinc-jvm <options> <source files>
|
||||
where possible options include:
|
||||
-d <directory|jar> Destination for generated class files
|
||||
-jar <path> Resulting .jar file path
|
||||
-output <path> Output directory path for .class files
|
||||
-classpath <path> Paths where to find user class files
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
-inline
|
||||
off
|
||||
-help
|
||||
-help
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Usage: kotlinc-jvm <options> <source files>
|
||||
where possible options include:
|
||||
-d <directory|jar> Destination for generated class files
|
||||
-jar <path> Resulting .jar file path
|
||||
-output <path> Output directory path for .class files
|
||||
-classpath <path> Paths where to find user class files
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
-inline
|
||||
on
|
||||
-help
|
||||
-help
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Usage: kotlinc-jvm <options> <source files>
|
||||
where possible options include:
|
||||
-d <directory|jar> Destination for generated class files
|
||||
-jar <path> Resulting .jar file path
|
||||
-output <path> Output directory path for .class files
|
||||
-classpath <path> Paths where to find user class files
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
-inline
|
||||
wrong
|
||||
wrong
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false'
|
||||
Usage: kotlinc-jvm <options> <source files>
|
||||
where possible options include:
|
||||
-d <directory|jar> Destination for generated class files
|
||||
-jar <path> Resulting .jar file path
|
||||
-output <path> Output directory path for .class files
|
||||
-classpath <path> Paths where to find user class files
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
$TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -3,5 +3,5 @@ $TESTDATA_DIR$/simple.kt
|
||||
not/existing/path
|
||||
-annotations
|
||||
yet/another/not/existing/path
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
not/existing/path
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
$TESTDATA_DIR$/signatureClash.kt
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
$TESTDATA_DIR$/simple.kt
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$TESTDATA_DIR$/../warnings.kt
|
||||
-suppress
|
||||
warnings
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$TESTDATA_DIR$/../warnings.kt
|
||||
-suppress
|
||||
WaRnInGs
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$TESTDATA_DIR$/wrongAbiVersion.kt
|
||||
-classpath
|
||||
$TESTDATA_DIR$/wrongAbiVersionLib
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -1 +1 @@
|
||||
-wrongArgument
|
||||
-wrongArgument
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Invalid argument: -wrongArgument
|
||||
Usage: kotlinc-jvm <options> <source files>
|
||||
where possible options include:
|
||||
-d <directory|jar> Destination for generated class files
|
||||
-jar <path> Resulting .jar file path
|
||||
-output <path> Output directory path for .class files
|
||||
-classpath <path> Paths where to find user class files
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$TESTDATA_DIR$/wrongKotlinSignature.kt
|
||||
-classpath
|
||||
$TESTDATA_DIR$/wrongKotlinSignatureLib
|
||||
-output
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class MockLibraryUtil {
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MockLibraryUtil {
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
Enum<?> invocationResult = (Enum<?>) execMethod.invoke(
|
||||
compilerObject, new PrintStream(outStream),
|
||||
new String[] {sourcesPath, "-output", outDir.getAbsolutePath(), "-classpath", sourcesPath}
|
||||
new String[] {sourcesPath, "-d", outDir.getAbsolutePath(), "-classpath", sourcesPath}
|
||||
);
|
||||
|
||||
assertEquals(new String(outStream.toByteArray()), ExitCode.OK.name(), invocationResult.name());
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ForTestCompileRuntime {
|
||||
@NotNull String... src
|
||||
) {
|
||||
List<String> args = KotlinPackage.arrayListOf(
|
||||
"-output", destDir.getPath(),
|
||||
"-d", destDir.getPath(),
|
||||
"-noStdlib",
|
||||
"-noJdkAnnotations",
|
||||
"-suppress", "warnings",
|
||||
|
||||
@@ -44,13 +44,15 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
File stdlib = ForTestCompileRuntime.runtimeJarForTests();
|
||||
File jdkAnnotations = JetTestUtils.getJdkAnnotationsJar();
|
||||
File resultJar = new File(tempDir, "result.jar");
|
||||
ExitCode rv = new K2JVMCompiler().exec(System.out,
|
||||
"-module", JetTestCaseBuilder.getTestDataPathBase() + "/compiler/smoke/Smoke.ktm",
|
||||
"-jar", resultJar.getAbsolutePath(),
|
||||
"-noStdlib",
|
||||
"-classpath", stdlib.getAbsolutePath(),
|
||||
"-noJdkAnnotations",
|
||||
"-annotations", jdkAnnotations.getAbsolutePath());
|
||||
ExitCode rv = new K2JVMCompiler().exec(
|
||||
System.out,
|
||||
"-module", JetTestCaseBuilder.getTestDataPathBase() + "/compiler/smoke/Smoke.ktm",
|
||||
"-d", resultJar.getAbsolutePath(),
|
||||
"-noStdlib",
|
||||
"-classpath", stdlib.getAbsolutePath(),
|
||||
"-noJdkAnnotations",
|
||||
"-annotations", jdkAnnotations.getAbsolutePath()
|
||||
);
|
||||
Assert.assertEquals("compilation completed with non-zero code", ExitCode.OK, rv);
|
||||
FileInputStream fileInputStream = new FileInputStream(resultJar);
|
||||
try {
|
||||
@@ -81,9 +83,8 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
File jdkAnnotations = JetTestUtils.getJdkAnnotationsJar();
|
||||
ExitCode exitCode = new K2JVMCompiler().exec(
|
||||
System.out,
|
||||
JetTestCaseBuilder.getTestDataPathBase() +
|
||||
"/compiler/smoke/Smoke.kt",
|
||||
"-output", out.getAbsolutePath(),
|
||||
JetTestCaseBuilder.getTestDataPathBase() + "/compiler/smoke/Smoke.kt",
|
||||
"-d", out.getAbsolutePath(),
|
||||
"-noStdlib",
|
||||
"-classpath", stdlib.getAbsolutePath(),
|
||||
"-noJdkAnnotations",
|
||||
|
||||
@@ -34,7 +34,7 @@ class KDocCompiler() : K2JVMCompiler() {
|
||||
}
|
||||
|
||||
protected override fun usage(target : PrintStream) {
|
||||
target.println("Usage: KDocCompiler -docOutput <docOutputDir> [-output <outputDir>|-jar <jarFileName>] [-stdlib <path to runtime.jar>] [<filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||
target.println("Usage: KDocCompiler -docOutput <docOutputDir> -d [<outputDir>|<jarFileName>] [-stdlib <path to runtime.jar>] [<filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user