Developing preprocessor task for ant

This commit is contained in:
Ilya Gorbunov
2015-08-03 23:07:39 +03:00
parent 7b206fdaf4
commit e8c93abdb5
5 changed files with 74 additions and 10 deletions
@@ -8,8 +8,9 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="cli" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="library" name="ant" level="project" />
<orderEntry type="module" module-name="cli" />
<orderEntry type="module" module-name="frontend" />
</component>
</module>
@@ -36,7 +36,7 @@ fun createJvmProfile(targetRoot: File, version: Int) = Profile("JVM$version", Jv
fun createJsProfile(targetRoot: File) = Profile("JS", JsPlatformEvaluator(), File(targetRoot, "js"))
public class Preprocessor(val profile: Profile) {
public class Preprocessor() {
val fileType = JetFileType.INSTANCE
val jetPsiFactory: JetPsiFactory
@@ -58,7 +58,7 @@ public class Preprocessor(val profile: Profile) {
}
}
public fun processSources(sourceRoot: File) {
public fun processSources(sourceRoot: File, profile: Profile) {
processDirectorySingleEvaluator(sourceRoot, profile.targetRoot, profile.evaluator)
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2015 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.kotlin.preprocessor
import org.apache.tools.ant.Task
import java.io.File
public class PreprocessorTask: Task() {
public class JvmProfileConfig {
public var version: Int? = null
public var output: File? = null
}
public class JsProfileConfig{
public var output: File? = null
}
public var src: File? = null
private val profiles = arrayListOf<Profile>()
public fun addConfiguredJvmProfile(configuration: JvmProfileConfig) {
val version = configuration.version ?: throw IllegalArgumentException("version")
val output = configuration.output ?: throw IllegalArgumentException("output")
profiles.add(Profile("JVM$version", JvmPlatformEvaluator(version), output))
}
public fun addConfiguredJsProfile(configuration: JsProfileConfig) {
val output = configuration.output ?: throw IllegalArgumentException("output")
profiles.add(Profile("JS", JsPlatformEvaluator(), output))
}
override fun execute() {
checkParameters()
profiles.forEach { profile ->
val preprocessor = Preprocessor()
log("Preprocessing sources for ${profile.name}")
preprocessor.processSources(src!!, profile)
}
}
private fun checkParameters() {
if (src == null) throw IllegalArgumentException("src")
if (profiles.isEmpty()) throw IllegalArgumentException("profiles")
}
}
@@ -21,18 +21,16 @@ import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
require(args.size() == 1, "Please specify path to sources")
require(args.size() == 2, "Please specify path to sources and output path for all platforms")
val sourcePath = File(args.first())
val sourcePath = File(args[0])
val targetPath = File(args[1])
val targetPath = File("libraries/stdlib/target")
val profiles = listOf(6, 7, 8).map { Preprocessor(createJvmProfile(targetPath, version = it)) }
val profiles = listOf(6, 7, 8).map { createJvmProfile(targetPath, version = it) } + createJsProfile(targetPath)
val pool = Executors.newCachedThreadPool()
profiles.forEach { pool.submit { it.processSources(sourcePath) } }
profiles.forEach { profile -> pool.submit { Preprocessor().processSources(sourcePath, profile) } }
pool.shutdown()
pool.awaitTermination(1, TimeUnit.MINUTES)