Added inline flag to ant build tool

This commit is contained in:
Mikhael Bogdanov
2013-12-02 17:18:03 +04:00
parent e06e4b8e74
commit 22daacefbe
4 changed files with 49 additions and 20 deletions
@@ -22,6 +22,7 @@ import org.apache.tools.ant.types.Reference;
import org.jetbrains.jet.buildtools.core.BytecodeCompiler; import org.jetbrains.jet.buildtools.core.BytecodeCompiler;
import org.jetbrains.jet.buildtools.core.Util; import org.jetbrains.jet.buildtools.core.Util;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
@@ -47,6 +48,7 @@ public class BytecodeCompilerTask extends Task {
private File module; private File module;
private Path compileClasspath; private Path compileClasspath;
private boolean includeRuntime = true; private boolean includeRuntime = true;
private String inline;
public void setOutput(File output) { public void setOutput(File output) {
this.output = output; this.output = output;
@@ -90,6 +92,9 @@ public class BytecodeCompilerTask extends Task {
this.includeRuntime = includeRuntime; this.includeRuntime = includeRuntime;
} }
public void setInline(String inline) {
this.inline = inline;
}
/** /**
* Set the classpath to be used for this compilation. * 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 stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null);
String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null); String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null);
String[] externalAnnotationsPath = (this.externalAnnotations != null) ? this.externalAnnotations.list() : null; String[] externalAnnotationsPath = (this.externalAnnotations != null) ? this.externalAnnotations.list() : null;
boolean enableInline = InlineUtil.optionToInlineFlag(inline);
if (this.src != null) { if (this.src != null) {
@@ -149,10 +155,10 @@ public class BytecodeCompilerTask extends Task {
log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination)); log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination));
if (this.output != null) { if (this.output != null) {
compiler.sourcesToDir(source, destination, stdlibPath, classpath, externalAnnotationsPath); compiler.sourcesToDir(source, destination, stdlibPath, classpath, externalAnnotationsPath, enableInline);
} }
else { 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) { else if (this.module != null) {
@@ -167,7 +173,7 @@ public class BytecodeCompilerTask extends Task {
log(jarPath != null ? String.format("Compiling [%s] => [%s]", modulePath, jarPath) : log(jarPath != null ? String.format("Compiling [%s] => [%s]", modulePath, jarPath) :
String.format("Compiling [%s]", modulePath)); 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 { else {
throw new CompileEnvironmentException("\"src\" or \"module\" should be specified"); throw new CompileEnvironmentException("\"src\" or \"module\" should be specified");
@@ -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.ANNOTATIONS_PATH_KEY;
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_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 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 classpath compilation classpath, only used if not null and not empty
* @param sourceRoots * @param sourceRoots
* @param enableInline
* @return compile environment instance * @return compile environment instance
*/ */
private JetCoreEnvironment env(String stdlib, String[] classpath, String[] externalAnnotationsPath, String[] sourceRoots) { private JetCoreEnvironment env(
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourceRoots); String stdlib,
String[] classpath,
String[] externalAnnotationsPath,
String[] sourceRoots,
boolean enableInline
) {
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourceRoots, enableInline);
return JetCoreEnvironment.createForProduction(Disposer.newDisposable(), configuration); return JetCoreEnvironment.createForProduction(Disposer.newDisposable(), configuration);
} }
private CompilerConfiguration createConfiguration(@Nullable String stdlib, private CompilerConfiguration createConfiguration(
@Nullable String stdlib,
@Nullable String[] classpath, @Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath, @Nullable String[] externalAnnotationsPath,
@NotNull String[] sourceRoots) { @NotNull String[] sourceRoots,
boolean enableInline
) {
KotlinPaths paths = getKotlinPathsForAntTask(); KotlinPaths paths = getKotlinPathsForAntTask();
CompilerConfiguration configuration = new CompilerConfiguration(); CompilerConfiguration configuration = new CompilerConfiguration();
configuration.addAll(CLASSPATH_KEY, PathUtil.getJdkClassesRoots()); 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(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
configuration.put(ENABLE_INLINE, enableInline);
// lets register any compiler plugins // lets register any compiler plugins
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins()); configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
return configuration; return configuration;
@@ -153,9 +166,10 @@ public class BytecodeCompiler {
@NotNull String output, @NotNull String output,
@Nullable String stdlib, @Nullable String stdlib,
@Nullable String[] classpath, @Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath) { @Nullable String[] externalAnnotationsPath,
boolean enableInline) {
try { 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); boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, null, new File(output), true);
if (!success) { if (!success) {
@@ -182,9 +196,10 @@ public class BytecodeCompiler {
boolean includeRuntime, boolean includeRuntime,
@Nullable String stdlib, @Nullable String stdlib,
@Nullable String[] classpath, @Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath) { @Nullable String[] externalAnnotationsPath,
boolean enableInline) {
try { 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); boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, new File(jar), null, includeRuntime);
if (!success) { if (!success) {
@@ -199,19 +214,21 @@ public class BytecodeCompiler {
/** /**
* {@code CompileEnvironment#compileModules} wrapper. * {@code CompileEnvironment#compileModules} wrapper.
* * @param module compilation module file
* @param module compilation module file
* @param jar compilation destination jar * @param jar compilation destination jar
* @param includeRuntime whether Kotlin runtime library is included in destination jar * @param includeRuntime whether Kotlin runtime library is included in destination jar
* @param stdlib "kotlin-runtime.jar" path * @param stdlib "kotlin-runtime.jar" path
* @param classpath compilation classpath, can be <code>null</code> or empty * @param classpath compilation classpath, can be <code>null</code> or empty
* @param enableInline
*/ */
public void moduleToJar(@NotNull String module, public void moduleToJar(
@NotNull String module,
@NotNull String jar, @NotNull String jar,
boolean includeRuntime, boolean includeRuntime,
@Nullable String stdlib, @Nullable String stdlib,
@Nullable String[] classpath, @Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath) { @Nullable String[] externalAnnotationsPath, boolean enableInline
) {
try { try {
ModuleChunk modules = CompileEnvironmentUtil.loadModuleDescriptions(getKotlinPathsForAntTask(), module, ModuleChunk modules = CompileEnvironmentUtil.loadModuleDescriptions(getKotlinPathsForAntTask(), module,
MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR); MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
@@ -219,7 +236,8 @@ public class BytecodeCompiler {
for (Module m : modules.getModules()) { for (Module m : modules.getModules()) {
sourcesRoots.addAll(m.getSourceFiles()); 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(); File directory = new File(module).getParentFile();
boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime); boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime);
if (!success) { if (!success) {
@@ -32,6 +32,7 @@ import org.jetbrains.jet.codegen.CompilationException;
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;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.KotlinPathsFromHomeDir; import org.jetbrains.jet.utils.KotlinPathsFromHomeDir;
import org.jetbrains.jet.utils.PathUtil; import org.jetbrains.jet.utils.PathUtil;
@@ -107,7 +108,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions); configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions); 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); configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
@@ -28,11 +28,15 @@ import org.jetbrains.jet.lang.resolve.constants.EnumValue;
public class InlineUtil { 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) { public static boolean hasNoinlineAnnotation(@NotNull CallableDescriptor valueParameterDescriptor) {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();