From 22daacefbe8254f82fcc96a68164b7bf7029f7ac Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 2 Dec 2013 17:18:03 +0400 Subject: [PATCH] Added inline flag to ant build tool --- .../buildtools/ant/BytecodeCompilerTask.java | 12 +++-- .../jet/buildtools/core/BytecodeCompiler.java | 44 +++++++++++++------ .../jetbrains/jet/cli/jvm/K2JVMCompiler.java | 3 +- .../jet/lang/types/lang/InlineUtil.java | 10 +++-- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java index 6f9ade8c012..ebd028cb7bc 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java @@ -22,6 +22,7 @@ import org.apache.tools.ant.types.Reference; import org.jetbrains.jet.buildtools.core.BytecodeCompiler; import org.jetbrains.jet.buildtools.core.Util; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; +import org.jetbrains.jet.lang.types.lang.InlineUtil; import java.io.File; import java.util.Arrays; @@ -47,6 +48,7 @@ public class BytecodeCompilerTask extends Task { private File module; private Path compileClasspath; private boolean includeRuntime = true; + private String inline; public void setOutput(File output) { this.output = output; @@ -90,6 +92,9 @@ public class BytecodeCompilerTask extends Task { this.includeRuntime = includeRuntime; } + public void setInline(String inline) { + this.inline = inline; + } /** * Set the classpath to be used for this compilation. @@ -136,6 +141,7 @@ public class BytecodeCompilerTask extends Task { String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null); String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null); String[] externalAnnotationsPath = (this.externalAnnotations != null) ? this.externalAnnotations.list() : null; + boolean enableInline = InlineUtil.optionToInlineFlag(inline); if (this.src != null) { @@ -149,10 +155,10 @@ public class BytecodeCompilerTask extends Task { log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination)); if (this.output != null) { - compiler.sourcesToDir(source, destination, stdlibPath, classpath, externalAnnotationsPath); + compiler.sourcesToDir(source, destination, stdlibPath, classpath, externalAnnotationsPath, enableInline); } else { - compiler.sourcesToJar(source, destination, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath); + compiler.sourcesToJar(source, destination, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath, enableInline); } } else if (this.module != null) { @@ -167,7 +173,7 @@ public class BytecodeCompilerTask extends Task { log(jarPath != null ? String.format("Compiling [%s] => [%s]", modulePath, jarPath) : String.format("Compiling [%s]", modulePath)); - compiler.moduleToJar(modulePath, jarPath, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath); + compiler.moduleToJar(modulePath, jarPath, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath, enableInline); } else { throw new CompileEnvironmentException("\"src\" or \"module\" should be specified"); diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java index e7694111ac2..26eaa4a123f 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java @@ -41,6 +41,7 @@ import java.util.List; import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ANNOTATIONS_PATH_KEY; import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY; +import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.ENABLE_INLINE; /** @@ -61,18 +62,28 @@ public class BytecodeCompiler { * @param stdlib path to "kotlin-runtime.jar", only used if not null and not empty * @param classpath compilation classpath, only used if not null and not empty * @param sourceRoots + * @param enableInline * @return compile environment instance */ - private JetCoreEnvironment env(String stdlib, String[] classpath, String[] externalAnnotationsPath, String[] sourceRoots) { - CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourceRoots); + private JetCoreEnvironment env( + String stdlib, + String[] classpath, + String[] externalAnnotationsPath, + String[] sourceRoots, + boolean enableInline + ) { + CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourceRoots, enableInline); return JetCoreEnvironment.createForProduction(Disposer.newDisposable(), configuration); } - private CompilerConfiguration createConfiguration(@Nullable String stdlib, + private CompilerConfiguration createConfiguration( + @Nullable String stdlib, @Nullable String[] classpath, @Nullable String[] externalAnnotationsPath, - @NotNull String[] sourceRoots) { + @NotNull String[] sourceRoots, + boolean enableInline + ) { KotlinPaths paths = getKotlinPathsForAntTask(); CompilerConfiguration configuration = new CompilerConfiguration(); configuration.addAll(CLASSPATH_KEY, PathUtil.getJdkClassesRoots()); @@ -109,6 +120,8 @@ public class BytecodeCompiler { } configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR); + configuration.put(ENABLE_INLINE, enableInline); + // lets register any compiler plugins configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins()); return configuration; @@ -153,9 +166,10 @@ public class BytecodeCompiler { @NotNull String output, @Nullable String stdlib, @Nullable String[] classpath, - @Nullable String[] externalAnnotationsPath) { + @Nullable String[] externalAnnotationsPath, + boolean enableInline) { try { - JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src); + JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline); boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, null, new File(output), true); if (!success) { @@ -182,9 +196,10 @@ public class BytecodeCompiler { boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath, - @Nullable String[] externalAnnotationsPath) { + @Nullable String[] externalAnnotationsPath, + boolean enableInline) { try { - JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src); + JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline); boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, new File(jar), null, includeRuntime); if (!success) { @@ -199,19 +214,21 @@ public class BytecodeCompiler { /** * {@code CompileEnvironment#compileModules} wrapper. - * - * @param module compilation module file + * @param module compilation module file * @param jar compilation destination jar * @param includeRuntime whether Kotlin runtime library is included in destination jar * @param stdlib "kotlin-runtime.jar" path * @param classpath compilation classpath, can be null or empty + * @param enableInline */ - public void moduleToJar(@NotNull String module, + public void moduleToJar( + @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath, - @Nullable String[] externalAnnotationsPath) { + @Nullable String[] externalAnnotationsPath, boolean enableInline + ) { try { ModuleChunk modules = CompileEnvironmentUtil.loadModuleDescriptions(getKotlinPathsForAntTask(), module, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR); @@ -219,7 +236,8 @@ public class BytecodeCompiler { for (Module m : modules.getModules()) { sourcesRoots.addAll(m.getSourceFiles()); } - CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourcesRoots.toArray(new String[0])); + CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourcesRoots.toArray(new String[0]), + enableInline); File directory = new File(module).getParentFile(); boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime); if (!success) { diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java index b48aea59e4a..547a9fc7e27 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java @@ -32,6 +32,7 @@ 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; @@ -107,7 +108,7 @@ public class K2JVMCompiler extends CLICompiler { configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions); configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions); - configuration.put(JVMConfigurationKeys.ENABLE_INLINE, !"off".equalsIgnoreCase(arguments.enableInline)); + configuration.put(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.optionToInlineFlag(arguments.enableInline)); configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java index dc5fac040a5..c67eabfa11a 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/InlineUtil.java @@ -28,11 +28,15 @@ import org.jetbrains.jet.lang.resolve.constants.EnumValue; public class InlineUtil { - public static boolean DEFAULT_INLINE_FLAG = true; + public static final boolean DEFAULT_INLINE_FLAG = true; - public static boolean DEFAULT_INLINE_FLAG_FOR_TEST = true; + public static final boolean DEFAULT_INLINE_FLAG_FOR_TEST = true; - public static boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/ + public static final boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/ + + public static boolean optionToInlineFlag(@Nullable String option) { + return ("on".equalsIgnoreCase(option) || "off".equalsIgnoreCase(option)) ? "on".equalsIgnoreCase(option) : DEFAULT_INLINE_FLAG; + } public static boolean hasNoinlineAnnotation(@NotNull CallableDescriptor valueParameterDescriptor) { KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();