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