Ant task - "stdlib" attribute added, "excludeStdlib" attribute removed; <define-kotlinc/> invokes "bootstrap.xml" and works recursively

"clean" task - <delete dir="${basedir}/bootstrap.compiler"/>
This commit is contained in:
Evgeny Goldin
2012-01-27 00:50:36 +02:00
parent 8b3b7092e4
commit a43a6c6678
4 changed files with 44 additions and 55 deletions
@@ -16,29 +16,31 @@ import java.io.File;
*/
public class BytecodeCompilerTask extends Task {
private final BytecodeCompiler compiler = new BytecodeCompiler();
private boolean includeRuntime = true;
private String stdlib;
private File module;
private File srcdir;
private File file;
private File destdir;
private File destjar;
private boolean includeRuntime = true;
private boolean excludeStdlib = false;
public void setModule ( File module ) { this.module = module; }
public void setSrcdir ( File srcdir ) { this.srcdir = srcdir; }
public void setFile ( File file ) { this.file = file; }
public void setDestdir ( File destdir ) { this.destdir = destdir; }
public void setDestjar ( File destjar ) { this.destjar = destjar; }
public void setStdlib ( String stdlib ) { this.stdlib = stdlib; }
public void setModule ( File module ) { this.module = module; }
public void setSrcdir ( File srcdir ) { this.srcdir = srcdir; }
public void setFile ( File file ) { this.file = file; }
public void setDestdir ( File destdir ) { this.destdir = destdir; }
public void setDestjar ( File destjar ) { this.destjar = destjar; }
public void setIncludeRuntime ( boolean includeRuntime ) { this.includeRuntime = includeRuntime; }
public void setExcludeStdlib ( boolean excludeStdlib ) { this.excludeStdlib = excludeStdlib; }
@Override
public void execute() {
final BytecodeCompiler compiler = new BytecodeCompiler( this.stdlib );
if (( this.srcdir != null ) || ( this.file != null )) {
if (( this.destdir == null ) && ( this.destjar == null )) {
@@ -51,10 +53,10 @@ public class BytecodeCompilerTask extends Task {
log( String.format( "[%s] => [%s]", src, dest ));
if ( this.destdir != null ) {
compiler.sourcesToDir( src, dest, this.excludeStdlib );
compiler.sourcesToDir( src, dest );
}
else {
compiler.sourcesToJar( src, dest, this.includeRuntime, this.excludeStdlib );
compiler.sourcesToJar( src, dest, this.includeRuntime );
}
}
else if ( this.module != null ) {
+20 -27
View File
@@ -43,13 +43,11 @@
<antcall target="dist"/>
</then>
</if>
<unzip src = "${output}/${output.name}.zip"
dest = "${kotlin-home}"/>
<move todir = "${kotlin-home}">
<fileset dir = "${kotlin-home}/kotlinc"/>
</move>
<delete dir = "${kotlin-home}/kotlinc" failonerror = "true"/>
<delete dir="${bootstrap-dir}" failonerror="true"/>
<mkdir dir="${bootstrap-dir}"/>
<copy file="${output}/${output.name}.zip" todir="${bootstrap-dir}"/>
<ant antfile="${basedir}/bootstrap.xml"/>
<define-kotlinc/> <!-- Recursive invocation, will use bootstrapped compiler this time -->
</else>
</if>
</then>
@@ -60,7 +58,6 @@
<fileset dir = "${kotlin-home}/lib" includes = "*.jar"/>
</classpath>
</taskdef>
</sequential>
</macrodef>
@@ -77,8 +74,11 @@
<!-- Runs <kotlinc> create a *.class files in directory -->
<macrodef name="kotlinc-dir">
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<attribute name="includeRuntime" default="true"/>
<attribute name="stdlib" default="${kotlin-home}/lib/kotlin-runtime.jar"/>
<sequential>
<cleanup/>
@@ -86,10 +86,10 @@
<if>
<equals arg1="@{file}" arg2=""/>
<then>
<kotlinc srcdir = "@{srcdir}" destdir = "${tests-dir}" />
<kotlinc srcdir = "@{srcdir}" destdir = "${tests-dir}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
<else>
<kotlinc file = "@{file}" destdir = "${tests-dir}" />
<kotlinc file = "@{file}" destdir = "${tests-dir}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</else>
</if>
</sequential>
@@ -98,9 +98,11 @@
<!-- Runs <kotlinc> to create a *.class files in a jar -->
<macrodef name="kotlinc-jar">
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<attribute name="module" default=""/>
<attribute name="file" default=""/>
<attribute name="srcdir" default=""/>
<attribute name="module" default=""/>
<attribute name="includeRuntime" default="true"/>
<attribute name="stdlib" default="${kotlin-home}/lib/kotlin-runtime.jar"/>
<sequential>
<cleanup/>
@@ -110,14 +112,14 @@
<equals arg1="@{file}" arg2=""/>
</not>
<then>
<kotlinc file = "@{file}" destjar = "${tests-jar}"/>
<kotlinc file = "@{file}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
<elseif>
<not>
<equals arg1="@{srcdir}" arg2=""/>
</not>
<then>
<kotlinc srcdir = "@{srcdir}" destjar = "${tests-jar}"/>
<kotlinc srcdir = "@{srcdir}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
</elseif>
<elseif>
@@ -125,7 +127,7 @@
<equals arg1="@{module}" arg2=""/>
</not>
<then>
<kotlinc module = "@{module}" destjar = "${tests-jar}"/>
<kotlinc module = "@{module}" destjar = "${tests-jar}" includeRuntime = "@{includeRuntime}" stdlib = "@{stdlib}"/>
</then>
</elseif>
<else>
@@ -325,15 +327,6 @@
</target>
<!-- Invoked manually in a dev environment - simulates a bootstrap environment as in TeamCity build -->
<target name="buildToolsBootstrap">
<delete dir="${bootstrap-dir}" failonerror="true"/>
<mkdir dir="${bootstrap-dir}"/>
<copy file="${output}/${output.name}.zip" todir="${bootstrap-dir}"/>
<ant antfile="${basedir}/bootstrap.xml"/>
</target>
<!-- Tests build tools distribution jar -->
<target name="buildToolsTest">
<define-kotlinc/>
@@ -8,19 +8,14 @@ import org.jetbrains.jet.compiler.CompileEnvironment;
*/
public class BytecodeCompiler {
private final CompileEnvironment ENV = createCompileEnvironment();
private final CompileEnvironment ENV;
public BytecodeCompiler () {
}
/**
* Creates and initializes new {@link CompileEnvironment} instance.
* @return new {@link CompileEnvironment} instance
*/
private CompileEnvironment createCompileEnvironment () {
return new CompileEnvironment();
public BytecodeCompiler ( String stdlib ) {
ENV = new CompileEnvironment();
if ( stdlib != null ) {
ENV.setStdlib( stdlib );
}
}
@@ -39,10 +34,9 @@ public class BytecodeCompiler {
*
* @param source compilation source (directory or file)
* @param destination compilation destination
* @param excludeStdlib whether Kotlin standard library is excluded in compilation
*/
public void sourcesToDir ( String source, String destination, boolean excludeStdlib ) {
boolean success = ENV.compileBunchOfSources( source, null, destination, true);
public void sourcesToDir ( String source, String destination ) {
boolean success = ENV.compileBunchOfSources( source, null, destination, true );
if ( ! success ) {
throw new RuntimeException( compilationError( source ));
}
@@ -55,10 +49,9 @@ public class BytecodeCompiler {
* @param source compilation source (directory or file)
* @param jar compilation destination jar
* @param includeRuntime whether Kotlin runtime library is included in destination jar
* @param excludeStdlib whether Kotlin standard library is excluded in compilation
*/
public void sourcesToJar ( String source, String jar, boolean includeRuntime, boolean excludeStdlib ) {
boolean success = ENV.compileBunchOfSources( source, jar, null, includeRuntime);
public void sourcesToJar ( String source, String jar, boolean includeRuntime ) {
boolean success = ENV.compileBunchOfSources( source, jar, null, includeRuntime );
if ( ! success ) {
throw new RuntimeException( compilationError( source ));
}
+1
View File
@@ -99,6 +99,7 @@
<target name="clean">
<delete dir="${output}"/>
<delete dir="${basedir}/bootstrap.compiler"/>
</target>
<target name="dist" depends="clean,jarRT,jarJDKHeaders,jar,buildToolsJar">