JS backend: check libraries in cli compiler before translation
This commit is contained in:
@@ -28,6 +28,8 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.OutputFileCollection;
|
||||
@@ -79,7 +81,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
protected ExitCode doExecute(
|
||||
@NotNull K2JSCompilerArguments arguments,
|
||||
@NotNull Services services,
|
||||
@NotNull MessageCollector messageCollector,
|
||||
@NotNull final MessageCollector messageCollector,
|
||||
@NotNull Disposable rootDisposable
|
||||
) {
|
||||
if (arguments.freeArgs.isEmpty()) {
|
||||
@@ -109,6 +111,16 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
File outputFile = new File(arguments.outputFile);
|
||||
|
||||
Config config = getConfig(arguments, project);
|
||||
if (config.checkLibFilesAndReportErrors(new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String message) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
||||
return Unit.INSTANCE$;
|
||||
}
|
||||
})) {
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (analyzeAndReportErrors(messageCollector, sourcesFiles, config)) {
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/withLib.kt
|
||||
-library-files
|
||||
not/existing/path
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
@@ -0,0 +1,2 @@
|
||||
ERROR: Path 'not/existing/path'does not exist
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/withLib.kt
|
||||
-library-files
|
||||
compiler/integration-tests/testData/ant/js/simpleWithStdlibAndFolderAsAnotherLib
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
@@ -0,0 +1,2 @@
|
||||
ERROR: 'compiler/integration-tests/testData/ant/js/simpleWithStdlibAndFolderAsAnotherLib' is not a valid Kotlin Javascript library
|
||||
COMPILATION_ERROR
|
||||
@@ -168,6 +168,12 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
|
||||
doJsTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("libraryDirNotFound.args")
|
||||
public void testLibraryDirNotFound() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/js/libraryDirNotFound.args");
|
||||
doJsTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nativeDeclarations.args")
|
||||
public void testNativeDeclarations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/js/nativeDeclarations.args");
|
||||
@@ -180,6 +186,12 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
|
||||
doJsTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notValidLibraryDir.args")
|
||||
public void testNotValidLibraryDir() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/js/notValidLibraryDir.args");
|
||||
doJsTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("outputPostfixFileNotFound.args")
|
||||
public void testOutputPostfixFileNotFound() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/cli/js/outputPostfixFileNotFound.args");
|
||||
|
||||
@@ -76,4 +76,18 @@ public class K2JsCliTest extends CliBaseTest {
|
||||
|
||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void libraryDirNotFound() throws Exception {
|
||||
executeCompilerCompareOutputJS();
|
||||
|
||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notValidLibraryDir() throws Exception {
|
||||
executeCompilerCompareOutputJS();
|
||||
|
||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user