kotlinc-js, kotlinc-jvm: report error on empty sources
This commit is contained in:
@@ -36,10 +36,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
|||||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants;
|
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants;
|
||||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
import org.jetbrains.kotlin.cli.common.messages.*;
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation;
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
|
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
|
||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompilerJarLocator;
|
import org.jetbrains.kotlin.cli.jvm.compiler.CompilerJarLocator;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
@@ -84,16 +81,18 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
protected ExitCode doExecute(
|
protected ExitCode doExecute(
|
||||||
@NotNull K2JSCompilerArguments arguments,
|
@NotNull K2JSCompilerArguments arguments,
|
||||||
@NotNull Services services,
|
@NotNull Services services,
|
||||||
@NotNull final MessageCollector messageCollector,
|
@NotNull MessageCollector messageCollector,
|
||||||
@NotNull Disposable rootDisposable
|
@NotNull Disposable rootDisposable
|
||||||
) {
|
) {
|
||||||
|
final MessageSeverityCollector messageSeverityCollector = new MessageSeverityCollector(messageCollector);
|
||||||
|
|
||||||
if (arguments.freeArgs.isEmpty()) {
|
if (arguments.freeArgs.isEmpty()) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
|
||||||
return ExitCode.INTERNAL_ERROR;
|
return ExitCode.INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageSeverityCollector);
|
||||||
|
|
||||||
CompilerJarLocator locator = services.get(CompilerJarLocator.class);
|
CompilerJarLocator locator = services.get(CompilerJarLocator.class);
|
||||||
if (locator != null) {
|
if (locator != null) {
|
||||||
@@ -107,13 +106,22 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
Project project = environmentForJS.getProject();
|
Project project = environmentForJS.getProject();
|
||||||
List<JetFile> sourcesFiles = environmentForJS.getSourceFiles();
|
List<JetFile> sourcesFiles = environmentForJS.getSourceFiles();
|
||||||
|
|
||||||
if (arguments.verbose) {
|
if (arguments.outputFile == null) {
|
||||||
reportCompiledSourcesList(messageCollector, sourcesFiles);
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify output file via -output", CompilerMessageLocation.NO_LOCATION);
|
||||||
|
return ExitCode.INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.outputFile == null) {
|
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify output file via -output", CompilerMessageLocation.NO_LOCATION);
|
return ExitCode.COMPILATION_ERROR;
|
||||||
return ExitCode.INTERNAL_ERROR;
|
}
|
||||||
|
|
||||||
|
if (sourcesFiles.isEmpty()) {
|
||||||
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION);
|
||||||
|
return COMPILATION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.verbose) {
|
||||||
|
reportCompiledSourcesList(messageSeverityCollector, sourcesFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
File outputFile = new File(arguments.outputFile);
|
File outputFile = new File(arguments.outputFile);
|
||||||
@@ -122,14 +130,14 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
if (config.checkLibFilesAndReportErrors(new Function1<String, Unit>() {
|
if (config.checkLibFilesAndReportErrors(new Function1<String, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(String message) {
|
public Unit invoke(String message) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
||||||
return Unit.INSTANCE$;
|
return Unit.INSTANCE$;
|
||||||
}
|
}
|
||||||
})) {
|
})) {
|
||||||
return COMPILATION_ERROR;
|
return COMPILATION_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalyzerWithCompilerReport analyzerWithCompilerReport = analyzeAndReportErrors(messageCollector, sourcesFiles, config);
|
AnalyzerWithCompilerReport analyzerWithCompilerReport = analyzeAndReportErrors(messageSeverityCollector, sourcesFiles, config);
|
||||||
if (analyzerWithCompilerReport.hasErrors()) {
|
if (analyzerWithCompilerReport.hasErrors()) {
|
||||||
return COMPILATION_ERROR;
|
return COMPILATION_ERROR;
|
||||||
}
|
}
|
||||||
@@ -142,7 +150,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
if (arguments.outputPrefix != null) {
|
if (arguments.outputPrefix != null) {
|
||||||
outputPrefixFile = new File(arguments.outputPrefix);
|
outputPrefixFile = new File(arguments.outputPrefix);
|
||||||
if (!outputPrefixFile.exists()) {
|
if (!outputPrefixFile.exists()) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR,
|
||||||
"Output prefix file '" + arguments.outputPrefix + "' not found",
|
"Output prefix file '" + arguments.outputPrefix + "' not found",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
return ExitCode.COMPILATION_ERROR;
|
return ExitCode.COMPILATION_ERROR;
|
||||||
@@ -153,7 +161,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
if (arguments.outputPostfix != null) {
|
if (arguments.outputPostfix != null) {
|
||||||
outputPostfixFile = new File(arguments.outputPostfix);
|
outputPostfixFile = new File(arguments.outputPostfix);
|
||||||
if (!outputPostfixFile.exists()) {
|
if (!outputPostfixFile.exists()) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR,
|
||||||
"Output postfix file '" + arguments.outputPostfix + "' not found",
|
"Output postfix file '" + arguments.outputPostfix + "' not found",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
return ExitCode.COMPILATION_ERROR;
|
return ExitCode.COMPILATION_ERROR;
|
||||||
@@ -171,7 +179,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalyzerWithCompilerReport.reportDiagnostics(translationResult.getDiagnostics(), messageCollector);
|
AnalyzerWithCompilerReport.reportDiagnostics(translationResult.getDiagnostics(), messageSeverityCollector);
|
||||||
|
|
||||||
if (!(translationResult instanceof TranslationResult.Success)) return ExitCode.COMPILATION_ERROR;
|
if (!(translationResult instanceof TranslationResult.Success)) return ExitCode.COMPILATION_ERROR;
|
||||||
|
|
||||||
@@ -179,7 +187,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, outputPrefixFile, outputPostfixFile);
|
OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, outputPrefixFile, outputPostfixFile);
|
||||||
|
|
||||||
if (outputFile.isDirectory()) {
|
if (outputFile.isDirectory()) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR,
|
||||||
"Cannot open output file '" + outputFile.getPath() + "': is a directory",
|
"Cannot open output file '" + outputFile.getPath() + "': is a directory",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
return ExitCode.COMPILATION_ERROR;
|
return ExitCode.COMPILATION_ERROR;
|
||||||
@@ -189,7 +197,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
if (outputDir == null) {
|
if (outputDir == null) {
|
||||||
outputDir = outputFile.getAbsoluteFile().getParentFile();
|
outputDir = outputFile.getAbsoluteFile().getParentFile();
|
||||||
}
|
}
|
||||||
OutputUtilsPackage.writeAll(outputFiles, outputDir, messageCollector);
|
OutputUtilsPackage.writeAll(outputFiles, outputDir, messageSeverityCollector);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,15 +72,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
@NotNull MessageCollector messageCollector,
|
@NotNull MessageCollector messageCollector,
|
||||||
@NotNull Disposable rootDisposable
|
@NotNull Disposable rootDisposable
|
||||||
) {
|
) {
|
||||||
|
MessageSeverityCollector messageSeverityCollector = new MessageSeverityCollector(messageCollector);
|
||||||
KotlinPaths paths = arguments.kotlinHome != null
|
KotlinPaths paths = arguments.kotlinHome != null
|
||||||
? new KotlinPathsFromHomeDir(new File(arguments.kotlinHome))
|
? new KotlinPathsFromHomeDir(new File(arguments.kotlinHome))
|
||||||
: PathUtil.getKotlinPathsForCompiler();
|
: PathUtil.getKotlinPathsForCompiler();
|
||||||
|
|
||||||
messageCollector.report(CompilerMessageSeverity.LOGGING,
|
messageSeverityCollector.report(CompilerMessageSeverity.LOGGING,
|
||||||
"Using Kotlin home directory " + paths.getHomePath(), CompilerMessageLocation.NO_LOCATION);
|
"Using Kotlin home directory " + paths.getHomePath(), CompilerMessageLocation.NO_LOCATION);
|
||||||
|
|
||||||
final CompilerConfiguration configuration = new CompilerConfiguration();
|
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageSeverityCollector);
|
||||||
|
|
||||||
if (IncrementalCompilation.ENABLED) {
|
if (IncrementalCompilation.ENABLED) {
|
||||||
IncrementalCacheProvider incrementalCacheProvider = services.get(IncrementalCacheProvider.class);
|
IncrementalCacheProvider incrementalCacheProvider = services.get(IncrementalCacheProvider.class);
|
||||||
@@ -100,7 +101,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
MessageCollectorUtil.reportException(messageCollector, t);
|
MessageCollectorUtil.reportException(messageSeverityCollector, t);
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,21 +110,21 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
}
|
}
|
||||||
catch (PluginCliOptionProcessingException e) {
|
catch (PluginCliOptionProcessingException e) {
|
||||||
String message = e.getMessage() + "\n\n" + PluginPackage.cliPluginUsageString(e.getPluginId(), e.getOptions());
|
String message = e.getMessage() + "\n\n" + PluginPackage.cliPluginUsageString(e.getPluginId(), e.getOptions());
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
catch (CliOptionProcessingException e) {
|
catch (CliOptionProcessingException e) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, e.getMessage(), CompilerMessageLocation.NO_LOCATION);
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, e.getMessage(), CompilerMessageLocation.NO_LOCATION);
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
MessageCollectorUtil.reportException(messageCollector, t);
|
MessageCollectorUtil.reportException(messageSeverityCollector, t);
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.script) {
|
if (arguments.script) {
|
||||||
if (arguments.freeArgs.isEmpty()) {
|
if (arguments.freeArgs.isEmpty()) {
|
||||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate",
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "Specify script source path to evaluate",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
return COMPILATION_ERROR;
|
return COMPILATION_ERROR;
|
||||||
}
|
}
|
||||||
@@ -154,7 +155,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
|
|
||||||
putAdvancedOptions(configuration, arguments);
|
putAdvancedOptions(configuration, arguments);
|
||||||
|
|
||||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
messageSeverityCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
try {
|
try {
|
||||||
configureEnvironment(configuration, arguments);
|
configureEnvironment(configuration, arguments);
|
||||||
@@ -175,11 +176,11 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
final KotlinCoreEnvironment environment;
|
final KotlinCoreEnvironment environment;
|
||||||
|
|
||||||
if (arguments.module != null) {
|
if (arguments.module != null) {
|
||||||
MessageCollector sanitizedCollector = new FilteringMessageCollector(messageCollector, in(CompilerMessageSeverity.VERBOSE));
|
MessageCollector sanitizedCollector = new FilteringMessageCollector(messageSeverityCollector, in(CompilerMessageSeverity.VERBOSE));
|
||||||
ModuleScriptData moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector);
|
ModuleScriptData moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector);
|
||||||
|
|
||||||
if (outputDir != null) {
|
if (outputDir != null) {
|
||||||
messageCollector.report(CompilerMessageSeverity.WARNING,
|
messageSeverityCollector.report(CompilerMessageSeverity.WARNING,
|
||||||
"The '-d' option with a directory destination is ignored because '-module' is specified",
|
"The '-d' option with a directory destination is ignored because '-module' is specified",
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
}
|
}
|
||||||
@@ -200,6 +201,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
environment = createCoreEnvironment(rootDisposable, configuration);
|
environment = createCoreEnvironment(rootDisposable, configuration);
|
||||||
|
|
||||||
|
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) {
|
||||||
|
return COMPILATION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (environment.getSourceFiles().isEmpty()) {
|
||||||
|
messageSeverityCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION);
|
||||||
|
return COMPILATION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
|
KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, jar, outputDir, arguments.includeRuntime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +224,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
catch (CompilationException e) {
|
catch (CompilationException e) {
|
||||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
|
messageSeverityCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
|
||||||
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,11 @@ public class MockLibraryUtil {
|
|||||||
File contentDir = JetTestUtils.tmpDir("testLibrary-" + jarName);
|
File contentDir = JetTestUtils.tmpDir("testLibrary-" + jarName);
|
||||||
|
|
||||||
File classesDir = new File(contentDir, "classes");
|
File classesDir = new File(contentDir, "classes");
|
||||||
compileKotlin(sourcesPath, classesDir, extraClasspath);
|
|
||||||
|
List<File> kotlinFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.kt"), new File(sourcesPath));
|
||||||
|
if (!kotlinFiles.isEmpty()) {
|
||||||
|
compileKotlin(sourcesPath, classesDir, extraClasspath);
|
||||||
|
}
|
||||||
|
|
||||||
List<File> javaFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(sourcesPath));
|
List<File> javaFiles = FileUtil.findFilesByMask(Pattern.compile(".*\\.java"), new File(sourcesPath));
|
||||||
if (!javaFiles.isEmpty()) {
|
if (!javaFiles.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user