Do not fail on unknown -X flags
For better compatibility if we add experimental stuff in 1.0.X compilers
This commit is contained in:
+2
@@ -58,6 +58,8 @@ public abstract class CommonCompilerArguments {
|
|||||||
|
|
||||||
public List<String> freeArgs = new SmartList<String>();
|
public List<String> freeArgs = new SmartList<String>();
|
||||||
|
|
||||||
|
public List<String> unknownExtraFlags = new SmartList<String>();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String executableScriptFileName() {
|
public String executableScriptFileName() {
|
||||||
return "kotlinc";
|
return "kotlinc";
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import com.intellij.openapi.Disposable;
|
|||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.SystemInfo;
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
import com.sampullara.cli.Args;
|
import com.sampullara.cli.Args;
|
||||||
|
import kotlin.Pair;
|
||||||
|
import kotlin.collections.CollectionsKt;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.fusesource.jansi.AnsiConsole;
|
import org.fusesource.jansi.AnsiConsole;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -87,7 +90,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
private A parseArguments(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull String[] args) {
|
private A parseArguments(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull String[] args) {
|
||||||
try {
|
try {
|
||||||
A arguments = createArguments();
|
A arguments = createArguments();
|
||||||
arguments.freeArgs = Args.parse(arguments, args);
|
parseArguments(args, arguments);
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
@@ -104,6 +107,26 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess") // Used in maven (see KotlinCompileMojoBase.java)
|
||||||
|
public void parseArguments(@NotNull String[] args, @NotNull A arguments) {
|
||||||
|
Pair<List<String>, List<String>> unparsedArgs =
|
||||||
|
CollectionsKt.partition(Args.parse(arguments, args, false), new Function1<String, Boolean>() {
|
||||||
|
@Override
|
||||||
|
public Boolean invoke(String s) {
|
||||||
|
return s.startsWith("-X");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
arguments.unknownExtraFlags = unparsedArgs.getFirst();
|
||||||
|
arguments.freeArgs = unparsedArgs.getSecond();
|
||||||
|
|
||||||
|
for (String argument : arguments.freeArgs) {
|
||||||
|
if (argument.startsWith("-")) {
|
||||||
|
throw new IllegalArgumentException("Invalid argument: " + argument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow derived classes to add additional command line arguments
|
* Allow derived classes to add additional command line arguments
|
||||||
*/
|
*/
|
||||||
@@ -169,6 +192,8 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
messageCollector = new FilteringMessageCollector(messageCollector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
|
messageCollector = new FilteringMessageCollector(messageCollector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reportUnknownExtraFlags(messageCollector, arguments);
|
||||||
|
|
||||||
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
|
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
|
||||||
try {
|
try {
|
||||||
ExitCode exitCode = OK;
|
ExitCode exitCode = OK;
|
||||||
@@ -226,6 +251,16 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reportUnknownExtraFlags(@NotNull MessageCollector collector, @NotNull A arguments) {
|
||||||
|
for (String flag : arguments.unknownExtraFlags) {
|
||||||
|
collector.report(
|
||||||
|
CompilerMessageSeverity.WARNING,
|
||||||
|
"Flag is not supported by this version of the compiler: " + flag,
|
||||||
|
CompilerMessageLocation.NO_LOCATION
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract ExitCode doExecute(
|
protected abstract ExitCode doExecute(
|
||||||
@NotNull A arguments,
|
@NotNull A arguments,
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-Xabcdefghijklm
|
||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-Xnopqrstuvwxyz
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-XXxxxxxxxxxxxx
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
warning: flag is not supported by this version of the compiler: -Xabcdefghijklm
|
||||||
|
warning: flag is not supported by this version of the compiler: -Xnopqrstuvwxyz
|
||||||
|
warning: flag is not supported by this version of the compiler: -XXxxxxxxxxxxxx
|
||||||
|
OK
|
||||||
@@ -241,6 +241,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
doJvmTest(fileName);
|
doJvmTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unknownExtraFlags.args")
|
||||||
|
public void testUnknownExtraFlags() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/unknownExtraFlags.args");
|
||||||
|
doJvmTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("version.args")
|
@TestMetadata("version.args")
|
||||||
public void testVersion() throws Exception {
|
public void testVersion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/version.args");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/version.args");
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<arg>-Xno-optimize</arg>
|
<arg>-Xno-optimize</arg>
|
||||||
<arg>-Xno-call-assertions</arg>
|
<arg>-Xno-call-assertions</arg>
|
||||||
<arg>-Xno-param-assertions</arg>
|
<arg>-Xno-param-assertions</arg>
|
||||||
|
<arg>-Xunknown-extra-argument-abcdefghijklmnopqrstuvwxyz</arg>
|
||||||
</args>
|
</args>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
-9
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.maven;
|
package org.jetbrains.kotlin.maven;
|
||||||
|
|
||||||
import com.intellij.util.ArrayUtil;
|
|
||||||
import com.sampullara.cli.Args;
|
|
||||||
import kotlin.collections.CollectionsKt;
|
import kotlin.collections.CollectionsKt;
|
||||||
import kotlin.jvm.functions.Function1;
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
@@ -100,13 +98,6 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
|||||||
arguments.moduleName = moduleName;
|
arguments.moduleName = moduleName;
|
||||||
getLog().info("Module name is " + moduleName);
|
getLog().info("Module name is " + moduleName);
|
||||||
|
|
||||||
try {
|
|
||||||
Args.parse(arguments, ArrayUtil.toStringArray(args));
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
throw new MojoExecutionException(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments.noOptimize) {
|
if (arguments.noOptimize) {
|
||||||
getLog().info("Optimization is turned off");
|
getLog().info("Optimization is turned off");
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.maven;
|
|||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import com.sampullara.cli.Args;
|
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
@@ -115,9 +114,9 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
}
|
}
|
||||||
|
|
||||||
A arguments = createCompilerArguments();
|
A arguments = createCompilerArguments();
|
||||||
configureCompilerArguments(arguments);
|
|
||||||
|
|
||||||
CLICompiler<A> compiler = createCompiler();
|
CLICompiler<A> compiler = createCompiler();
|
||||||
|
|
||||||
|
configureCompilerArguments(arguments, compiler);
|
||||||
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
||||||
|
|
||||||
MessageCollector messageCollector = new MessageCollector() {
|
MessageCollector messageCollector = new MessageCollector() {
|
||||||
@@ -224,7 +223,7 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
*/
|
*/
|
||||||
protected abstract void configureSpecificCompilerArguments(@NotNull A arguments) throws MojoExecutionException;
|
protected abstract void configureSpecificCompilerArguments(@NotNull A arguments) throws MojoExecutionException;
|
||||||
|
|
||||||
private void configureCompilerArguments(@NotNull A arguments) throws MojoExecutionException {
|
private void configureCompilerArguments(@NotNull A arguments, @NotNull CLICompiler<A> compiler) throws MojoExecutionException {
|
||||||
if (getLog().isDebugEnabled()) {
|
if (getLog().isDebugEnabled()) {
|
||||||
arguments.verbose = true;
|
arguments.verbose = true;
|
||||||
}
|
}
|
||||||
@@ -245,18 +244,19 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
|||||||
|
|
||||||
arguments.suppressWarnings = nowarn;
|
arguments.suppressWarnings = nowarn;
|
||||||
|
|
||||||
arguments.freeArgs.addAll(sources);
|
|
||||||
getLog().info("Compiling Kotlin sources from " + sources);
|
getLog().info("Compiling Kotlin sources from " + sources);
|
||||||
|
|
||||||
configureSpecificCompilerArguments(arguments);
|
configureSpecificCompilerArguments(arguments);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Args.parse(arguments, ArrayUtil.toStringArray(args));
|
compiler.parseArguments(ArrayUtil.toStringArray(args), arguments);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
throw new MojoExecutionException(e.getMessage());
|
throw new MojoExecutionException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arguments.freeArgs.addAll(sources);
|
||||||
|
|
||||||
if (arguments.noInline) {
|
if (arguments.noInline) {
|
||||||
getLog().info("Method inlining is turned off");
|
getLog().info("Method inlining is turned off");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user