diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 07884486d25..2c37df3e028 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -171,19 +171,22 @@ public open class K2JVMCompiler : CLICompiler() { val compilerConfiguration = KotlinToJVMBytecodeCompiler.createCompilerConfiguration(configuration, moduleScript.getModules(), directory) environment = createCoreEnvironment(rootDisposable, compilerConfiguration) + if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR + KotlinToJVMBytecodeCompiler.compileModules(environment, configuration, moduleScript.getModules(), directory, jar, arguments.includeRuntime) } else if (arguments.script) { val scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size()) environment = createCoreEnvironment(rootDisposable, configuration) + + if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR + KotlinToJVMBytecodeCompiler.compileAndExecuteScript(configuration, paths, environment, scriptArgs) } else { environment = createCoreEnvironment(rootDisposable, configuration) - if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) { - return COMPILATION_ERROR - } + if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR if (environment.getSourceFiles().isEmpty()) { messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 19689a3c54f..ab1cac76491 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -85,11 +85,6 @@ public class KotlinToJVMBytecodeCompiler { if (!source.isAbsolute()) { source = new File(directory, sourceFile); } - - if (!source.exists()) { - throw new CompileEnvironmentException("'" + source + "' does not exist in module " + module.getModuleName()); - } - result.add(source.getAbsolutePath()); } return result; diff --git a/compiler/testData/cli/jvm/nonexistentPathInModule.args b/compiler/testData/cli/jvm/nonexistentPathInModule.args new file mode 100644 index 00000000000..bf3db449d6b --- /dev/null +++ b/compiler/testData/cli/jvm/nonexistentPathInModule.args @@ -0,0 +1,2 @@ +-module +$TESTDATA_DIR$/nonexistentPathInModule.xml diff --git a/compiler/testData/cli/jvm/nonexistentPathInModule.out b/compiler/testData/cli/jvm/nonexistentPathInModule.out new file mode 100644 index 00000000000..56f17b9ff22 --- /dev/null +++ b/compiler/testData/cli/jvm/nonexistentPathInModule.out @@ -0,0 +1,3 @@ +error: source file or directory not found: $TESTDATA_DIR$/nonexistentFile.kt +error: source file or directory not found: $TESTDATA_DIR$/some/nonexistent/dir +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/nonexistentPathInModule.xml b/compiler/testData/cli/jvm/nonexistentPathInModule.xml new file mode 100644 index 00000000000..1ddd1289d9a --- /dev/null +++ b/compiler/testData/cli/jvm/nonexistentPathInModule.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/compiler/testData/cli/jvm/nonexistentScript.args b/compiler/testData/cli/jvm/nonexistentScript.args new file mode 100644 index 00000000000..0bb0463a006 --- /dev/null +++ b/compiler/testData/cli/jvm/nonexistentScript.args @@ -0,0 +1,2 @@ +-script +path/to/nonexistent.kts diff --git a/compiler/testData/cli/jvm/nonexistentScript.out b/compiler/testData/cli/jvm/nonexistentScript.out new file mode 100644 index 00000000000..2dc22bb8c2b --- /dev/null +++ b/compiler/testData/cli/jvm/nonexistentScript.out @@ -0,0 +1,2 @@ +error: source file or directory not found: path/to/nonexistent.kts +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java b/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java index f9631cf9902..c7c2137f954 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java @@ -53,6 +53,16 @@ public class CliCommonTest extends CliBaseTest { executeCompilerCompareOutputJVM(); } + @Test + public void nonexistentPathInModule() throws Exception { + executeCompilerCompareOutputJVM(); + } + + @Test + public void nonexistentScript() throws Exception { + executeCompilerCompareOutputJVM(); + } + @Test public void diagnosticsOrder() throws Exception { executeCompilerCompareOutputJVM(); diff --git a/compiler/tests/org/jetbrains/kotlin/cli/KotlincExecutableTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/KotlincExecutableTestGenerated.java index e05d7028713..c25dbf21b7c 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/KotlincExecutableTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/KotlincExecutableTestGenerated.java @@ -169,6 +169,18 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes doJvmTest(fileName); } + @TestMetadata("nonexistentPathInModule.args") + public void testNonexistentPathInModule() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/jvm/nonexistentPathInModule.args"); + doJvmTest(fileName); + } + + @TestMetadata("nonexistentScript.args") + public void testNonexistentScript() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/jvm/nonexistentScript.args"); + doJvmTest(fileName); + } + @TestMetadata("pluginSimple.args") public void testPluginSimple() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/jvm/pluginSimple.args");