CLI: Support "-X" advanced options, simplify some boolean options

This commit is contained in:
Alexander Udalov
2014-07-30 11:10:26 -07:00
parent 991c33d236
commit 160cde09d6
30 changed files with 93 additions and 303 deletions
@@ -41,6 +41,9 @@ public abstract class CommonCompilerArguments {
@ValueDescription(SUPPRESS_WARNINGS) @ValueDescription(SUPPRESS_WARNINGS)
public String suppress; public String suppress;
@Argument(value = "X", description = "Print a synopsis of advanced options")
public boolean extraHelp;
public List<String> freeArgs = new SmartList<String>(); public List<String> freeArgs = new SmartList<String>();
public boolean suppressAllWarnings() { public boolean suppressAllWarnings() {
@@ -48,12 +48,6 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "noJdkAnnotations", description = "Don't include JDK external annotations into classpath") @Argument(value = "noJdkAnnotations", description = "Don't include JDK external annotations into classpath")
public boolean noJdkAnnotations; public boolean noJdkAnnotations;
@Argument(value = "notNullAssertions", description = "Generate not-null assertion after each invocation of method returning not-null")
public boolean notNullAssertions;
@Argument(value = "notNullParamAssertions", description = "Generate not-null assertions on parameters of methods accessible from Java")
public boolean notNullParamAssertions;
@Argument(value = "module", description = "Path to the module file to compile") @Argument(value = "module", description = "Path to the module file to compile")
@ValueDescription("<path>") @ValueDescription("<path>")
public String module; public String module;
@@ -65,13 +59,19 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@ValueDescription("<path>") @ValueDescription("<path>")
public String kotlinHome; public String kotlinHome;
@Argument(value = "inline", description = "Inlining mode (default is on)") // Advanced options
@ValueDescription("{on,off}")
public String inline;
@Argument(value = "optimize", description = "Optimization mode (default is on)") @Argument(value = "Xno-call-assertions", description = "Don't generate not-null assertion after each invocation of method returning not-null")
@ValueDescription("{on,off}") public boolean noCallAssertions;
public String optimize;
@Argument(value = "Xno-param-assertions", description = "Don't generate not-null assertions on parameters of methods accessible from Java")
public boolean noParamAssertions;
@Argument(value = "Xno-inline", description = "Disable method inlining")
public boolean noInline;
@Argument(value = "Xno-optimize", description = "Disable optimizations")
public boolean noOptimize;
@Override @Override
@NotNull @NotNull
@@ -61,12 +61,11 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) { protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
try { try {
arguments.freeArgs = Args.parse(arguments, args); arguments.freeArgs = Args.parse(arguments, args);
checkArguments(arguments);
return true; return true;
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {
errStream.println(e.getMessage()); errStream.println(e.getMessage());
usage(errStream); usage(errStream, false);
} }
catch (Throwable t) { catch (Throwable t) {
// Always use tags // Always use tags
@@ -75,15 +74,11 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
return false; return false;
} }
protected void checkArguments(@NotNull A argument) {
}
/** /**
* Allow derived classes to add additional command line arguments * Allow derived classes to add additional command line arguments
*/ */
protected void usage(@NotNull PrintStream target) { protected void usage(@NotNull PrintStream target, boolean extraHelp) {
Usage.print(target, createArguments()); Usage.print(target, createArguments(), extraHelp);
} }
/** /**
@@ -102,8 +97,8 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
*/ */
@NotNull @NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull A arguments) { public ExitCode exec(@NotNull PrintStream errStream, @NotNull A arguments) {
if (arguments.help) { if (arguments.help || arguments.extraHelp) {
usage(errStream); usage(errStream, arguments.extraHelp);
return OK; return OK;
} }
@@ -29,35 +29,39 @@ class Usage {
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers // The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
private static final int OPTION_NAME_PADDING_WIDTH = 29; private static final int OPTION_NAME_PADDING_WIDTH = 29;
public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments) { public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments, boolean extraHelp) {
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>"); target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
target.println("where possible options include:"); target.println("where " + (extraHelp ? "advanced" : "possible") + " options include:");
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) { for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
for (Field field : clazz.getDeclaredFields()) { for (Field field : clazz.getDeclaredFields()) {
String usage = fieldUsage(field); String usage = fieldUsage(field, extraHelp);
if (usage != null) { if (usage != null) {
target.println(usage); target.println(usage);
} }
} }
} }
if (extraHelp) {
target.println();
target.println("Advanced options are non-standard and may be changed or removed without any notice.");
}
} }
@Nullable @Nullable
private static String fieldUsage(@NotNull Field field) { private static String fieldUsage(@NotNull Field field, boolean extraHelp) {
Argument argument = field.getAnnotation(Argument.class); Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null; if (argument == null) return null;
ValueDescription description = field.getAnnotation(ValueDescription.class); ValueDescription description = field.getAnnotation(ValueDescription.class);
String value = argument.value();
boolean extraOption = value.startsWith("X") && value.length() > 1;
if (extraHelp != extraOption) return null;
String prefix = argument.prefix(); String prefix = argument.prefix();
StringBuilder sb = new StringBuilder(" "); StringBuilder sb = new StringBuilder(" ");
sb.append(prefix); sb.append(prefix);
if (argument.value().isEmpty()) { sb.append(value);
sb.append(field.getName());
}
else {
sb.append(argument.value());
}
if (!argument.alias().isEmpty()) { if (!argument.alias().isEmpty()) {
sb.append(" ("); sb.append(" (");
sb.append(prefix); sb.append(prefix);
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.CLIConfigurationKeys; import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.common.modules.ModuleScriptData; import org.jetbrains.jet.cli.common.modules.ModuleScriptData;
@@ -33,8 +32,6 @@ import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler; import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal; import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal;
import org.jetbrains.jet.codegen.CompilationException; import org.jetbrains.jet.codegen.CompilationException;
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CommonConfigurationKeys;
import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
@@ -103,12 +100,10 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
? CommandLineScriptUtils.scriptParameters() ? CommandLineScriptUtils.scriptParameters()
: Collections.<AnalyzerScriptParameter>emptyList()); : Collections.<AnalyzerScriptParameter>emptyList());
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions); configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, !arguments.noCallAssertions);
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions); configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, !arguments.noParamAssertions);
configuration.put(JVMConfigurationKeys.ENABLE_INLINE, configuration.put(JVMConfigurationKeys.ENABLE_INLINE, !arguments.noInline);
CompilerArgumentsUtil.optionToBooleanFlag(arguments.inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG)); configuration.put(JVMConfigurationKeys.ENABLE_OPTIMIZATION, !arguments.noOptimize);
configuration.put(JVMConfigurationKeys.ENABLE_OPTIMIZATION,
CompilerArgumentsUtil.optionToBooleanFlag(arguments.optimize, OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG));
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
@@ -208,18 +203,4 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
} }
return annotationsPath; return annotationsPath;
} }
@Override
protected void checkArguments(@NotNull K2JVMCompilerArguments argument) {
super.checkArguments(argument);
if (!CompilerArgumentsUtil.checkOption(argument.inline)) {
throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", argument.inline));
}
if (!CompilerArgumentsUtil.checkOption(argument.optimize)) {
throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", argument.optimize));
}
}
} }
@@ -0,0 +1 @@
-X
+5
View File
@@ -0,0 +1,5 @@
Usage: kotlinc-js <options> <source files>
where advanced options include:
Advanced options are non-standard and may be changed or removed without any notice.
OK
+1
View File
@@ -12,4 +12,5 @@ where possible options include:
-version Display compiler version -version Display compiler version
-help (-h) Print a synopsis of standard options -help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings -suppress warnings Suppress all compiler warnings
-X Print a synopsis of advanced options
OK OK
+1
View File
@@ -0,0 +1 @@
-X
+9
View File
@@ -0,0 +1,9 @@
Usage: kotlinc-jvm <options> <source files>
where advanced options include:
-Xno-call-assertions Don't generate not-null assertion after each invocation of method returning not-null
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
-Xno-inline Disable method inlining
-Xno-optimize Disable optimizations
Advanced options are non-standard and may be changed or removed without any notice.
OK
+1 -4
View File
@@ -7,16 +7,13 @@ where possible options include:
-noJdk Don't include Java runtime into classpath -noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath -noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath -noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile -module <path> Path to the module file to compile
-script Evaluate the script file -script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery -kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-optimize {on,off} Optimization mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag -tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output -verbose Enable verbose logging output
-version Display compiler version -version Display compiler version
-help (-h) Print a synopsis of standard options -help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings -suppress warnings Suppress all compiler warnings
-X Print a synopsis of advanced options
OK OK
@@ -1,3 +0,0 @@
-inline
off
-help
-22
View File
@@ -1,22 +0,0 @@
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-d <directory|jar> Destination for generated class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-optimize {on,off} Optimization mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
OK
-3
View File
@@ -1,3 +0,0 @@
-inline
on
-help
-22
View File
@@ -1,22 +0,0 @@
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-d <directory|jar> Destination for generated class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-optimize {on,off} Optimization mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
OK
@@ -1,2 +0,0 @@
-inline
wrong
@@ -1,23 +0,0 @@
Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false'
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-d <directory|jar> Destination for generated class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-optimize {on,off} Optimization mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
INTERNAL_ERROR
+1 -4
View File
@@ -8,16 +8,13 @@ where possible options include:
-noJdk Don't include Java runtime into classpath -noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath -noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath -noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile -module <path> Path to the module file to compile
-script Evaluate the script file -script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery -kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-optimize {on,off} Optimization mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag -tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output -verbose Enable verbose logging output
-version Display compiler version -version Display compiler version
-help (-h) Print a synopsis of standard options -help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings -suppress warnings Suppress all compiler warnings
-X Print a synopsis of advanced options
INTERNAL_ERROR INTERNAL_ERROR
@@ -33,7 +33,7 @@ import org.jetbrains.jet.cli.AbstractKotlincExecutableTest;
@InnerTestClasses({KotlincExecutableTestGenerated.Jvm.class, KotlincExecutableTestGenerated.Js.class}) @InnerTestClasses({KotlincExecutableTestGenerated.Jvm.class, KotlincExecutableTestGenerated.Js.class})
public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTest { public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTest {
@TestMetadata("compiler/testData/cli/jvm") @TestMetadata("compiler/testData/cli/jvm")
@InnerTestClasses({Jvm.Inline.class, Jvm.WrongAbiVersionLib.class}) @InnerTestClasses({Jvm.WrongAbiVersionLib.class})
public static class Jvm extends AbstractKotlincExecutableTest { public static class Jvm extends AbstractKotlincExecutableTest {
public void testAllFilesPresentInJvm() throws Exception { public void testAllFilesPresentInJvm() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cli/jvm"), Pattern.compile("^(.+)\\.args$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cli/jvm"), Pattern.compile("^(.+)\\.args$"), true);
@@ -54,6 +54,11 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
doJvmTest("compiler/testData/cli/jvm/diagnosticsOrder.args"); doJvmTest("compiler/testData/cli/jvm/diagnosticsOrder.args");
} }
@TestMetadata("extraHelp.args")
public void testExtraHelp() throws Exception {
doJvmTest("compiler/testData/cli/jvm/extraHelp.args");
}
@TestMetadata("help.args") @TestMetadata("help.args")
public void testHelp() throws Exception { public void testHelp() throws Exception {
doJvmTest("compiler/testData/cli/jvm/help.args"); doJvmTest("compiler/testData/cli/jvm/help.args");
@@ -109,29 +114,6 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
doJvmTest("compiler/testData/cli/jvm/wrongKotlinSignature.args"); doJvmTest("compiler/testData/cli/jvm/wrongKotlinSignature.args");
} }
@TestMetadata("compiler/testData/cli/jvm/inline")
public static class Inline extends AbstractKotlincExecutableTest {
public void testAllFilesPresentInInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cli/jvm/inline"), Pattern.compile("^(.+)\\.args$"), true);
}
@TestMetadata("off.args")
public void testOff() throws Exception {
doJvmTest("compiler/testData/cli/jvm/inline/off.args");
}
@TestMetadata("on.args")
public void testOn() throws Exception {
doJvmTest("compiler/testData/cli/jvm/inline/on.args");
}
@TestMetadata("wrong.args")
public void testWrong() throws Exception {
doJvmTest("compiler/testData/cli/jvm/inline/wrong.args");
}
}
@TestMetadata("compiler/testData/cli/jvm/wrongAbiVersionLib") @TestMetadata("compiler/testData/cli/jvm/wrongAbiVersionLib")
@InnerTestClasses({}) @InnerTestClasses({})
public static class WrongAbiVersionLib extends AbstractKotlincExecutableTest { public static class WrongAbiVersionLib extends AbstractKotlincExecutableTest {
@@ -149,7 +131,6 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
public static Test innerSuite() { public static Test innerSuite() {
TestSuite suite = new TestSuite("Jvm"); TestSuite suite = new TestSuite("Jvm");
suite.addTestSuite(Jvm.class); suite.addTestSuite(Jvm.class);
suite.addTestSuite(Inline.class);
suite.addTest(WrongAbiVersionLib.innerSuite()); suite.addTest(WrongAbiVersionLib.innerSuite());
return suite; return suite;
} }
@@ -161,6 +142,11 @@ public class KotlincExecutableTestGenerated extends AbstractKotlincExecutableTes
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cli/js"), Pattern.compile("^(.+)\\.args$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cli/js"), Pattern.compile("^(.+)\\.args$"), true);
} }
@TestMetadata("jsExtraHelp.args")
public void testJsExtraHelp() throws Exception {
doJsTest("compiler/testData/cli/js/jsExtraHelp.args");
}
@TestMetadata("jsHelp.args") @TestMetadata("jsHelp.args")
public void testJsHelp() throws Exception { public void testJsHelp() throws Exception {
doJsTest("compiler/testData/cli/js/jsHelp.args"); doJsTest("compiler/testData/cli/js/jsHelp.args");
@@ -142,8 +142,6 @@ public class KotlinCompilerRunner {
setupCommonSettings(settings); setupCommonSettings(settings);
settings.module = moduleFile.getAbsolutePath(); settings.module = moduleFile.getAbsolutePath();
settings.notNullAssertions = true;
settings.notNullParamAssertions = true;
settings.noStdlib = true; settings.noStdlib = true;
settings.noJdkAnnotations = true; settings.noJdkAnnotations = true;
settings.noJdk = true; settings.noJdk = true;
@@ -33,7 +33,7 @@ class KDocCompiler() : K2JVMCompiler() {
return KDocArguments() return KDocArguments()
} }
protected override fun usage(target : PrintStream) { protected override fun usage(target: PrintStream, extraHelp: Boolean) {
target.println("Usage: KDocCompiler -docOutput <docOutputDir> -d [<outputDir>|<jarFileName>] [-stdlib <path to runtime.jar>] [<filename or dirname>|-module <module file>] [-includeRuntime]"); target.println("Usage: KDocCompiler -docOutput <docOutputDir> -d [<outputDir>|<jarFileName>] [-stdlib <path to runtime.jar>] [<filename or dirname>|-module <module file>] [-includeRuntime]");
} }
} }
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.doc.KDocConfig import org.jetbrains.kotlin.doc.KDocConfig
import java.util.concurrent.Callable import java.util.concurrent.Callable
import org.gradle.api.Project import org.gradle.api.Project
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil
public open class KotlinCompile(): AbstractCompile() { public open class KotlinCompile(): AbstractCompile() {
@@ -116,16 +115,10 @@ public open class KotlinCompile(): AbstractCompile() {
args.noStdlib = true args.noStdlib = true
args.noJdkAnnotations = true args.noJdkAnnotations = true
args.inline = kotlinOptions.inline args.noInline = kotlinOptions.noInline
args.optimize = kotlinOptions.optimize args.noOptimize = kotlinOptions.noOptimize
args.noCallAssertions = kotlinOptions.noCallAssertions
if (!CompilerArgumentsUtil.checkOption(args.inline)) { args.noParamAssertions = kotlinOptions.noParamAssertions
throw GradleException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", args.inline))
}
if (!CompilerArgumentsUtil.checkOption(args.optimize)) {
throw GradleException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", args.optimize))
}
val messageCollector = GradleMessageCollector(getLogger()) val messageCollector = GradleMessageCollector(getLogger())
getLogger().debug("Calling compiler") getLogger().debug("Calling compiler")
@@ -1,16 +1,6 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import com.google.common.io.Files
import com.intellij.openapi.util.SystemInfo
import java.io.File
import java.util.Arrays
import java.util.Scanner
import org.junit.Before
import org.junit.After
import org.junit.Test import org.junit.Test
import kotlin.test.assertTrue
import kotlin.test.assertEquals
import kotlin.test.fail
import org.junit.Ignore import org.junit.Ignore
import org.jetbrains.kotlin.gradle.BaseGradleIT.Project import org.jetbrains.kotlin.gradle.BaseGradleIT.Project
@@ -37,14 +27,8 @@ class BasicKotlinGradleIT : BaseGradleIT() {
} }
} }
Test fun testInlineDisabled() { Test fun testAdvancedOptions() {
Project("inlineDisabled", "1.6").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") { Project("advancedOptions", "1.6").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") {
assertSuccessful()
}
}
Test fun testOptimizationDisabled() {
Project("optimizationDisabled", "1.6").build("build", "-Pkotlin.gradle.plugin.version=0.1-SNAPSHOT") {
assertSuccessful() assertSuccessful()
} }
} }
@@ -40,8 +40,10 @@ test {
} }
compileKotlin { compileKotlin {
kotlinOptions.annotations = "externalAnnotations" kotlinOptions.noInline = true
kotlinOptions.inline = false kotlinOptions.noOptimize = true
kotlinOptions.noCallAssertions = true
kotlinOptions.noParamAssertions = true
} }
@@ -1,11 +0,0 @@
<root>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner.MapJoiner withKeyValueSeparator(java.lang.String)'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner skipNulls()'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
</root>
@@ -1,50 +0,0 @@
buildscript {
repositories {
mavenCentral()
maven {
url 'file://' + pathToKotlinPlugin
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin-core:0.1-SNAPSHOT'
}
}
import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin
apply plugin: KotlinPlugin
sourceSets {
main {
kotlin {
srcDir 'src'
}
}
}
repositories {
maven {
url 'file://' + pathToKotlinPlugin
}
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:12.0'
testCompile 'org.testng:testng:6.8'
testRuntime 'org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT'
}
test {
useTestNG()
}
compileKotlin {
kotlinOptions.annotations = "externalAnnotations"
kotlinOptions.optimize = false
}
task wrapper(type: Wrapper) {
gradleVersion="1.4"
}
@@ -1,11 +0,0 @@
<root>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner.MapJoiner withKeyValueSeparator(java.lang.String)'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
<item name='com.google.common.base.Joiner com.google.common.base.Joiner skipNulls()'>
<annotation name="org.jetbrains.annotations.NotNull" />
</item>
</root>
@@ -1,13 +0,0 @@
package demo
import java.util.ArrayList
class KotlinGreetingJoiner() {
val names = ArrayList<String?>()
fun addName(name : String?): Unit{
names.add(name)
}
}
@@ -28,25 +28,19 @@ import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.ExitCode; import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.KotlinVersion; import org.jetbrains.jet.cli.common.KotlinVersion;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler; import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
import org.jetbrains.jet.codegen.inline.InlineCodegenUtil;
import org.jetbrains.jet.codegen.optimization.OptimizationUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@@ -321,24 +315,23 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
arguments.noJdkAnnotations = true; arguments.noJdkAnnotations = true;
arguments.annotations = getFullAnnotationsPath(log, annotationPaths); arguments.annotations = getFullAnnotationsPath(log, annotationPaths);
log.info("Using kotlin annotations from " + arguments.annotations); log.info("Using kotlin annotations from " + arguments.annotations);
arguments.inline = inline; arguments.noInline = !CompilerArgumentsUtil.optionToBooleanFlag(inline, true);
arguments.optimize = optimize; arguments.noOptimize = !CompilerArgumentsUtil.optionToBooleanFlag(optimize, true);
if (!CompilerArgumentsUtil.checkOption(arguments.inline)) { if (!CompilerArgumentsUtil.checkOption(inline)) {
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", arguments.inline)); throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("inline", inline));
} }
if (!CompilerArgumentsUtil.checkOption(arguments.optimize)) { if (!CompilerArgumentsUtil.checkOption(optimize)) {
throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", arguments.optimize)); throw new MojoExecutionException(CompilerArgumentsUtil.getWrongCheckOptionErrorMessage("optimize", optimize));
} }
log.info("Method inlining is " + CompilerArgumentsUtil.optionToBooleanFlag(arguments.inline, InlineCodegenUtil.DEFAULT_INLINE_FLAG)); if (arguments.noInline) {
log.info( log.info("Method inlining is turned off");
"Optimization mode is " + CompilerArgumentsUtil.optionToBooleanFlag( }
arguments.optimize, if (arguments.noOptimize) {
OptimizationUtils.DEFAULT_OPTIMIZATION_FLAG log.info("Optimization is turned off");
) }
);
} }
protected String getFullAnnotationsPath(Log log, List<String> annotations) { protected String getFullAnnotationsPath(Log log, List<String> annotations) {