From e301825a6bf4eb4f9eaa3f9f1c8faf849184499a Mon Sep 17 00:00:00 2001 From: dimdim11 Date: Thu, 21 Nov 2024 20:12:46 +0300 Subject: [PATCH] Fix proto with proto-libraries, refactor errorprone Refactor errorprone Fix building protos in Gradle commit_hash:54d1cdf9df00e7ab30b991ddf1f534ab5992ef3c --- .../ide-gradle/build.gradle.kts.jinja | 41 +++++++---------- .../ide-gradle/build.gradle.kts.proto.jinja | 46 ++++++++++++++++++- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/build/export_generators/ide-gradle/build.gradle.kts.jinja b/build/export_generators/ide-gradle/build.gradle.kts.jinja index 46bcd4cef..798922b5b 100644 --- a/build/export_generators/ide-gradle/build.gradle.kts.jinja +++ b/build/export_generators/ide-gradle/build.gradle.kts.jinja @@ -38,21 +38,6 @@ subprojects { {%- endif %} plugins { -{#- some plugins configuration -#} -{%- for library in target.consumer if library.classpath -%} -{#- error prone plugin configuration -#} -{%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations/" in library.jar -%} - - id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}" - -{%- endif -%} -{%- endfor -%} - -{#- lombok configuration -#} -{#- TODO remove usings annotation_processors semantic -#} -{%- if ("lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors) or (target.use_annotation_processor|length and target.use_annotation_processor|select('startsWith', 'contrib/java/org/projectlombok/lombok')|length) %} - id("io.freefair.lombok") version "8.6" -{%- endif -%} {%- if mainClass %} `application` {%- else %} @@ -76,6 +61,17 @@ plugins { {%- if target.with_kotlinc_plugin_serialization|length %} kotlin("plugin.serialization") version "{{ kotlin_version }}" {% endif -%} +{%- endif -%} + +{#- errorprone plugin configuration -#} +{%- if target.consumer|selectattr('jar', 'startsWith', 'contrib/java/com/google/errorprone/error_prone_annotations')|length %} + id("net.ltgt.errorprone") version "{{ errorprone_plugin_version }}" +{%- endif -%} + +{#- lombok plugin configuration -#} +{#- TODO remove usings annotation_processors semantic -#} +{%- if ("lombok.launch.AnnotationProcessorHider$AnnotationProcessor" in target.annotation_processors) or (target.use_annotation_processor|length and target.use_annotation_processor|select('startsWith', 'contrib/java/org/projectlombok/lombok')|length) %} + id("io.freefair.lombok") version "8.6" {%- endif %} } @@ -272,6 +268,7 @@ sourceSets.main.java.srcDirs += "{{ srcdir_glob[0] }}" {%- endfor -%} sourceSets { +{%- if target.runs|length %} main { {#- Default by Gradle: @@ -280,13 +277,11 @@ sourceSets { resources.srcDir("src/main/resources") #} -{%- if target.runs|length -%} {%- for run in target.runs -%} {{ OutDirs(run, ' java.srcDir("', '")') }} -{%- endfor -%} -{%- endif %} +{%- endfor %} } - +{%- endif %} test { {#- Default by Gradle: @@ -315,11 +310,9 @@ sourceSets { dependencies { {%- for library in target.consumer if library.classpath -%} -{# error prone plugin configuration #} -{%- if library.prebuilt and library.jar and (library.type != "contrib" or build_contribs) and "contrib/java/com/google/errorprone/error_prone_annotations" in library.jar -%} -{% set errorprone_version = library.jar -%} -{% set errorprone_parts = errorprone_version|replace("contrib/java/com/google/errorprone/error_prone_annotations/") -%} -{% set errorprone_parts = split(errorprone_parts, '/') %} +{%- if library.prebuilt and (library.type != "contrib" or build_contribs) and ("contrib/java/com/google/errorprone/error_prone_annotations" in library.jar) -%} +{%- set errorprone_version = library.jar|replace("contrib/java/com/google/errorprone/error_prone_annotations/", "") -%} +{%- set errorprone_parts = split(errorprone_version, '/', 2) %} errorprone("com.google.errorprone:error_prone_core:{{ errorprone_parts[0] }}") {%- endif -%} diff --git a/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja b/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja index bb6de76ad..fe989ed98 100644 --- a/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja +++ b/build/export_generators/ide-gradle/build.gradle.kts.proto.jinja @@ -1,4 +1,6 @@ {%- set publish = target.publish -%} +{%- set libraries = target.consumer|selectattr('type', 'eq', 'library') -%} + import com.google.protobuf.gradle.* val baseBuildDir = "{{ export_root }}/gradle.build/" @@ -7,6 +9,11 @@ subprojects { buildDir = file(baseBuildDir + project.path.replaceFirst(":", "/").replace(":", ".")) } +val mainProtosDir = File(buildDir, "main_protos") +{%- if libraries|length %} +val mainExtractedIncludeProtosDir = File(buildDir, "extracted-include-protos/main") +{%- endif %} + plugins { id("java-library") id("com.google.protobuf") version "0.8.19" @@ -99,8 +106,13 @@ dependencies { } {%- endif -%} {%- endif -%} -{%- endfor %} - protobuf(files("$projectDir")) +{%- endfor -%} + +{%- if target.proto_namespace %} + protobuf(files(File(mainProtosDir, "{{ target.proto_namespace }}"))) +{%- else %} + protobuf(files(mainProtosDir)) +{%- endif %} } protobuf { @@ -141,6 +153,36 @@ protobuf { {%- endif %} } +val prepareMainProtos = tasks.register("prepareMainProtos") { + from("$project_root") { +{#- list of all current project proto files -#} +{%- for proto in target.proto_files %} + include("{{ proto }}") +{%- endfor %} + } + into(mainProtosDir) +} + +{% if libraries|length -%} +val extractMainLibrariesProtos = tasks.register("extractMainLibrariesProtos") { + from("$project_root") { +{#- list of all library directories -#} +{%- for library in libraries -%} +{%- set path_and_jar = rsplit(library.jar, '/', 2) %} + include("{{ path_and_jar[0] }}/**/*.proto") +{%- endfor %} + } + into(mainExtractedIncludeProtosDir) +} + +{% endif -%} +afterEvaluate { + tasks.getByName("extractProto").dependsOn(prepareMainProtos) +{%- if libraries|length %} + tasks.getByName("extractProto").dependsOn(extractMainLibrariesProtos) +{%- endif %} +} + {# To avoid problems when build project with proto #} tasks.getByName("sourcesJar").dependsOn("generateProto")