square / wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
https://square.github.io/wire/
Apache License 2.0
4.24k stars 570 forks source link

Remove generated sources when corresponding .proto is deleted #1954

Closed mathjeff closed 3 years ago

mathjeff commented 3 years ago

AndroidX is observing some build failures involving generated .kt files remaining in the build directory after the corresponding .proto files get deleted.

Is it possible for these .kt files to be deleted automatically during the build?

In particular:

  1. We created a proto file at https://android-review.googlesource.com/c/platform/frameworks/support/+/1684172/8/benchmark/macro/src/main/proto/test.proto
  2. A build was run and a .kt file was generated atout/androidx/benchmark/benchmark-macro/build/generated/source/wire/androidx/benchmark/macro/protos/TestProto.kt:30
  3. The generated .kt file contained some problems that would be caught by a static checking tool (Metalava) except that this was suppressed via an annotation in the package-info.java ( https://android-review.googlesource.com/c/platform/frameworks/support/+/1684172/8/benchmark/macro/src/main/java/androidx/benchmark/macro/protos/package-info.java#22 )
  4. A later change deletes the .proto file ( https://android-review.googlesource.com/c/platform/frameworks/support/+/1680545/6/benchmark/macro/src/main/proto/test.proto ) and moves the package-info.java to another dir ( https://android-review.googlesource.com/c/platform/frameworks/support/+/1680545/6/benchmark/macro/src/main/java/perfetto/protos/package-info.java )
  5. The subsequent Gradle build does not delete the leftover .kt files in the build directory, failing with:
Detected these failing tasks: [':benchmark:benchmark-macro:generateApi']
> Task :benchmark:benchmark-macro:generateApi

../../../../out/androidx/benchmark/benchmark-macro/build/generated/source/wire/androidx/benchmark/macro/protos/TestProto.kt:30: error: Must avoid boxed primitives (`java.lang.Long`) [AutoBoxing]
../../../../out/androidx/benchmark/benchmark-macro/build/generated/source/wire/androidx/benchmark/macro/protos/TestProto.kt:67: error: Must avoid boxed primitives (`java.lang.Long`) [AutoBoxing]
../../../../out/androidx/benchmark/benchmark-macro/build/generated/source/wire/androidx/benchmark/macro/protos/TestProto.kt:67: error: A Kotlin method with default parameter values should be annotated with @JvmOverloads for better Java interoperability; see https://android.github.io/kotlin-guides/interop.html#function-overloads-for-defaults [MissingJvmstatic]
../../../../out/androidx/benchmark/benchmark-macro/build/generated/source/wire/androidx/benchmark/macro/protos/TestProto.kt:30: error: Must avoid boxed primitives (`java.lang.Long`) [AutoBoxing]
> Task :benchmark:benchmark-macro:generateApi

    Your change has API lint issues. Fix the code according to the messages above.

    If a check is broken, suppress it in code in Kotlin with @Suppress("id")/@get:Suppress("id")
    and in Java with @SuppressWarnings("id") and file bug to
    https://issuetracker.google.com/issues/new?component=739152&template=1344623

    If you are doing a refactoring or suppression above does not work, use ./gradlew updateApiLintBaseline

Could the generated sources be removed when the corresponding .proto files are removed?

Thanks!

oldergod commented 3 years ago

Thank you. This is fixed on master via https://github.com/square/wire/pull/1932 and will be part of the next release.

mathjeff commented 3 years ago

Thanks!