Skip to content

Commit 22306e7

Browse files
committed
Fix build after changes introduced by metadata/jvm libs
1 parent 76e9cac commit 22306e7

File tree

4 files changed

+71
-48
lines changed

4 files changed

+71
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Wraps [JetBrains/kotlin] to produce a subset of the [Kotlin] compiler to be used
1010

1111
+ all Kotlin/Java sources, even for external dependencies
1212
+ every package relocated under `me.eugeniomarletti.kotlin.metadata.shadow.*` in both compiled classes and sources
13-
+ "full" version of all [Protocol Buffers], instead of the "lite" one used by default (see [Options > `optimize_for` > `LITE_RUNTIME`](https://developers.google.com/protocol-buffers/docs/proto#options))
13+
+ ~~"full" version of all [Protocol Buffers], instead of the "lite" one used by default (see [Options > `optimize_for` > `LITE_RUNTIME`](https://developers.google.com/protocol-buffers/docs/proto#options))~~ _(temporarily disabled until fixed)_
1414
+ `.proto` files `package`/`import` directives fixed to reflect their relative locations (allows inspection through [the IDE](https://plugins.jetbrains.com/plugin/8277-protobuf-support))
1515

1616
## Download

__injected/override/build.gradle.kts

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ val projectEmpty: String by consts
5858
val projectReflect: String by consts
5959
val projectReflectApi: String by consts
6060
val projectBuildCommon: String by consts
61-
val projectDeserialization: String by consts
6261
val projectDescriptorsRuntime: String by consts
62+
val projectUtilRuntime: String by consts
63+
val projectMetadata: String by consts
64+
val projectMetadataJvm: String by consts
6365

6466
val srcCore = "$rootDir/core"
65-
val srcReflectApi = "$srcCore/reflection.jvm/src"
66-
val srcDescriptorsRuntime = "$srcCore/descriptors.runtime/src"
67+
val srcReflectionJvm = "$srcCore/reflection.jvm/src"
68+
val srcDescriptorsRuntime = project(projectDescriptorsRuntime).file("src").path!!
6769

68-
val srcDirDeserializationFull = buildDir.resolve("deserialization-protobufs-full")
70+
val srcSetsDir = buildDir.resolve("src-sets")
71+
72+
val taskWriteCompilerVersion: String by consts
6973

7074
val taskCopyAnnotations = "copyAnnotations"
7175
val taskReflectShadowJar = "reflectShadowJar"
@@ -105,7 +109,7 @@ val regexTrimProtoImport = Regex("" +
105109
"\\s+" + // - space
106110
"\"" + // - 'quotes' char (opens)
107111
")") + // - end group
108-
"core/deserialization/src/" + // text (to remove)
112+
"core/metadata/src/" + // text (to remove)
109113
("(?<after>" + // start group ('**.proto"; ')
110114
".+" + // - any text (proto path)
111115
"\\." + // - 'dot' char
@@ -135,9 +139,6 @@ val regexTrimDebugProtoClassName = Regex("" +
135139
//endregion
136140
//endregion
137141

138-
evaluationDependsOn(projectReflect) // for tasks
139-
evaluationDependsOn(projectDeserialization) // for srcSets
140-
141142
val sourceProtobuf by configurations.creating
142143
val sourceJavaxInject by configurations.creating
143144

@@ -146,34 +147,16 @@ dependencies {
146147
sourceJavaxInject(commonDep("javax.inject") + ":sources")
147148
}
148149

150+
evaluationDependsOn(projectUtilRuntime) // for tasks
151+
project(projectUtilRuntime).tasks["compileJava"].dependsOn(taskWriteCompilerVersion)
152+
153+
evaluationDependsOn(projectReflect) // for tasks
149154
val publishJars by tasks.creating {
150155
dependsOn("$projectReflect:$taskPublish")
151156
defaultTasks(this)
152157
}
153158

154-
// create a copy of [projectDeserialization] srcDirs, plus: extra protos, full versions of compiled protos, protobuf sources
155-
val copyDeserializationSrcSets by tasks.creating(Copy::class) {
156-
val mainSrcDirs = project(projectDeserialization)
157-
.the<JavaPluginConvention>()
158-
.sourceSets["main"]
159-
.java
160-
.srcDirs
161-
162-
val extraProtos = project(projectBuildCommon)
163-
.projectDir
164-
.resolve("src")
165-
.asFileTree { include("**.proto") }
166-
.files // flatten
167-
168-
val compiledProtosFull = project(projectBuildCommon)
169-
.projectDir
170-
.resolve("test")
171-
.asFileTree {
172-
include { it.name.matches(regexTrimDebugProtoFileName) }
173-
rename(regexTrimDebugProtoFileName.toPattern(), "$1")
174-
mapEachLine { it.replace(regexTrimDebugProtoClassName, "$1") }
175-
}
176-
159+
val srcDirMetadataOverride = project(projectMetadata).overrideSrcSets(srcSetsDir) {
177160
val pathProtoOriginal = packageProtoOriginal.packageToPath()
178161
val pathProtoJetbrains = packageProtoJetbrains.packageToPath()
179162
val sourcesProtobuf = sourceProtobuf.collect {
@@ -182,19 +165,17 @@ val copyDeserializationSrcSets by tasks.creating(Copy::class) {
182165
mapEachLine { it.replace(packageProtoOriginal, packageProtoJetbrains) }
183166
}
184167

185-
into(srcDirDeserializationFull)
186-
187-
from(mainSrcDirs)
188-
from(extraProtos)
189-
from(compiledProtosFull) { duplicatesStrategy = INCLUDE }
190168
from(sourcesProtobuf) { duplicatesStrategy = INCLUDE }
191169
}
192170

193-
// force the enhanced srcDir
194-
with(project(projectDeserialization)) {
195-
tasks["compileJava"]
196-
.dependsOn(copyDeserializationSrcSets)
197-
.doFirst { the<JavaPluginConvention>().sourceSets["main"].java.setSrcDirs(listOf(srcDirDeserializationFull)) }
171+
val srcDirMetadataJvmOverride = project(projectMetadataJvm).overrideSrcSets(srcSetsDir) {
172+
val extraProtos = project(projectBuildCommon)
173+
.projectDir
174+
.resolve("src")
175+
.asFileTree { include("**/java_descriptors.proto") }
176+
.files // flatten
177+
178+
from(extraProtos)
198179
}
199180

200181
with(project(projectReflect)) {
@@ -242,14 +223,19 @@ with(project(projectReflect)) {
242223
val packageJavaxInjectLib = packageJavaxInjectJetbrains.replaceFirst(packageJetbrains, packageLib)
243224
val pathJavaxOriginal = packageJavaxInjectOriginal.packageToPath()
244225
val pathJavaxInjectLib = packageJavaxInjectLib.packageToPath()
245-
val sourcesJavaxInject = sourceJavaxInject.collect {
246-
exclude("META-INF/**")
226+
val sourcesJavaxInject = copySpec {
227+
from(sourceJavaxInject.collect { exclude("META-INF/**") })
247228
eachFile { path = path.replace(pathJavaxOriginal, pathJavaxInjectLib) }
248229
mapEachLine { it.replace(packageJavaxInjectOriginal, packageJavaxInjectLib) }
249230
}
250231

251-
from(sourcesJavaxInject)
252-
from(srcDirDeserializationFull) { duplicatesStrategy = INCLUDE }
232+
with(sourcesJavaxInject)
233+
234+
dependsOn(srcDirMetadataOverride)
235+
dependsOn(srcDirMetadataJvmOverride)
236+
237+
from(srcDirMetadataOverride) { duplicatesStrategy = INCLUDE }
238+
from(srcDirMetadataJvmOverride) { duplicatesStrategy = INCLUDE }
253239

254240
// relocate package paths
255241
eachFile { path = path.replace(pathReflectImpl, pathLib) }
@@ -269,7 +255,7 @@ with(project(projectReflect)) {
269255
val sourcesJar = (tasks[taskSourcesJar] as Jar).apply {
270256
// exclude unneeded dependencies
271257
includeEmptyDirs = false
272-
excludeDir(srcReflectApi)
258+
excludeDir(srcReflectionJvm)
273259
excludeDir(srcDescriptorsRuntime)
274260
}
275261

@@ -328,6 +314,38 @@ with(project(projectReflect)) {
328314
}
329315

330316
//region utils
317+
fun Project.pathParts(): List<String> =
318+
ArrayList<String>(depth + 1).apply {
319+
var project = project
320+
while (true) {
321+
add(0, project.name)
322+
project = project.parent ?: break
323+
}
324+
}
325+
326+
fun Project.overrideSrcSets(topDir: File, configure: Copy.() -> Unit): Copy {
327+
evaluationDependsOn(path)
328+
329+
val srcDir = pathParts().fold(topDir) { dir, pathPart -> dir.resolve(pathPart) }
330+
331+
val copySrcSetsTask = createTask("__copySrcSets", Copy::class) {
332+
from(mainSrcSet.java.srcDirs)
333+
into(srcDir)
334+
includeEmptyDirs = false
335+
configure()
336+
}
337+
338+
// force the enhanced srcDir
339+
tasks["compileJava"]
340+
.dependsOn(copySrcSetsTask)
341+
.doFirst { mainSrcSet.java.setSrcDirs(listOf(srcDir)) }
342+
343+
return copySrcSetsTask
344+
}
345+
346+
val Project.mainSrcSet: SourceSet
347+
get() = the<JavaPluginConvention>().sourceSets["main"]
348+
331349
fun File.asFileTree(configure: ConfigurableFileTree.() -> Unit = {}) = fileTree(this, configure)
332350

333351
fun ContentFilterable.mapEachLine(transform: (String) -> String) = filter(transform)

consts.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ val consts: Properties by extra(object : Properties() {
6363
val projectBuildCommon by ":kotlin-build-common"
6464
val projectDeserialization by ":core:deserialization"
6565
val projectDescriptorsRuntime by ":core:descriptors.runtime"
66+
val projectUtilRuntime by ":core:util.runtime"
67+
val projectMetadata by ":core:metadata"
68+
val projectMetadataJvm by ":core:metadata.jvm"
69+
70+
val taskWriteCompilerVersion by ":prepare:build.version:writeCompilerVersion"
6671

6772
operator fun <T> T.provideDelegate(thisRef: Properties, property: KProperty<*>) =
6873
object : ReadOnlyProperty<Properties, T> {

kotlin.init.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ gradle.settingsEvaluated {
3434

3535
project(projectNames.first()).afterEvaluate {
3636
this@rootProject.defaultTasks = defaultTasks
37-
log("set default tasks on root project from project '$path': $defaultTasks")
37+
log("set default tasks on root project from project '$path': ${this@rootProject.defaultTasks}")
3838
}
3939
}
4040
}

0 commit comments

Comments
 (0)