Protect scripts compilation from passing -Xuse-ir via configuration
as well as other options that require changes in the compilation setup before compiler options from the configuration could be processed
This commit is contained in:
+4
-11
@@ -170,19 +170,12 @@ private fun CompilerConfiguration.updateWithCompilerOptions(
|
||||
false
|
||||
} ?: run {
|
||||
messageCollector.reportArgumentParseProblems(it)
|
||||
reportArgumentsIgnoredGenerally(
|
||||
it,
|
||||
messageCollector,
|
||||
ignoredOptionsReportingState
|
||||
)
|
||||
val error = reportArgumentsNotAllowed(it, messageCollector, ignoredOptionsReportingState)
|
||||
reportArgumentsIgnoredGenerally(it, messageCollector, ignoredOptionsReportingState)
|
||||
if (isRefinement) {
|
||||
reportArgumentsIgnoredFromRefinement(
|
||||
it,
|
||||
messageCollector,
|
||||
ignoredOptionsReportingState
|
||||
)
|
||||
reportArgumentsIgnoredFromRefinement(it, messageCollector, ignoredOptionsReportingState)
|
||||
}
|
||||
true
|
||||
!error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-13
@@ -92,15 +92,32 @@ class IgnoredOptionsReportingState {
|
||||
var currentArguments = K2JVMCompilerArguments()
|
||||
}
|
||||
|
||||
internal fun reportArgumentsNotAllowed(
|
||||
arguments: K2JVMCompilerArguments,
|
||||
messageCollector: MessageCollector,
|
||||
reportingState: IgnoredOptionsReportingState
|
||||
) =
|
||||
reportInvalidArguments(
|
||||
arguments,
|
||||
"The following compiler arguments are not allowed in the script compilation configuration: ",
|
||||
CompilerMessageSeverity.ERROR,
|
||||
messageCollector,
|
||||
reportingState,
|
||||
K2JVMCompilerArguments::useJavac,
|
||||
K2JVMCompilerArguments::useIR,
|
||||
K2JVMCompilerArguments::useOldBackend,
|
||||
K2JVMCompilerArguments::useFir
|
||||
)
|
||||
|
||||
internal fun reportArgumentsIgnoredGenerally(
|
||||
arguments: K2JVMCompilerArguments,
|
||||
messageCollector: MessageCollector,
|
||||
reportingState: IgnoredOptionsReportingState
|
||||
) {
|
||||
|
||||
reportIgnoredArguments(
|
||||
) =
|
||||
reportInvalidArguments(
|
||||
arguments,
|
||||
"The following compiler arguments are ignored on script compilation: ",
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
messageCollector,
|
||||
reportingState,
|
||||
K2JVMCompilerArguments::version,
|
||||
@@ -121,14 +138,14 @@ internal fun reportArgumentsIgnoredGenerally(
|
||||
K2JVMCompilerArguments::reportPerf,
|
||||
K2JVMCompilerArguments::dumpPerf
|
||||
)
|
||||
}
|
||||
|
||||
internal fun reportArgumentsIgnoredFromRefinement(
|
||||
arguments: K2JVMCompilerArguments, messageCollector: MessageCollector, reportingState: IgnoredOptionsReportingState
|
||||
) {
|
||||
reportIgnoredArguments(
|
||||
) =
|
||||
reportInvalidArguments(
|
||||
arguments,
|
||||
"The following compiler arguments are ignored when configured from refinement callbacks: ",
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
messageCollector,
|
||||
reportingState,
|
||||
K2JVMCompilerArguments::noJdk,
|
||||
@@ -138,23 +155,26 @@ internal fun reportArgumentsIgnoredFromRefinement(
|
||||
K2JVMCompilerArguments::noStdlib,
|
||||
K2JVMCompilerArguments::noReflect
|
||||
)
|
||||
}
|
||||
|
||||
private fun reportIgnoredArguments(
|
||||
arguments: K2JVMCompilerArguments, message: String,
|
||||
|
||||
private fun reportInvalidArguments(
|
||||
arguments: K2JVMCompilerArguments,
|
||||
message: String, severity: CompilerMessageSeverity,
|
||||
messageCollector: MessageCollector, reportingState: IgnoredOptionsReportingState,
|
||||
vararg toIgnore: KMutableProperty1<K2JVMCompilerArguments, *>
|
||||
) {
|
||||
val ignoredArgKeys = toIgnore.mapNotNull { argProperty ->
|
||||
): Boolean {
|
||||
val invalidArgKeys = toIgnore.mapNotNull { argProperty ->
|
||||
if (argProperty.get(arguments) != argProperty.get(reportingState.currentArguments)) {
|
||||
argProperty.annotations.firstIsInstanceOrNull<Argument>()?.value
|
||||
?: throw IllegalStateException("unknown compiler argument property: $argProperty: no Argument annotation found")
|
||||
} else null
|
||||
}
|
||||
|
||||
if (ignoredArgKeys.isNotEmpty()) {
|
||||
messageCollector.report(CompilerMessageSeverity.STRONG_WARNING, "$message${ignoredArgKeys.joinToString(", ")}")
|
||||
if (invalidArgKeys.isNotEmpty()) {
|
||||
messageCollector.report(severity, "$message${invalidArgKeys.joinToString(", ")}")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
val MessageCollector.reporter: MessageReporter
|
||||
|
||||
Reference in New Issue
Block a user