From 9c906836f30b7e6ef3b2b38e448322486b127efd Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 30 Jul 2014 19:41:05 -0700 Subject: [PATCH] Ant task: drop "module" support, drop unused compiler plugins code Modules should only be used in IDE and the compiler is launched there directly --- .../buildtools/ant/BytecodeCompilerTask.java | 42 +++-------- .../jet/buildtools/core/BytecodeCompiler.java | 73 +------------------ 2 files changed, 13 insertions(+), 102 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 35b8374fb31..723c8f24aae 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 @@ -45,7 +45,6 @@ public class BytecodeCompilerTask extends Task { private File stdlib; private Path src; private Path externalAnnotations; - private File module; private Path compileClasspath; private boolean includeRuntime = true; private final List additionalArguments = new ArrayList(); @@ -80,10 +79,6 @@ public class BytecodeCompilerTask extends Task { return externalAnnotations.createPath(); } - public void setModule(File module) { - this.module = module; - } - public void setIncludeRuntime(boolean includeRuntime) { this.includeRuntime = includeRuntime; } @@ -108,7 +103,6 @@ public class BytecodeCompilerTask extends Task { } } - /** * Adds a reference to a classpath defined elsewhere. * @@ -121,7 +115,6 @@ public class BytecodeCompilerTask extends Task { this.compileClasspath.createPath().setRefid(ref); } - /** * Set the nested {@code } to be used for this compilation. * @@ -131,43 +124,28 @@ public class BytecodeCompilerTask extends Task { setClasspath(classpath); } - @Override public void execute() { - BytecodeCompiler compiler = new BytecodeCompiler(); - String stdlibPath = (stdlib != null ? getPath(stdlib) : null); - String[] classpath = (compileClasspath != null ? compileClasspath.list() : null); - String[] externalAnnotationsPath = (externalAnnotations != null) ? externalAnnotations.list() : null; + String stdlibPath = stdlib != null ? getPath(stdlib) : null; + String[] classpath = compileClasspath != null ? compileClasspath.list() : null; + String[] externalAnnotationsPath = externalAnnotations != null ? externalAnnotations.list() : null; List args = new ArrayList(); for (Commandline.Argument argument : additionalArguments) { args.addAll(Arrays.asList(argument.getParts())); } + if (src == null) { + throw new BuildException("\"src\" should be specified"); + } if (output == null) { throw new BuildException("\"output\" should be specified"); } - if (src != null) { - String[] source = Util.getPaths(src.list()); - String destination = getPath(output); + String[] source = Util.getPaths(src.list()); + String destination = getPath(output); - log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination)); - compiler.compileSources(source, destination, includeRuntime, stdlibPath, classpath, externalAnnotationsPath, args); - } - else if (module != null) { - if (!output.toString().endsWith(".jar")) { - throw new BuildException("Module compilation is only supported for jar destination"); - } - - String modulePath = getPath(module); - String jarPath = getPath(output); - - log(String.format("Compiling [%s] => [%s]", modulePath, jarPath)); - compiler.compileModule(modulePath, jarPath, includeRuntime, stdlibPath, classpath, externalAnnotationsPath, args); - } - else { - throw new BuildException("\"src\" or \"module\" should be specified"); - } + log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination)); + BytecodeCompiler.compileSources(source, destination, includeRuntime, stdlibPath, classpath, externalAnnotationsPath, args); } } 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 f7aeed973bb..7ff11568d09 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 @@ -22,15 +22,12 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; import com.sampullara.cli.Args; -import kotlin.modules.Module; import org.apache.tools.ant.BuildException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.cli.common.CLIConfigurationKeys; -import org.jetbrains.jet.cli.common.CompilerPlugin; import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments; import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream; -import org.jetbrains.jet.cli.common.modules.ModuleScriptData; import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys; import org.jetbrains.jet.cli.jvm.K2JVMCompiler; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; @@ -43,24 +40,17 @@ import org.jetbrains.jet.utils.KotlinPathsFromHomeDir; import org.jetbrains.jet.utils.PathUtil; import java.io.File; -import java.util.ArrayList; import java.util.Arrays; 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.compiler.CompileEnvironmentUtil.loadModuleDescriptions; public class BytecodeCompiler { private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - private List compilerPlugins = new ArrayList(); - - public BytecodeCompiler() { - } - @NotNull - private CompilerConfiguration createConfiguration( + private static CompilerConfiguration createConfiguration( @Nullable String stdlib, @Nullable String[] classpath, @Nullable String[] externalAnnotationsPath, @@ -114,8 +104,6 @@ public class BytecodeCompiler { K2JVMCompiler.putAdvancedOptions(configuration, arguments); - // lets register any compiler plugins - configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins()); return configuration; } @@ -141,13 +129,12 @@ public class BytecodeCompiler { /** * {@code KotlinToJVMBytecodeCompiler#compileBunchOfSources} wrapper. * @param src compilation source (directory or file) - * @param destination compilation destination jar + * @param destination compilation destination (directory or 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 args additional command line arguments to Kotlin compiler */ - public void compileSources( + public static void compileSources( @NotNull String[] src, @NotNull String destination, boolean includeRuntime, @@ -183,61 +170,7 @@ public class BytecodeCompiler { } } - /** - * {@code KotlinToJVMBytecodeCompiler#compileModules} wrapper. - * @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 args additional command line arguments to Kotlin compiler - */ - public void compileModule( - @NotNull String module, - @NotNull String jar, - boolean includeRuntime, - @Nullable String stdlib, - @Nullable String[] classpath, - @Nullable String[] externalAnnotationsPath, - @NotNull List args - ) { - try { - ModuleScriptData moduleScriptData = - loadModuleDescriptions(getKotlinPathsForAntTask(), module, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR); - List modules = moduleScriptData.getModules(); - List sourcesRoots = new ArrayList(); - for (Module m : modules) { - sourcesRoots.addAll(m.getSourceFiles()); - } - CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, - ArrayUtil.toStringArray(sourcesRoots), args); - File directory = new File(module).getParentFile(); - boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime); - if (!success) { - throw new CompileEnvironmentException(errorMessage(new String[]{module}, false)); - } - } - catch (BuildException e) { - throw e; - } - catch (CompileEnvironmentException e) { - throw e; - } - catch (Exception e) { - throw new CompileEnvironmentException(errorMessage(new String[]{module}, true), e); - } - } - - public List getCompilerPlugins() { - return compilerPlugins; - } - - public void setCompilerPlugins(List compilerPlugins) { - this.compilerPlugins = compilerPlugins; - } - private static KotlinPaths getKotlinPathsForAntTask() { return new KotlinPathsFromHomeDir(PathUtil.getJarPathForClass(BytecodeCompiler.class).getParentFile().getParentFile()); } - }