Move GenerateProtoBuf to separate source set with no dependencies
Also move GenerateProtoBufCompare to a new source set with a dependency only on build-common. #KTI-79 Fixed
This commit is contained in:
@@ -24,6 +24,8 @@ fun extraSourceSet(name: String, extendMain: Boolean = true): Pair<SourceSet, Co
|
||||
val (builtinsSourceSet, builtinsApi) = extraSourceSet("builtins", extendMain = false)
|
||||
val (evaluateSourceSet, evaluateApi) = extraSourceSet("evaluate")
|
||||
val (interpreterSourceSet, interpreterApi) = extraSourceSet("interpreter")
|
||||
val (protobufSourceSet, protobufApi) = extraSourceSet("protobuf")
|
||||
val (protobufCompareSourceSet, protobufCompareApi) = extraSourceSet("protobufCompare")
|
||||
val (wasmSourceSet, wasmApi) = extraSourceSet("wasm")
|
||||
|
||||
dependencies {
|
||||
@@ -38,10 +40,14 @@ dependencies {
|
||||
interpreterApi(project(":compiler:ir.tree"))
|
||||
interpreterApi(project(":compiler:ir.tree.impl"))
|
||||
interpreterApi(project(":compiler:ir.psi2ir"))
|
||||
protobufApi(kotlinStdlib())
|
||||
protobufCompareApi(projectTests(":kotlin-build-common"))
|
||||
|
||||
testCompile(builtinsSourceSet.output)
|
||||
testCompile(evaluateSourceSet.output)
|
||||
testCompile(interpreterSourceSet.output)
|
||||
testCompile(protobufSourceSet.output)
|
||||
testCompile(protobufCompareSourceSet.output)
|
||||
|
||||
testCompile(projectTests(":compiler:cli"))
|
||||
testCompile(projectTests(":idea:idea-maven"))
|
||||
@@ -96,8 +102,8 @@ projectTest(parallel = true) {
|
||||
|
||||
val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateTestsKt")
|
||||
|
||||
val generateProtoBuf by generator("org.jetbrains.kotlin.generators.protobuf.GenerateProtoBufKt")
|
||||
val generateProtoBufCompare by generator("org.jetbrains.kotlin.generators.protobuf.GenerateProtoBufCompare")
|
||||
val generateProtoBuf by generator("org.jetbrains.kotlin.generators.protobuf.GenerateProtoBufKt", protobufSourceSet)
|
||||
val generateProtoBufCompare by generator("org.jetbrains.kotlin.generators.protobuf.GenerateProtoBufCompare", protobufCompareSourceSet)
|
||||
|
||||
val generateGradleOptions by generator("org.jetbrains.kotlin.generators.arguments.GenerateGradleOptionsKt")
|
||||
val generateKeywordStrings by generator("org.jetbrains.kotlin.generators.frontend.GenerateKeywordStrings")
|
||||
|
||||
+21
-17
@@ -1,13 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.generators.protobuf
|
||||
|
||||
import com.intellij.execution.configurations.GeneralCommandLine
|
||||
import com.intellij.execution.util.ExecUtil
|
||||
import com.intellij.util.LineSeparator
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.system.exitProcess
|
||||
@@ -78,19 +75,27 @@ fun main() {
|
||||
println("Do not forget to run GenerateProtoBufCompare")
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
throw e
|
||||
} finally {
|
||||
// Workaround for JVM hanging: IDEA's process handler creates thread pool
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkVersion() {
|
||||
val processOutput = ExecUtil.execAndGetOutput(GeneralCommandLine(PROTOC_EXE, "--version"))
|
||||
private data class ProcessOutput(val stdout: String, val stderr: String)
|
||||
|
||||
val version = processOutput.stdout.trim()
|
||||
private fun execAndGetOutput(vararg args: String): ProcessOutput {
|
||||
val process = ProcessBuilder().command(*args).redirectErrorStream(true).start()
|
||||
val stdout = process.inputStream.reader().readText()
|
||||
val stderr = process.errorStream.reader().readText()
|
||||
return ProcessOutput(stdout, stderr).also { process.waitFor() }
|
||||
}
|
||||
|
||||
private fun checkVersion() {
|
||||
val (stdout, stderr) = execAndGetOutput(PROTOC_EXE, "--version")
|
||||
|
||||
val version = stdout.trim()
|
||||
if (version.isEmpty()) {
|
||||
throw AssertionError("Output is empty, stderr: ${processOutput.stderr}")
|
||||
throw AssertionError("Output is empty, stderr: $stderr")
|
||||
}
|
||||
if (version != "libprotoc 2.6.1") {
|
||||
throw AssertionError("Expected protoc 2.6.1, but was: $version")
|
||||
@@ -98,15 +103,14 @@ private fun checkVersion() {
|
||||
}
|
||||
|
||||
private fun execProtoc(protoPath: String, outPath: String) {
|
||||
val commandLine = GeneralCommandLine(
|
||||
val commandLine =
|
||||
listOf(PROTOC_EXE, protoPath, "--java_out=$outPath") +
|
||||
PROTOBUF_PROTO_PATHS.map { "--proto_path=$it" }
|
||||
)
|
||||
println("running $commandLine")
|
||||
val processOutput = ExecUtil.execAndGetOutput(commandLine)
|
||||
print(processOutput.stdout)
|
||||
if (processOutput.stderr.isNotEmpty()) {
|
||||
throw AssertionError(processOutput.stderr)
|
||||
println("running ${commandLine.joinToString(" ")}")
|
||||
val (stdout, stderr) = execAndGetOutput(*commandLine.toTypedArray())
|
||||
print(stdout)
|
||||
if (stderr.isNotEmpty()) {
|
||||
throw AssertionError(stderr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +149,7 @@ private fun renamePackagesInSingleFile(javaFile: File) {
|
||||
}
|
||||
|
||||
javaFile.writeText(
|
||||
javaFile.readLines().joinToString(LineSeparator.getSystemLineSeparator().separatorString) { line ->
|
||||
javaFile.readLines().joinToString(System.lineSeparator()) { line ->
|
||||
line.replace("com.google.protobuf", "org.jetbrains.kotlin.protobuf")
|
||||
// Memory footprint optimizations: do not allocate too big bytes buffers that effectively remain unused
|
||||
.replace(" unknownFieldsOutput);", " unknownFieldsOutput, 1);")
|
||||
+6
-15
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.generators.protobuf
|
||||
@@ -39,8 +28,10 @@ class GenerateProtoBufCompare {
|
||||
}
|
||||
|
||||
fun generate(destFile: File, forbidGenerationOnTeamcity: Boolean = true) {
|
||||
GeneratorsFileUtil.writeFileIfContentChanged(destFile, GenerateProtoBufCompare().generate(),
|
||||
forbidGenerationOnTeamcity = forbidGenerationOnTeamcity)
|
||||
GeneratorsFileUtil.writeFileIfContentChanged(
|
||||
destFile, GenerateProtoBufCompare().generate(),
|
||||
forbidGenerationOnTeamcity = forbidGenerationOnTeamcity
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user