From e8c93abdb55753bdda0ed3405216932524312608 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 3 Aug 2015 23:07:39 +0300 Subject: [PATCH] Developing preprocessor task for ant --- build.xml | 5 ++ .../conditional-preprocessor.iml | 3 +- .../Preprocessor.kt | 4 +- .../PreprocessorTask.kt | 60 +++++++++++++++++++ .../org.jetbrains.kotlin.preprocessor/cli.kt | 12 ++-- 5 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/PreprocessorTask.kt diff --git a/build.xml b/build.xml index d3ecc4a1b61..689d260ba52 100644 --- a/build.xml +++ b/build.xml @@ -16,6 +16,7 @@ + @@ -738,6 +739,10 @@ + + + + diff --git a/compiler/conditional-preprocessor/conditional-preprocessor.iml b/compiler/conditional-preprocessor/conditional-preprocessor.iml index 07111c35a27..d9ba8a64b22 100644 --- a/compiler/conditional-preprocessor/conditional-preprocessor.iml +++ b/compiler/conditional-preprocessor/conditional-preprocessor.iml @@ -8,8 +8,9 @@ - + + \ No newline at end of file diff --git a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/Preprocessor.kt b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/Preprocessor.kt index d17ff1363b5..9e8cddeafdb 100644 --- a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/Preprocessor.kt +++ b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/Preprocessor.kt @@ -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) } diff --git a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/PreprocessorTask.kt b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/PreprocessorTask.kt new file mode 100644 index 00000000000..4ffffde5d3a --- /dev/null +++ b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/PreprocessorTask.kt @@ -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() + + 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") + } +} \ No newline at end of file diff --git a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/cli.kt b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/cli.kt index 8383585c379..b9b59bc6e1b 100644 --- a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/cli.kt +++ b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/cli.kt @@ -21,18 +21,16 @@ import java.util.concurrent.Executors import java.util.concurrent.TimeUnit fun main(args: Array) { - 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)