Skip to content

Commit

Permalink
Prevent KAPT from logging errors when compiling modules without entry…
Browse files Browse the repository at this point in the history
… points.

When Hilt Android is run on a module that contains no entry points, KAPT will log an error about `disableAndroidSuperclassValidation` not being a support option. This is because the Hilt Gradle plugin will add this option when applied but if no entry points exists, no processor actually accepts that option.

With this fix, all Hilt processors accept these options (though they are unused). This will prevent KAPT from logging these warnings in most cases.

It is still possible for warnings to be logged, for example if the Hilt plugin is applied, but Hilt isn't used but for those cases the user can simply skip applying the plugin.

Fixes #2040
Closes #2372

RELNOTES="Reduce the possibility of KAPT logging warnings due to no processor supporting `disableAndroidSuperclassValidation` when no Android entry points are in the source module."
PiperOrigin-RevId: 360836064
  • Loading branch information
ansman authored and Dagger Team committed Mar 4, 2021
1 parent 39894d2 commit c70cf2d
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion java/dagger/hilt/android/processor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ gen_maven_artifact(
"//java/dagger/hilt/android/processor/internal:android_classnames",
"//java/dagger/hilt/android/processor/internal:utils",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:android_generators",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:compiler_options",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:metadata",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:processor_lib",
"//java/dagger/hilt/android/processor/internal/bindvalue:bind_value_processor_lib",
Expand All @@ -48,6 +47,7 @@ gen_maven_artifact(
"//java/dagger/hilt/android/processor/internal/viewmodel:processor_lib",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:component_descriptor",
"//java/dagger/hilt/processor/internal:component_names",
"//java/dagger/hilt/processor/internal:components",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package dagger.hilt.android.processor.internal.androidentrypoint;

import static dagger.hilt.android.processor.internal.androidentrypoint.HiltCompilerOptions.BooleanOption.DISABLE_ANDROID_SUPERCLASS_VALIDATION;
import static dagger.hilt.processor.internal.HiltCompilerOptions.BooleanOption.DISABLE_ANDROID_SUPERCLASS_VALIDATION;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;

import com.google.auto.common.MoreElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public Set<String> getSupportedAnnotationTypes() {
AndroidClassNames.HILT_ANDROID_APP.toString());
}

@Override
public Set<String> getSupportedOptions() {
return HiltCompilerOptions.getProcessorOptions();
}

@Override
public boolean delayErrors() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ java_library(
srcs = ["AndroidEntryPointProcessor.java"],
deps = [
":android_generators",
":compiler_options",
":metadata",
"//java/dagger/hilt/android/processor/internal:android_classnames",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:processors",
"//java/dagger/internal/guava:collect",
"@google_bazel_common//third_party/java/auto:service",
"@google_bazel_common//third_party/java/incap",
Expand Down Expand Up @@ -81,9 +79,9 @@ java_library(
"AndroidEntryPointMetadata.java",
],
deps = [
":compiler_options",
"//java/dagger/hilt/android/processor/internal:android_classnames",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:components",
"//java/dagger/hilt/processor/internal:kotlin",
"//java/dagger/hilt/processor/internal:processor_errors",
Expand All @@ -98,11 +96,6 @@ java_library(
],
)

java_library(
name = "compiler_options",
srcs = ["HiltCompilerOptions.java"],
)

filegroup(
name = "srcs_filegroup",
srcs = glob(["*"]),
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/hilt/processor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ gen_maven_artifact(
"//java/dagger/hilt/android/processor/internal:android_classnames",
"//java/dagger/hilt/android/processor/internal:utils",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:android_generators",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:compiler_options",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:metadata",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:processor_lib",
"//java/dagger/hilt/android/processor/internal/bindvalue:bind_value_processor_lib",
Expand All @@ -68,6 +67,7 @@ gen_maven_artifact(
"//java/dagger/hilt/android/processor/internal/viewmodel:processor_lib",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:component_descriptor",
"//java/dagger/hilt/processor/internal:component_names",
"//java/dagger/hilt/processor/internal:components",
Expand Down
6 changes: 6 additions & 0 deletions java/dagger/hilt/processor/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ java_library(
"ProcessorErrorHandler.java",
],
deps = [
":compiler_options",
":processor_errors",
":processors",
"//java/dagger/internal/guava:base",
Expand Down Expand Up @@ -134,6 +135,11 @@ java_library(
],
)

java_library(
name = "compiler_options",
srcs = ["HiltCompilerOptions.java"],
)

filegroup(
name = "srcs_filegroup",
srcs = glob(["*"]),
Expand Down
9 changes: 9 additions & 0 deletions java/dagger/hilt/processor/internal/BaseProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ TypeElement element(Elements elements) {
private Messager messager;
private ProcessorErrorHandler errorHandler;

@Override
public final Set<String> getSupportedOptions() {
// This is declared here rather than in the actual processors because KAPT will issue a
// warning if any used option is not unsupported. This can happen when there is a module
// which uses Hilt but lacks any @AndroidEntryPoint annotations.
// See: https://github.com/google/dagger/issues/2040
return HiltCompilerOptions.getProcessorOptions();
}

/** Used to perform initialization before each round of processing. */
protected void preRoundProcess(RoundEnvironment roundEnv) {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package dagger.hilt.android.processor.internal.androidentrypoint;
package dagger.hilt.processor.internal;

import java.util.Arrays;
import java.util.Set;
Expand All @@ -23,7 +23,6 @@

/** Hilt annotation processor options. */
// TODO(danysantiago): Consider consolidating with Dagger compiler options logic.
// TODO(user): Move this class to dagger/hilt/processor/internal
public final class HiltCompilerOptions {

/** Processor options which can have true or false values. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static com.google.auto.common.MoreElements.asType;
import static com.google.auto.common.MoreElements.getPackage;
import static com.google.common.collect.Iterables.getOnlyElement;
import static dagger.hilt.android.processor.internal.androidentrypoint.HiltCompilerOptions.BooleanOption.DISABLE_MODULES_HAVE_INSTALL_IN_CHECK;
import static dagger.hilt.processor.internal.HiltCompilerOptions.BooleanOption.DISABLE_MODULES_HAVE_INSTALL_IN_CHECK;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableList;
import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet;
import static javax.lang.model.element.ElementKind.CLASS;
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/hilt/processor/internal/aggregateddeps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ java_library(
],
deps = [
"//:dagger_with_compiler",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:compiler_options",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:components",
"//java/dagger/hilt/processor/internal:kotlin",
"//java/dagger/hilt/processor/internal:processor_errors",
Expand Down

0 comments on commit c70cf2d

Please sign in to comment.