Add argument to allow running compiler without sources
`-Xbuild-file` argument allows the compiler to run without passing any Kotlin source file in arguments. We have been using this property in Kotlin Gradle plugin for a few important cases: 1. incremental compilation (to update caches when there are only removed files); 2. for KAPT (Kotlin sources don't make sense in context of running APs). We want to stop using `-Xbuild-file` in Kotlin Gradle plugin, and avoid breaking the Gradle plugin or IC in other build-systems. This change adds an argument to explicitly run the compiler without specifying any Kotlin source file.
This commit is contained in:
+6
@@ -275,6 +275,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var friendPaths: Array<String>? by FreezableVar(null)
|
||||
|
||||
@Argument(
|
||||
value = "-Xallow-no-source-files",
|
||||
description = "Allow no source files"
|
||||
)
|
||||
var allowNoSourceFiles: Boolean by FreezableVar(false)
|
||||
|
||||
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
|
||||
val result = super.configureAnalysisFlags(collector)
|
||||
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
||||
|
||||
@@ -80,10 +80,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration.configureExplicitContentRoots(arguments)
|
||||
configuration.configureStandardLibs(paths, arguments)
|
||||
|
||||
// in case of IC we need to run compiler even
|
||||
// when there are no files to compile (to update caches & metadata when a file is removed)
|
||||
val isICEnabled = configuration[JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS] != null
|
||||
if (arguments.buildFile == null && arguments.freeArgs.isEmpty() && !(arguments.version || isICEnabled)) {
|
||||
if (arguments.buildFile == null && arguments.freeArgs.isEmpty() && !arguments.version && !arguments.allowNoSourceFiles) {
|
||||
if (arguments.script) {
|
||||
messageCollector.report(ERROR, "Specify script source path to evaluate")
|
||||
return COMPILATION_ERROR
|
||||
@@ -154,7 +151,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
if (!it) return COMPILATION_ERROR
|
||||
}
|
||||
|
||||
if (environment.getSourceFiles().isEmpty() && !isICEnabled && buildFile == null) {
|
||||
if (environment.getSourceFiles().isEmpty() && !arguments.allowNoSourceFiles && buildFile == null) {
|
||||
if (arguments.version) return OK
|
||||
|
||||
messageCollector.report(ERROR, "No source files")
|
||||
|
||||
+1
@@ -368,6 +368,7 @@ class IncrementalJvmCompilerRunner(
|
||||
val compiler = K2JVMCompiler()
|
||||
val freeArgsBackup = args.freeArgs.toList()
|
||||
args.freeArgs += sourcesToCompile.map { it.absolutePath }
|
||||
args.allowNoSourceFiles = true
|
||||
val exitCode = compiler.exec(messageCollector, services, args)
|
||||
args.freeArgs = freeArgsBackup
|
||||
return exitCode
|
||||
|
||||
+1
@@ -2,6 +2,7 @@ Usage: kotlinc-jvm <options> <source files>
|
||||
where advanced options include:
|
||||
-Xadd-modules=<module[,]> Root modules to resolve in addition to the initial modules,
|
||||
or all modules on the module path if <module> is ALL-MODULE-PATH
|
||||
-Xallow-no-source-files Allow no source files
|
||||
-Xassertions={always-enable|always-disable|jvm|legacy}
|
||||
Assert calls behaviour
|
||||
-Xassertions=always-enable: enable, ignore jvm assertion settings;
|
||||
|
||||
+1
@@ -405,6 +405,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
|
||||
if (defaultsOnly) return
|
||||
|
||||
args.allowNoSourceFiles = true
|
||||
args.classpathAsList = compileClasspath.toList()
|
||||
args.destinationAsFile = destinationDir
|
||||
parentKotlinOptionsImpl?.updateArguments(args)
|
||||
|
||||
Reference in New Issue
Block a user