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.

This fixes google#2040
  • Loading branch information
ansman committed Feb 11, 2021
1 parent 732323b commit 3e4a539
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 18 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,14 +38,14 @@ 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",
"//java/dagger/hilt/android/processor/internal/customtestapplication:processor_lib",
"//java/dagger/hilt/android/processor/internal/viewmodel:validation_plugin_lib",
"//java/dagger/hilt/android/processor/internal/uninstallmodules:processor_lib",
"//java/dagger/hilt/android/processor/internal/viewmodel:processor_lib",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:component_descriptor",
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,9 +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:compiler_options",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:processors",
"//java/dagger/internal/guava:collect",
Expand Down Expand Up @@ -81,7 +81,7 @@ java_library(
"AndroidEntryPointMetadata.java",
],
deps = [
":compiler_options",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/android/processor/internal:android_classnames",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:components",
Expand All @@ -98,11 +98,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,14 +58,14 @@ 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",
"//java/dagger/hilt/android/processor/internal/customtestapplication:processor_lib",
"//java/dagger/hilt/android/processor/internal/viewmodel:validation_plugin_lib",
"//java/dagger/hilt/android/processor/internal/uninstallmodules:processor_lib",
"//java/dagger/hilt/android/processor/internal/viewmodel:processor_lib",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:component_descriptor",
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 @@ -26,6 +26,7 @@ java_library(
deps = [
":processor_errors",
":processors",
":compiler_options",
"//java/dagger/internal/guava:base",
"//java/dagger/internal/guava:collect",
"@google_bazel_common//third_party/java/auto:value",
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
8 changes: 8 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,14 @@ 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
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 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,7 +44,7 @@ java_library(
],
deps = [
"//:dagger_with_compiler",
"//java/dagger/hilt/android/processor/internal/androidentrypoint:compiler_options",
"//java/dagger/hilt/processor/internal:compiler_options",
"//java/dagger/hilt/processor/internal:base_processor",
"//java/dagger/hilt/processor/internal:classnames",
"//java/dagger/hilt/processor/internal:components",
Expand Down

0 comments on commit 3e4a539

Please sign in to comment.