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