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
@@ -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)
}