Rename module build-tools -> ant
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
<orderEntry type="library" name="idea-full" level="project" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="backend" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="library" name="ant-1.7" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.buildtools.ant
|
||||
|
||||
import org.apache.tools.ant.types.Path
|
||||
import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.jet.cli.js.K2JSCompiler
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Kotlin JavaScript compiler Ant task.
|
||||
* http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html
|
||||
*/
|
||||
public class Kotlin2JsTask : KotlinCompilerBaseTask<K2JSCompilerArguments>() {
|
||||
override val arguments = K2JSCompilerArguments()
|
||||
override val compiler = K2JSCompiler()
|
||||
|
||||
public var library: Path? = null
|
||||
public var outputPrefix: File? = null
|
||||
public var outputPostfix: File? = null
|
||||
public var sourceMap: Boolean = false
|
||||
|
||||
/**
|
||||
* {@link K2JsArgumentConstants.CALL} (default) if need generate a main function call (main function will be auto detected)
|
||||
* {@link K2JsArgumentConstants.NO_CALL} otherwise.
|
||||
*/
|
||||
public var main: String? = null
|
||||
|
||||
public fun createLibrary(): Path {
|
||||
val libraryPath = library
|
||||
if (libraryPath == null) {
|
||||
val t = Path(getProject())
|
||||
library = t
|
||||
return t
|
||||
}
|
||||
|
||||
return libraryPath.createPath()
|
||||
}
|
||||
|
||||
override fun fillSpecificArguments() {
|
||||
arguments.outputFile = getPath(output!!)
|
||||
|
||||
arguments.noStdlib = noStdlib
|
||||
|
||||
// TODO: write test
|
||||
library?.let {
|
||||
arguments.libraryFiles = it.list().map { getPath(File(it)) }.copyToArray()
|
||||
}
|
||||
|
||||
arguments.outputPrefix = outputPrefix?.canonicalPath
|
||||
arguments.outputPostfix = outputPostfix?.canonicalPath
|
||||
|
||||
arguments.main = main
|
||||
arguments.sourceMap = sourceMap
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.buildtools.ant
|
||||
|
||||
import org.apache.tools.ant.types.Path
|
||||
import org.apache.tools.ant.types.Reference
|
||||
|
||||
import java.io.File
|
||||
import java.io.File.pathSeparator
|
||||
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
|
||||
|
||||
/**
|
||||
* Kotlin bytecode compiler Ant task.
|
||||
* <p/>
|
||||
* See
|
||||
* http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html
|
||||
* http://evgeny-goldin.org/javadoc/ant/develop.html
|
||||
* http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Javac.java?view=markup.
|
||||
*/
|
||||
public class Kotlin2JvmTask : KotlinCompilerBaseTask<K2JVMCompilerArguments>() {
|
||||
override val arguments = K2JVMCompilerArguments()
|
||||
override val compiler = K2JVMCompiler()
|
||||
|
||||
public var externalAnnotations: Path? = null
|
||||
public var includeRuntime: Boolean = true
|
||||
|
||||
private var compileClasspath: Path? = null
|
||||
|
||||
public fun createExternalAnnotations(): Path {
|
||||
if (externalAnnotations == null) {
|
||||
externalAnnotations = Path(getProject())
|
||||
}
|
||||
return externalAnnotations!!.createPath()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the classpath to be used for this compilation.
|
||||
*
|
||||
* @param classpath an Ant Path object containing the compilation classpath.
|
||||
*/
|
||||
public fun setClasspath(classpath: Path) {
|
||||
if (this.compileClasspath == null) {
|
||||
this.compileClasspath = classpath
|
||||
}
|
||||
else {
|
||||
this.compileClasspath!!.append(classpath)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a reference to a classpath defined elsewhere.
|
||||
*
|
||||
* @param ref a reference to a classpath.
|
||||
*/
|
||||
public fun setClasspathRef(ref: Reference) {
|
||||
if (this.compileClasspath == null) {
|
||||
this.compileClasspath = Path(getProject())
|
||||
}
|
||||
this.compileClasspath!!.createPath().setRefid(ref)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nested {@code <classpath>} to be used for this compilation.
|
||||
*
|
||||
* @param classpath an Ant Path object containing the compilation classpath.
|
||||
*/
|
||||
public fun addConfiguredClasspath(classpath: Path) {
|
||||
setClasspath(classpath)
|
||||
}
|
||||
|
||||
override fun fillSpecificArguments() {
|
||||
arguments.destination = getPath(output!!)
|
||||
|
||||
val classpath = arrayListOf<String>()
|
||||
compileClasspath?.let { classpath.addAll(it.list()) }
|
||||
arguments.freeArgs?.forEach {
|
||||
val file = File(it)
|
||||
if (file.isDirectory() || file.extension != "kt") {
|
||||
classpath.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
arguments.classpath = classpath.join(pathSeparator)
|
||||
|
||||
arguments.annotations = externalAnnotations?.list()?.join(pathSeparator)
|
||||
arguments.noStdlib = noStdlib
|
||||
arguments.includeRuntime = includeRuntime
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.buildtools.ant;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.taskdefs.Javac;
|
||||
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
|
||||
import org.apache.tools.ant.taskdefs.compilers.Javac13;
|
||||
import org.apache.tools.ant.types.Path;
|
||||
|
||||
public class KotlinCompilerAdapter extends DefaultCompilerAdapter {
|
||||
private Path externalAnnotations;
|
||||
|
||||
public void setExternalAnnotations(Path externalAnnotations) {
|
||||
this.externalAnnotations = externalAnnotations;
|
||||
}
|
||||
|
||||
public Path createExternalAnnotations() {
|
||||
if (externalAnnotations == null) {
|
||||
externalAnnotations = new Path(getProject());
|
||||
}
|
||||
return externalAnnotations.createPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() throws BuildException {
|
||||
Javac javac = getJavac();
|
||||
|
||||
Kotlin2JvmTask kotlinTask = new Kotlin2JvmTask();
|
||||
kotlinTask.setOutput(javac.getDestdir());
|
||||
kotlinTask.setClasspath(javac.getClasspath());
|
||||
kotlinTask.setSrc(javac.getSrcdir());
|
||||
kotlinTask.setExternalAnnotations(externalAnnotations);
|
||||
|
||||
kotlinTask.execute();
|
||||
|
||||
javac.log("Running javac...");
|
||||
|
||||
Javac13 javac13 = new Javac13();
|
||||
javac13.setJavac(javac);
|
||||
return javac13.execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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.buildtools.ant
|
||||
|
||||
import org.apache.tools.ant.Task
|
||||
import org.apache.tools.ant.types.Path
|
||||
import org.apache.tools.ant.types.Reference
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream
|
||||
import java.io.File
|
||||
import org.apache.tools.ant.BuildException
|
||||
import org.jetbrains.jet.cli.common.ExitCode
|
||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.jet.cli.common.CLICompiler
|
||||
import org.apache.tools.ant.types.Commandline
|
||||
import com.sampullara.cli.Args
|
||||
import java.io.IOException
|
||||
import org.jetbrains.jet.config
|
||||
import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector
|
||||
import org.jetbrains.jet.cli.common.messages.MessageRenderer
|
||||
|
||||
/**
|
||||
* {@code file.getCanonicalPath()} convenience wrapper.
|
||||
*
|
||||
* @param file - file to get its canonical path.
|
||||
* @return file's canonical path
|
||||
*/
|
||||
fun getPath(file: File): String {
|
||||
try {
|
||||
return file.getCanonicalPath()
|
||||
}
|
||||
catch (e: IOException) {
|
||||
throw RuntimeException("Failed to resolve canonical file of [$file]: $e", e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for Kotlin compiler Ant tasks.
|
||||
* http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html
|
||||
*/
|
||||
public abstract class KotlinCompilerBaseTask<T : CommonCompilerArguments> : Task() {
|
||||
protected abstract val arguments: T
|
||||
protected abstract val compiler: CLICompiler<T>
|
||||
|
||||
public var src: Path? = null
|
||||
public var output: File? = null
|
||||
public var nowarn: Boolean = false
|
||||
public var verbose: Boolean = false
|
||||
public var printVersion: Boolean = false
|
||||
|
||||
public var noStdlib: Boolean = false
|
||||
|
||||
public val additionalArguments: MutableList<Commandline.Argument> = arrayListOf()
|
||||
|
||||
public fun createSrc(): Path {
|
||||
val srcPath = src
|
||||
if (srcPath == null) {
|
||||
val t = Path(getProject())
|
||||
src = t
|
||||
return t
|
||||
}
|
||||
|
||||
return srcPath.createPath()
|
||||
}
|
||||
|
||||
public fun setSrcRef(ref: Reference) {
|
||||
createSrc().setRefid(ref)
|
||||
}
|
||||
|
||||
public fun createCompilerArg(): Commandline.Argument {
|
||||
val argument = Commandline.Argument()
|
||||
additionalArguments.add(argument)
|
||||
return argument
|
||||
}
|
||||
|
||||
abstract fun fillSpecificArguments()
|
||||
|
||||
private fun fillArguments() {
|
||||
val sourcePaths = src ?: throw BuildException("\"src\" should be specified")
|
||||
arguments.freeArgs = sourcePaths.list().map { getPath(File(it)) }
|
||||
|
||||
output ?: throw BuildException("\"output\" should be specified")
|
||||
|
||||
arguments.suppressWarnings = nowarn
|
||||
arguments.verbose = verbose
|
||||
arguments.version = printVersion
|
||||
|
||||
val args = additionalArguments.flatMap { it.getParts()!!.toList() }
|
||||
try {
|
||||
Args.parse(arguments, args.copyToArray())
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
throw BuildException(e.getMessage())
|
||||
}
|
||||
|
||||
fillSpecificArguments()
|
||||
}
|
||||
|
||||
final override fun execute(): Unit {
|
||||
fillArguments()
|
||||
|
||||
val outputPath = getPath(output!!)
|
||||
|
||||
log("Compiling ${arguments.freeArgs} => [${outputPath}]");
|
||||
|
||||
val collector = PrintingMessageCollector(System.err, MessageRenderer.PLAIN, arguments.verbose)
|
||||
val exitCode = compiler.exec(collector, config.Services.EMPTY, arguments)
|
||||
|
||||
if (exitCode != ExitCode.OK) {
|
||||
throw BuildException("Compilation finished with exit code $exitCode")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
|
||||
<!-- http://evgeny-goldin.org/javadoc/ant/Types/antlib.html -->
|
||||
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
|
||||
|
||||
<antlib>
|
||||
<taskdef
|
||||
name = "kotlinc"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.Kotlin2JvmTask"/>
|
||||
<taskdef
|
||||
name = "kotlin2js"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.Kotlin2JsTask"/>
|
||||
<typedef
|
||||
name = "withKotlin"
|
||||
classname = "org.jetbrains.jet.buildtools.ant.KotlinCompilerAdapter"/>
|
||||
</antlib>
|
||||
Reference in New Issue
Block a user