K2: introduce "no source files" CLI check

This commit is contained in:
Mikhail Glukhikh
2023-06-22 17:05:39 +02:00
committed by Space Team
parent b821009617
commit 9bff7e3045
3 changed files with 17 additions and 4 deletions
@@ -26,7 +26,9 @@ data class GroupedKtSources(
val platformSources: Collection<KtSourceFile>,
val commonSources: Collection<KtSourceFile>,
val sourcesByModuleName: Map<String, Set<KtSourceFile>>,
)
) {
fun isEmpty(): Boolean = platformSources.isEmpty() && commonSources.isEmpty()
}
fun collectSources(
compilerConfiguration: CompilerConfiguration,
@@ -142,13 +142,15 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val targetDescription = chunk.map { input -> input.getModuleName() + "-" + input.getModuleType() }.let { names ->
names.singleOrNull() ?: names.joinToString()
}
if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR) && configuration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE)) {
if (configuration.getBoolean(CommonConfigurationKeys.USE_FIR) && configuration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE)) {
if (messageCollector.hasErrors()) return COMPILATION_ERROR
val projectEnvironment =
createProjectEnvironment(configuration, rootDisposable, EnvironmentConfigFiles.JVM_CONFIG_FILES, messageCollector)
if (messageCollector.hasErrors()) return COMPILATION_ERROR
compileModulesUsingFrontendIrAndLightTree(
projectEnvironment, configuration, messageCollector, buildFile, chunk, targetDescription
projectEnvironment, configuration, messageCollector, buildFile, chunk, targetDescription,
checkSourceFiles = !arguments.allowNoSourceFiles && !arguments.version
)
} else {
val environment = createCoreEnvironment(
@@ -79,7 +79,8 @@ fun compileModulesUsingFrontendIrAndLightTree(
messageCollector: MessageCollector,
buildFile: File?,
chunk: List<Module>,
targetDescription: String
targetDescription: String,
checkSourceFiles: Boolean
): Boolean {
require(projectEnvironment is VfsBasedProjectEnvironment) // TODO: abstract away this requirement
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
@@ -99,6 +100,14 @@ fun compileModulesUsingFrontendIrAndLightTree(
put(JVMConfigurationKeys.FRIEND_PATHS, module.getFriendPaths())
}
val groupedSources = collectSources(compilerConfiguration, projectEnvironment, messageCollector)
if (messageCollector.hasErrors()) {
return false
}
if (checkSourceFiles && groupedSources.isEmpty() && buildFile == null) {
messageCollector.report(CompilerMessageSeverity.ERROR, "No source files")
return false
}
val compilerInput = ModuleCompilerInput(
TargetId(module),