BuildTools: added ant task for Kotlin2Js compiler.

This commit is contained in:
Zalim Bashorov
2013-11-14 16:15:18 +04:00
parent 9723106d95
commit df4850c22f
8 changed files with 118 additions and 61 deletions
+3
View File
@@ -1,5 +1,8 @@
<component name="libraryTable">
<library name="ant-1.7">
<ANNOTATIONS>
<root url="file://$PROJECT_DIR$/annotations" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$PROJECT_DIR$/dependencies/ant-1.7/lib/ant.jar!/" />
</CLASSES>
@@ -0,0 +1,5 @@
<root>
<item name='org.apache.tools.ant.types.Path org.apache.tools.ant.types.Path createPath()'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
@@ -1,32 +0,0 @@
/*
* 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.Task;
/**
* Kotlin JavaScript compiler Ant task.
* http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html
*/
public class JavaScriptCompilerTask extends Task {
@Override
public void execute() {
log("JavaScriptCompilerTask");
}
}
@@ -0,0 +1,99 @@
/*
* 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.Task
import org.apache.tools.ant.types.Path
import org.apache.tools.ant.types.Reference
import org.jetbrains.jet.buildtools.core.Util
import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream
import org.jetbrains.jet.cli.js.K2JSCompiler
import java.io.File
import org.apache.tools.ant.BuildException
import org.jetbrains.jet.cli.common.ExitCode
import java.util.Arrays
/**
* Kotlin JavaScript compiler Ant task.
* http://evgeny-goldin.org/javadoc/ant/tutorial-writing-tasks.html
*/
public class Kotlin2JsCompilerTask : Task() {
public var src: Path? = null
public var output: File? = null
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 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 createLibrary(): Path {
val libraryPath = library
if (libraryPath == null) {
val t = Path(getProject())
library = t
return t
}
return libraryPath.createPath()
}
override fun execute(): Unit {
val arguments = K2JSCompilerArguments()
val sourcePaths = src ?: throw BuildException("\"src\" should be specified")
arguments.sourceFiles = Util.getPaths(sourcePaths.list())
val outputFile = output ?: throw BuildException("\"output\" should be specified")
arguments.outputFile = outputFile.canonicalPath
arguments.outputPrefix = outputPrefix?.canonicalPath
arguments.outputPostfix = outputPostfix?.canonicalPath
arguments.main = main
arguments.sourcemap = sourcemap
log("Compiling [${arguments.sourceFiles?.makeString(",")}] => [${arguments.outputFile}]");
val compiler = K2JSCompiler()
val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, arguments)
if (exitCode != ExitCode.OK) {
throw BuildException("Compilation finished with exit code $exitCode")
}
}
}
@@ -7,8 +7,8 @@
name = "kotlinc"
classname = "org.jetbrains.jet.buildtools.ant.BytecodeCompilerTask"/>
<taskdef
name = "kotlinJSc"
classname = "org.jetbrains.jet.buildtools.ant.JavaScriptCompilerTask"/>
name = "kotlin2js"
classname = "org.jetbrains.jet.buildtools.ant.Kotlin2JsCompilerTask"/>
<typedef
name = "withKotlin"
classname = "org.jetbrains.jet.buildtools.ant.KotlinCompilerAdapter"/>
@@ -1,24 +0,0 @@
/*
* 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.core;
/**
* Wrapper class for Kotlin JavaScript compiler.
*/
public class JavaScriptCompiler {
}
@@ -16,6 +16,8 @@
package org.jetbrains.jet.buildtools.core;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
@@ -30,14 +32,15 @@ public final class Util {
/**
* {@code file.getCanonicalFile().getPath()} convenience wrapper.
* {@code file.getCanonicalPath()} convenience wrapper.
*
* @param f file to get its canonical path.
* @return file's canonical path
*/
public static String getPath(File f) {
@NotNull
public static String getPath(@NotNull File f) {
try {
return f.getCanonicalFile().getPath();
return f.getCanonicalPath();
}
catch (IOException e) {
throw new RuntimeException(String.format("Failed to resolve canonical file of [%s]: %s", f, e), e);
+3
View File
@@ -22,6 +22,8 @@
<property name="java.target" value="1.6"/>
<property name="external.annotations.path" value="${basedir}/annotations"/>
<path id="classpath">
<file file="${bootstrap.runtime}"/>
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
@@ -436,6 +438,7 @@
<target name="antTools">
<cleandir dir="${output}/classes/buildTools"/>
<javac2 destdir="${output}/classes/buildTools" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false" source="${java.target}" target="${java.target}">
<withKotlin externalannotations="${external.annotations.path}"/>
<src>
<dirset dir="${basedir}/build-tools">
<include name="core/src"/>