minor: scripting: fix processing of externally provided options

This commit is contained in:
Ilya Chernikov
2023-05-11 11:09:26 +02:00
committed by Space Team
parent 6f8049ffd3
commit ae10eebc84
@@ -155,6 +155,9 @@ internal fun createInitialConfigurations(
val initialScriptCompilationConfiguration = val initialScriptCompilationConfiguration =
scriptCompilationConfiguration.withUpdatesFromCompilerConfiguration(kotlinCompilerConfiguration) scriptCompilationConfiguration.withUpdatesFromCompilerConfiguration(kotlinCompilerConfiguration)
// this is the second processing of the same args from script configuration, the first happens inside createInitialComopilerConfiguration
// but this one important for the error reporting
// TODO: rewrite to avoid double processing of the options
initialScriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions]?.let { compilerOptions -> initialScriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions]?.let { compilerOptions ->
kotlinCompilerConfiguration.updateWithCompilerOptions(compilerOptions, messageCollector, ignoredOptionsReportingState, false) kotlinCompilerConfiguration.updateWithCompilerOptions(compilerOptions, messageCollector, ignoredOptionsReportingState, false)
} }
@@ -190,8 +193,7 @@ internal fun CompilerConfiguration.updateWithCompilerOptions(
validateArguments(it.errors)?.let { throw Exception("Error parsing arguments: $it") } ?: true validateArguments(it.errors)?.let { throw Exception("Error parsing arguments: $it") } ?: true
} }
) { ) {
val compilerArguments = K2JVMCompilerArguments() val compilerArguments = makeScriptCompilerArguments(compilerOptions)
parseCommandLineArguments(compilerOptions, compilerArguments)
if (!validate(compilerArguments)) return if (!validate(compilerArguments)) return
@@ -206,6 +208,17 @@ internal fun CompilerConfiguration.updateWithCompilerOptions(
configureKlibPaths(compilerArguments) configureKlibPaths(compilerArguments)
} }
private fun makeScriptCompilerArguments(compilerOptions: List<String>): K2JVMCompilerArguments {
val compilerArguments = K2JVMCompilerArguments()
val argumentsWithExternalProp =
(System.getProperty(SCRIPT_BASE_COMPILER_ARGUMENTS_PROPERTY)?.takeIf { it.isNotBlank() }?.split(' ') ?: emptyList()) +
compilerOptions
parseCommandLineArguments(argumentsWithExternalProp, compilerArguments)
return compilerArguments
}
private fun ScriptCompilationConfiguration.withUpdatesFromCompilerConfiguration(kotlinCompilerConfiguration: CompilerConfiguration) = private fun ScriptCompilationConfiguration.withUpdatesFromCompilerConfiguration(kotlinCompilerConfiguration: CompilerConfiguration) =
withUpdatedClasspath(kotlinCompilerConfiguration.jvmClasspathRoots) withUpdatedClasspath(kotlinCompilerConfiguration.jvmClasspathRoots)
@@ -216,10 +229,8 @@ private fun createInitialCompilerConfiguration(
reportingState: IgnoredOptionsReportingState reportingState: IgnoredOptionsReportingState
): CompilerConfiguration { ): CompilerConfiguration {
val baseArguments = K2JVMCompilerArguments() val baseArguments = makeScriptCompilerArguments(
parseCommandLineArguments( scriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions] ?: emptyList()
scriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions] ?: emptyList(),
baseArguments
) )
reportArgumentsIgnoredGenerally(baseArguments, messageCollector, reportingState) reportArgumentsIgnoredGenerally(baseArguments, messageCollector, reportingState)