Remove task for ant, include preprocessor into the compiler, call preprocessor in ant build.

This commit is contained in:
Ilya Gorbunov
2015-08-04 18:56:16 +03:00
parent e8c93abdb5
commit 1df4ab847d
5 changed files with 73 additions and 49 deletions
+32 -8
View File
@@ -1,6 +1,4 @@
<project name="Kotlin" default="dist" xmlns:if="ant:if" xmlns:unless="ant:unless">
<include file="jslib_files.xml" />
<property file="resources/kotlinManifest.properties"/>
<!-- Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build -->
@@ -16,7 +14,7 @@
<property name="bootstrap.reflect" value="${bootstrap.compiler.home}/lib/kotlin-reflect.jar"/>
<property name="output" value="${basedir}/dist"/>
<property name="intermediate-sources" value="${basedir}/out/src" />
<property name="intermediate-sources" value="out/src" />
<property name="kotlin-home" value="${output}/kotlinc"/>
<property name="build.number" value="snapshot"/>
<property name="bootstrap.build.no.tests" value="false"/>
@@ -40,6 +38,8 @@
</or>
</condition>
<include file="jslib_files.xml" />
<!--
The compiler produced on the first step of the build (Bootstrap No Tests) is only guaranteed to work against the OLD runtime
located in dependencies/bootstrap-compiler/.../kotlin-runtime.jar, because the newly built compiler is just a Kotlin application,
@@ -87,6 +87,7 @@
<include name="compiler/builtins-serializer/src"/>
<include name="compiler/cli/src"/>
<include name="compiler/cli/cli-common/src"/>
<include name="compiler/conditional-preprocessor/src/"/>
<include name="compiler/rmi/rmi-server/src"/>
<include name="compiler/rmi/rmi-interface/src"/>
<include name="compiler/container/src"/>
@@ -203,6 +204,7 @@
<fileset dir="compiler/builtins-serializer/src"/>
<fileset dir="compiler/cli/src"/>
<fileset dir="compiler/cli/cli-common/src"/>
<fileset dir="compiler/conditional-preprocessor/src"/>
<fileset dir="compiler/rmi/rmi-server/src"/>
<fileset dir="compiler/rmi/rmi-interface/src"/>
<fileset dir="compiler/container/src"/>
@@ -305,6 +307,8 @@
<property name="compiled.stdlib.meta.js" value="stdlib.meta.js"/>
<property name="stdlib.js.dir" value="${basedir}/js/js.translator/testData"/>
<kotlin-pp src="libraries/stdlib/src" output="${intermediate-sources}/stdlib/js" profile="JS" />
<new-kotlin2js output="${output}/${compiled.builtins.js}">
<src>
<fileset refid="kotlin.builtin.files"/>
@@ -725,6 +729,29 @@
</sequential>
</macrodef>
<macrodef name="kotlin-pp">
<attribute name="src"/>
<attribute name="output"/>
<attribute name="profile"/>
<sequential>
<java classname="org.jetbrains.kotlin.preloading.Preloader" failonerror="true" fork="true" maxmemory="${max.heap.size.for.forked.jvm}">
<classpath>
<pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
</classpath>
<assertions>
<enable/>
</assertions>
<arg value="-cp"/>
<arg value="${kotlin-home}/lib/kotlin-compiler.jar"/>
<arg value="org.jetbrains.kotlin.preprocessor.PreprocessorPackage"/>
<arg value="@{src}"/>
<arg value="@{output}"/>
<arg value="@{profile}"/>
</java>
</sequential>
</macrodef>
<target name="builtins">
<new-kotlinc output="${output}/classes/builtins" moduleName="kotlin-builtins">
<src>
@@ -739,13 +766,10 @@
</target>
<target name="stdlib">
<taskdef name="kotlin-pp" classname="org.jetbrains.kotlin.preprocessor.PreprocessorTask" classpathref="classpath" classpath="out\production\conditional-preprocessor" />
<kotlin-pp src="libraries/stdlib/src">
<jvmprofile version="6" output="${intermediate-sources}/stdlib/jvm6" />
</kotlin-pp>
<kotlin-pp src="libraries/stdlib/src" output="${intermediate-sources}/stdlib/jvm6" profile="JVM6" />
<new-kotlinc output="${output}/classes/stdlib" moduleName="kotlin-stdlib" additionalOptions="-Xmultifile-package-facades">
<src>
<include name="libraries/stdlib/src"/>
<include name="${intermediate-sources}/stdlib/jvm6"/>
</src>
<class-path>
<pathelement path="${output}/classes/builtins"/>
@@ -68,7 +68,7 @@ public class Preprocessor() {
val sourceText = sourceFile.readText().convertLineSeparators()
val psiFile = jetPsiFactory.createFile(sourceFile.name, sourceText)
println("$psiFile")
//println("$psiFile")
val fileAnnotations = psiFile.parseConditionalAnnotations()
@@ -93,40 +93,42 @@ public class Preprocessor() {
for (sourceFile in sourceFiles)
{
val result = processFileSingleEvaluator(sourceFile, evaluator)
if (result is FileProcessingResult.Skip)
if (result is FileProcessingResult.Skip) {
println("$sourceFile is excluded")
continue
}
val destFile = sourceFile.makeRelativeTo(sourceRoot, targetRoot)
processedFiles += destFile
val targetFile = sourceFile.makeRelativeTo(sourceRoot, targetRoot)
processedFiles += targetFile
if (destFile.exists() && destFile.isDirectory)
destFile.deleteRecursively()
if (targetFile.exists() && targetFile.isDirectory)
targetFile.deleteRecursively()
// if no modifications — copy
if (result is FileProcessingResult.Copy) {
FileUtil.copy(sourceFile, destFile)
FileUtil.copy(sourceFile, targetFile)
} else if (result is FileProcessingResult.Modify) {
val resultText = result.getModifiedText()
if (destFile.exists() && destFile.isTextEqualTo(resultText))
if (targetFile.exists() && targetFile.isTextEqualTo(resultText))
continue
destFile.writeText(resultText)
println("Rewriting modified $targetFile")
targetFile.writeText(resultText)
}
}
for (sourceDir in sourceDirectories) {
val destDir = sourceDir.makeRelativeTo(sourceRoot, targetRoot)
if (!destDir.exists()) {
destDir.mkdirsOrFail()
val targetDir = sourceDir.makeRelativeTo(sourceRoot, targetRoot)
if (targetDir.exists() && !targetDir.isDirectory) {
targetDir.delete()
}
else if (!destDir.isDirectory) {
destDir.delete()
}
processDirectorySingleEvaluator(sourceDir, destDir, evaluator)
processedFiles += destDir
targetDir.mkdirsOrFail()
processDirectorySingleEvaluator(sourceDir, targetDir, evaluator)
processedFiles += targetDir
}
targetRoot.listFiles().forEach { targetFile ->
for (targetFile in targetRoot.listFiles()) {
if (!processedFiles.remove(processedFiles.find { FileUtil.filesEqual(it, targetFile) })) {
println("Removing skipped $targetFile")
targetFile.deleteRecursively()
}
}
@@ -15,7 +15,7 @@
*/
package org.jetbrains.kotlin.preprocessor
/*
import org.apache.tools.ant.Task
import java.io.File
@@ -25,7 +25,7 @@ public class PreprocessorTask: Task() {
public var version: Int? = null
public var output: File? = null
}
public class JsProfileConfig{
public class JsProfileConfig {
public var output: File? = null
}
@@ -57,4 +57,5 @@ public class PreprocessorTask: Task() {
if (src == null) throw IllegalArgumentException("src")
if (profiles.isEmpty()) throw IllegalArgumentException("profiles")
}
}
}
*/
@@ -21,17 +21,27 @@ import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
require(args.size() == 2, "Please specify path to sources and output path for all platforms")
if (args.size() != 3) {
println("Usage: <path to sources> <output path> <profile>")
System.exit(1)
}
val sourcePath = File(args[0])
val targetPath = File(args[1])
val profileName = args[2]
val profiles = listOf(6, 7, 8).map { createJvmProfile(targetPath, version = it) } + createJsProfile(targetPath)
val profiles = listOf(6, 7, 8).map { version -> "JVM$version" to { JvmPlatformEvaluator(version) } } + ("JS" to { JsPlatformEvaluator() })
val pool = Executors.newCachedThreadPool()
val (name, evaluatorBuilder) = profiles.single { it.first.equals(profileName, ignoreCase = true) }
val profile = Profile(name, evaluatorBuilder(), targetPath)
profiles.forEach { profile -> pool.submit { Preprocessor().processSources(sourcePath, profile) } }
println("Preprocessing sources in $sourcePath to $targetPath with profile ${profile.name}")
Preprocessor().processSources(sourcePath, profile)
pool.shutdown()
pool.awaitTermination(1, TimeUnit.MINUTES)
// val pool = Executors.newCachedThreadPool()
//
// profiles.forEach { profile -> pool.submit { Preprocessor().processSources(sourcePath, profile) } }
//
// pool.shutdown()
// pool.awaitTermination(1, TimeUnit.MINUTES)
}
+1 -14
View File
@@ -20,25 +20,12 @@
<include name="kotlin/annotation/Annotations.kt"/>
</fileset>
<fileset dir="${basedir}/libraries/stdlib/src">
<fileset dir="${basedir}/${intermediate-sources}/stdlib/js">
<include name="**/*.kt" />
<!-- JVM specific -->
<exclude name="**/*JVM.kt" />
<exclude name="kotlin/jvm/**" />
<exclude name="kotlin/beans/**" />
<exclude name="kotlin/browser/**" />
<exclude name="kotlin/concurrent/**" />
<exclude name="kotlin/io/**" />
<exclude name="kotlin/math/**" />
<exclude name="kotlin/template/**" />
<!-- Temporary disabled -->
<!--TODO fix: (84, 27) Unresolved reference: copyOf (_SpecialJVM.kt)-->
<exclude name="kotlin/collections/ImmutableArrayList.kt" />
<!-- TODO fix: AllModules is subclass of ThreadLocal. -->
<exclude name="kotlin/modules/**" />
</fileset>
</union>
</project>