Support inline true/false options
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.cli.common.arguments;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CompilerArgumentsUtil {
|
||||
public static final boolean DEFAULT_INLINE_FLAG = true;
|
||||
public static final boolean DEFAULT_INLINE_FLAG_FOR_TEST = true;
|
||||
|
||||
public static boolean optionToInlineFlag(@Nullable String option) {
|
||||
boolean enableInline = "on".equalsIgnoreCase(option) || "true".equalsIgnoreCase(option);
|
||||
return (enableInline || "off".equalsIgnoreCase(option) || "false".equalsIgnoreCase(option)) ? enableInline : DEFAULT_INLINE_FLAG;
|
||||
}
|
||||
|
||||
public static boolean checkInlineOption(@Nullable String option) {
|
||||
if (option == null ||
|
||||
"on".equalsIgnoreCase(option) ||
|
||||
"off".equalsIgnoreCase(option) ||
|
||||
"true".equalsIgnoreCase(option) ||
|
||||
"false".equalsIgnoreCase(option)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getWrongOptionErrorMessage(@Nullable String inline) {
|
||||
return "Wrong value for inline option: '" + inline + "'. Should be 'on'/'off' or 'true'/'false'";
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -66,6 +66,6 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
|
||||
public String kotlinHome;
|
||||
|
||||
@Argument(value = "inline", description = "Inlining mode: on/off (default is on)")
|
||||
public String enableInline;
|
||||
@Argument(value = "inline", description = "Inlining mode: on/off or true/false (default is on)")
|
||||
public String inline;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||
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.messages.*;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.*;
|
||||
@@ -32,7 +33,6 @@ import org.jetbrains.jet.codegen.CompilationException;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||
import org.jetbrains.jet.utils.KotlinPaths;
|
||||
import org.jetbrains.jet.utils.KotlinPathsFromHomeDir;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
@@ -108,7 +108,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions);
|
||||
configuration.put(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.optionToInlineFlag(arguments.enableInline));
|
||||
configuration.put(JVMConfigurationKeys.ENABLE_INLINE, CompilerArgumentsUtil.optionToInlineFlag(arguments.inline));
|
||||
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
@@ -197,11 +197,9 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
protected void checkArguments(@NotNull K2JVMCompilerArguments argument) {
|
||||
super.checkArguments(argument);
|
||||
|
||||
String inline = argument.enableInline;
|
||||
if (inline != null) {
|
||||
if (!"on".equalsIgnoreCase(inline) && !"off".equalsIgnoreCase(inline)) {
|
||||
throw new IllegalArgumentException("Wrong value for inline option: '" + inline + "'. Should be 'on' or 'off'");
|
||||
}
|
||||
if (!CompilerArgumentsUtil.checkInlineOption(argument.inline)) {
|
||||
throw new IllegalArgumentException(CompilerArgumentsUtil.getWrongOptionErrorMessage(argument.inline));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-3
@@ -18,7 +18,6 @@ package org.jetbrains.jet.cli.jvm.compiler;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import kotlin.Function0;
|
||||
@@ -30,6 +29,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.jet.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.output.OutputDirector;
|
||||
@@ -48,7 +48,6 @@ import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||
import org.jetbrains.jet.plugin.MainFunctionDetector;
|
||||
import org.jetbrains.jet.utils.KotlinPaths;
|
||||
|
||||
@@ -308,7 +307,7 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
|
||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG)
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, CompilerArgumentsUtil.DEFAULT_INLINE_FLAG)
|
||||
);
|
||||
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return generationState;
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.OutputFile;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorToString;
|
||||
@@ -56,7 +57,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.storage.ExceptionTracker;
|
||||
@@ -248,7 +248,7 @@ public class ReplInterpreter {
|
||||
|
||||
BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext();
|
||||
GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.BINARIES,
|
||||
bindingContext, Collections.singletonList(psiFile), InlineUtil.DEFAULT_INLINE_FLAG);
|
||||
bindingContext, Collections.singletonList(psiFile), CompilerArgumentsUtil.DEFAULT_INLINE_FLAG);
|
||||
|
||||
compileScript(psiFile.getScript(), scriptClassType, earlierScripts, generationState,
|
||||
CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
@@ -85,6 +85,16 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineDisabled() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineWrongArg() throws Exception {
|
||||
doAntTest(FAILED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jvmClasspath() throws Exception {
|
||||
doJvmAntTest();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
OUT:
|
||||
Buildfile: [TestData]/build.xml
|
||||
|
||||
build:
|
||||
[kotlinc] Compiling [[[TestData]/hello.kt]] => [[Temp]/hello.jar]
|
||||
|
||||
BUILD SUCCESSFUL
|
||||
Total time: [time]
|
||||
|
||||
Return code: 0
|
||||
@@ -0,0 +1,7 @@
|
||||
<project name="Ant Task Test" default="build">
|
||||
<taskdef resource="org/jetbrains/jet/buildtools/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||
|
||||
<target name="build">
|
||||
<kotlinc src="${test.data}/hello.kt" output="${temp}/hello.jar" inline="false"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package hello
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
for (s in arrayList("a"))
|
||||
println("Hello, $s!")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
OUT:
|
||||
Hello, a!
|
||||
|
||||
Return code: 0
|
||||
@@ -0,0 +1,31 @@
|
||||
OUT:
|
||||
Buildfile: [TestData]/build.xml
|
||||
|
||||
build:
|
||||
|
||||
ERR:
|
||||
|
||||
BUILD FAILED
|
||||
[TestData]/build.xml:5: org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException: Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false'
|
||||
at org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask.execute(BytecodeCompilerTask.java:146)
|
||||
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
|
||||
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
|
||||
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
|
||||
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
|
||||
at java.lang.reflect.Method.invoke(Method.java:597)
|
||||
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
|
||||
at org.apache.tools.ant.Task.perform(Task.java:348)
|
||||
at org.apache.tools.ant.Target.execute(Target.java:390)
|
||||
at org.apache.tools.ant.Target.performTasks(Target.java:411)
|
||||
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360)
|
||||
at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
|
||||
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
|
||||
at org.apache.tools.ant.Project.executeTargets(Project.java:1212)
|
||||
at org.apache.tools.ant.Main.runBuild(Main.java:801)
|
||||
at org.apache.tools.ant.Main.startAnt(Main.java:218)
|
||||
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
|
||||
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
|
||||
|
||||
Total time: [time]
|
||||
|
||||
Return code: 1
|
||||
@@ -0,0 +1,7 @@
|
||||
<project name="Ant Task Test" default="build">
|
||||
<taskdef resource="org/jetbrains/jet/buildtools/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||
|
||||
<target name="build">
|
||||
<kotlinc src="${test.data}/hello.kt" output="${temp}/hello.jar" inline="wrong"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package hello
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
for (s in arrayList("a"))
|
||||
println("Hello, $s!")
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline [String] Inlining mode: on/off (default is on)
|
||||
-inline [String] Inlining mode: on/off or true/false (default is on)
|
||||
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
|
||||
@@ -13,7 +13,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline [String] Inlining mode: on/off (default is on)
|
||||
-inline [String] Inlining mode: on/off or true/false (default is on)
|
||||
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
|
||||
@@ -13,7 +13,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline [String] Inlining mode: on/off (default is on)
|
||||
-inline [String] Inlining mode: on/off or true/false (default is on)
|
||||
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Wrong value for inline option: 'wrong'. Should be 'on' or 'off'
|
||||
Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false'
|
||||
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
-jar [String] jar file name
|
||||
-src [String] source file or directory (allows many paths separated by the system path separator)
|
||||
@@ -14,7 +14,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline [String] Inlining mode: on/off (default is on)
|
||||
-inline [String] Inlining mode: on/off or true/false (default is on)
|
||||
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
|
||||
@@ -14,7 +14,7 @@ Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-inline [String] Inlining mode: on/off (default is on)
|
||||
-inline [String] Inlining mode: on/off or true/false (default is on)
|
||||
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
@@ -31,7 +32,6 @@ import org.jetbrains.jet.codegen.state.Progress;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
import java.io.File;
|
||||
@@ -62,7 +62,7 @@ public class CodegenTestUtil {
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
|
||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST)
|
||||
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, CompilerArgumentsUtil.DEFAULT_INLINE_FLAG_FOR_TEST)
|
||||
);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return state.getFactory();
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.arguments.CompilerArgumentsUtil;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -59,7 +59,7 @@ public class GenerationUtils {
|
||||
public static GenerationState compileFilesGetGenerationState(@NotNull Project project, @NotNull AnalyzeExhaust analyzeExhaust, @NotNull List<JetFile> files) {
|
||||
analyzeExhaust.throwIfError();
|
||||
GenerationState state = new GenerationState(project, ClassBuilderFactories.TEST, analyzeExhaust.getBindingContext(), files,
|
||||
InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST);
|
||||
CompilerArgumentsUtil.DEFAULT_INLINE_FLAG_FOR_TEST);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user