Merge #530 by keith: Delete unused variables and arguments

Closes #530

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_android/pull/530 from keith:ks/delete-unused-variables-and-arguments c09781cea85ad02dbb29cda64ecfb840a1834fd3
PiperOrigin-RevId: 944063530
Change-Id: I5ebf8c7bd5d1dfb142a202d761f4a7c0217ef877
diff --git a/mobile_install/apks.bzl b/mobile_install/apks.bzl
index 63c6c15..56fbeeb 100644
--- a/mobile_install/apks.bzl
+++ b/mobile_install/apks.bzl
@@ -115,7 +115,7 @@
     to_pack = dexes + [r_dex]
     if native_zips:
         to_pack.extend(native_zips)
-    for i, artifact in enumerate(to_pack):
+    for artifact in to_pack:
         # the split attr in the manifest will be used to name the file on the device like
         # split_${SPLIT_ID}.apk. We need to follow the same pattern so that we can compare
         # files during sync time and only do the incremental install.
diff --git a/rules/aar_import/impl.bzl b/rules/aar_import/impl.bzl
index 3d491d9..11393b2 100644
--- a/rules/aar_import/impl.bzl
+++ b/rules/aar_import/impl.bzl
@@ -51,10 +51,6 @@
 ANDROID_MANIFEST = "AndroidManifest.xml"
 LINT_JAR = "lint.jar"
 
-# Resources context dict fields.
-_PROVIDERS = "providers"
-_VALIDATION_RESULTS = "validation_results"
-
 def _create_aar_tree_artifact(ctx, name):
     return ctx.actions.declare_directory("%s/unzipped/%s/%s" % (RULE_PREFIX, name, ctx.label.name))
 
@@ -138,9 +134,7 @@
         aar,
         package,
         manifest,
-        deps,
-        aar_resources_extractor_tool,
-        unzip_tool):
+        aar_resources_extractor_tool):
     # Extract resources and assets, if they exist.
     resources = _create_aar_tree_artifact(ctx, "resources")
     assets = _create_aar_tree_artifact(ctx, "assets")
@@ -492,10 +486,8 @@
         aar = aar,
         package = package,
         manifest = manifest_ctx.processed_manifest,
-        deps = ctx.attr.deps,
         aar_resources_extractor_tool =
             _get_android_toolchain(ctx).aar_resources_extractor.files_to_run,
-        unzip_tool = unzip_tool,
     )
     providers.extend(resources_ctx.providers)
 
diff --git a/rules/android_application/android_application_rule.bzl b/rules/android_application/android_application_rule.bzl
index deefd3f..97c0b4e 100644
--- a/rules/android_application/android_application_rule.bzl
+++ b/rules/android_application/android_application_rule.bzl
@@ -88,8 +88,6 @@
         get_android_sdk(ctx).aapt2,
         ctx.executable._feature_manifest_script,
         ctx.executable._priority_feature_manifest_script,
-        get_android_toolchain(ctx).android_resources_busybox,
-        _common.get_host_javabase(ctx),
     )
 
     # Remove all dexes from the feature module apk. jvm / resources are not
@@ -179,9 +177,7 @@
         feature_target,
         aapt2,
         feature_manifest_script,
-        priority_feature_manifest_script,
-        android_resources_busybox,
-        host_javabase):
+        priority_feature_manifest_script):
     info = feature_target[AndroidFeatureModuleInfo]
     manifest = ctx.actions.declare_file(ctx.label.name + "/" + feature_target.label.name + "/AndroidManifest.xml")
 
diff --git a/rules/android_binary/impl.bzl b/rules/android_binary/impl.bzl
index ad4d80e..5461f17 100644
--- a/rules/android_binary/impl.bzl
+++ b/rules/android_binary/impl.bzl
@@ -259,7 +259,7 @@
         ),
     )
 
-def _process_dex(ctx, validation_ctx, packaged_resources_ctx, manifest_ctx, deploy_ctx, bp_ctx, optimize_ctx, **_unused_ctxs):
+def _process_dex(ctx, validation_ctx, packaged_resources_ctx, manifest_ctx, deploy_ctx, optimize_ctx, **_unused_ctxs):
     if validation_ctx.use_r8:
         return ProviderInfo(
             name = "dex_ctx",
@@ -421,7 +421,7 @@
         ),
     )
 
-def _process_deploy_jar(ctx, validation_ctx, stamp_ctx, manifest_ctx, packaged_resources_ctx, jvm_ctx, build_info_ctx, proto_ctx, **_unused_ctxs):
+def _process_deploy_jar(ctx, validation_ctx, stamp_ctx, manifest_ctx, jvm_ctx, build_info_ctx, **_unused_ctxs):
     if validation_ctx.use_r8:
         return ProviderInfo(
             name = "deploy_ctx",
@@ -608,17 +608,6 @@
         transitive_resource_jars += dep.jars.to_list()
     return transitive_resource_jars
 
-def _is_test_binary(ctx):
-    """Whether this android_binary target is a test binary.
-
-    Args:
-      ctx: The context.
-
-    Returns:
-      Boolean indicating whether the target is a test target.
-    """
-    return ctx.attr.testonly or is_instrumentation(ctx) or str(ctx.label).find("/javatests/") >= 0
-
 def is_instrumentation(ctx):
     """Whether this android_binary target is an instrumentation binary.
 
diff --git a/rules/android_binary/rule.bzl b/rules/android_binary/rule.bzl
index 91ae065..3517d67 100644
--- a/rules/android_binary/rule.bzl
+++ b/rules/android_binary/rule.bzl
@@ -27,8 +27,6 @@
 
 visibility(PROJECT_VISIBILITY)
 
-_DEFAULT_ALLOWED_ATTRS = ["name", "visibility", "tags", "testonly", "transitive_configs", "$enable_manifest_merging", "features", "exec_properties"]
-
 _DEFAULT_PROVIDES = [ApkInfo, JavaInfo]
 
 def _outputs(name, proguard_generate_mapping, _package_name, _generate_proguard_outputs, _generate_art_profile_outputs):
@@ -126,7 +124,6 @@
 
     # Required for ACLs check in _outputs(), since the callback can't access the native module.
     attrs["$package_name"] = native.package_name()
-    target_fqn = "//%s:%s" % (native.package_name(), attrs["name"])
 
     if type(attrs.get("proguard_specs", None)) == "select" or attrs.get("proguard_specs", None):
         attrs["$generate_proguard_outputs"] = True
diff --git a/rules/android_library/impl.bzl b/rules/android_library/impl.bzl
index 6a3c740..4e00bb8 100644
--- a/rules/android_library/impl.bzl
+++ b/rules/android_library/impl.bzl
@@ -318,7 +318,7 @@
         ),
     )
 
-def _process_aar(ctx, java_package, resources_ctx, proguard_ctx, **unused_ctx):
+def _process_aar(ctx, resources_ctx, proguard_ctx, **unused_ctx):
     aar_ctx = {
         _PROVIDERS: [],
         _VALIDATION_OUTPUTS: [],
@@ -460,7 +460,6 @@
 def finalize(
         ctx,
         resources_ctx,
-        intellij_ctx,
         jvm_ctx,
         proguard_ctx,
         providers,
diff --git a/rules/data_binding.bzl b/rules/data_binding.bzl
index 9039cba..4460cdd 100644
--- a/rules/data_binding.bzl
+++ b/rules/data_binding.bzl
@@ -132,7 +132,6 @@
     return dep_lib_artifacts
 
 def _get_javac_opts(
-        ctx,
         java_package,
         artifact_type,
         dependency_artifacts_dir,
@@ -284,7 +283,6 @@
     )
 
     db_info[_JAVAC_OPTS] = _get_javac_opts(
-        ctx,
         java_package,
         artifact_type,
         (
diff --git a/rules/dex_desugar_aspect.bzl b/rules/dex_desugar_aspect.bzl
index a54a1bb..32a73f4 100644
--- a/rules/dex_desugar_aspect.bzl
+++ b/rules/dex_desugar_aspect.bzl
@@ -120,7 +120,7 @@
 
     if runtime_jars:
         basename_clash = _check_basename_clash(runtime_jars)
-        aspect_dexopts = _get_aspect_dexopts(ctx)
+        aspect_dexopts = _get_aspect_dexopts()
         for jar in runtime_jars:
             if ctx.fragments.android.desugar_java8:
                 jar_to_desugar = jar
@@ -214,7 +214,7 @@
         return ctx.rule.attr._aidl_lib[JavaInfo].runtime_output_jars
     return []
 
-def _get_aspect_dexopts(ctx):
+def _get_aspect_dexopts():
     return _power_set(_dex.normalize_dexopts(_dex.DEXOPTS_SUPPORTED_IN_INCREMENTAL_DEXING))
 
 def _get_boot_classpath(target, ctx):
diff --git a/rules/min_sdk_version.bzl b/rules/min_sdk_version.bzl
index 2f3985b..7aafb37 100644
--- a/rules/min_sdk_version.bzl
+++ b/rules/min_sdk_version.bzl
@@ -26,7 +26,7 @@
 _SETTING = "//rules/flags:min_sdk_version"
 _DEPOT_FLOOR = 23
 _DEX_DESUGAR = 23  # Kept at 23 due to b/331852939. See some related discussion at b/319114605
-_MIN_SDK_LEVELS = sorted([_DEPOT_FLOOR, 24])
+# _MIN_SDK_LEVELS = sorted([_DEPOT_FLOOR, 24])
 
 _ATTRS = dict(
     _min_sdk_version = attr.label(
@@ -35,7 +35,7 @@
     ),
 )
 
-def _clamp(min_sdk_version):
+def _clamp(min_sdk_version):  # @unused
     # TODO(asinclair): Uncomment this once android_binary is Starlarkified and the order of the
     # Android Platforms Transition and Feature Flags transition is swapped.
     # clamped = _MIN_SDK_LEVELS[0]
@@ -46,7 +46,7 @@
     # return clamped
     return 0
 
-def _get(ctx):
+def _get(ctx):  # @unused
     # This is the case when an android_binary target does not set a value explicitly.
     # The configuration value defaults to 0
     # So in this case we use the depot floor.
diff --git a/rules/native_deps.bzl b/rules/native_deps.bzl
index a6f561c..d7fe33f 100644
--- a/rules/native_deps.bzl
+++ b/rules/native_deps.bzl
@@ -35,7 +35,6 @@
 )
 
 def _split_config_aspect_impl(__, ctx):
-    android_cfg = ctx.fragments.android
     return SplitConfigInfo(
         build_config = ctx.configuration,
         target_platform = ctx.fragments.platform.platform,
diff --git a/rules/resources.bzl b/rules/resources.bzl
index 01adcfb..98d824b 100644
--- a/rules/resources.bzl
+++ b/rules/resources.bzl
@@ -52,11 +52,6 @@
     "assets, or exports_manifest are specified."
 )
 
-_ASSET_DEFINITION_ERROR = (
-    "In target %s, the assets and assets_dir attributes should be either " +
-    "both empty or non-empty."
-)
-
 _INCORRECT_RESOURCE_LAYOUT_ERROR = (
     "'%s' is not in the expected resource directory structure of " +
     "<resource directory>/{%s}/<file>" % (",").join(_RESOURCE_FOLDER_TYPES)
@@ -886,43 +881,6 @@
         toolchain = None,
     )
 
-def _fastr(ctx, r_pbs, package, manifest, android_kit):
-    """Create R.srcjar from the given R.pb files in the transitive closure.
-
-    Args:
-      ctx: The context.
-      r_pbs: Transitive  set of resource pbs.
-      package: The package name of the compile-time R.java.
-      manifest: File. The AndroidManifest.xml file.
-      android_kit: FilesToRunProvider. The Android Kit executable or
-        FilesToRunProvider.
-
-    Returns:
-      The output R source jar artifact.
-    """
-    inputs = r_pbs
-    r_srcjar = ctx.actions.declare_file(ctx.label.name + "/resources/R-fastr.srcjar")
-    args = ctx.actions.args()
-    args.use_param_file(param_file_arg = "--flagfile=%s", use_always = True)
-    args.set_param_file_format("multiline")
-    args.add("-rJavaOutput", r_srcjar)
-    if package:
-        args.add("-packageForR", package)
-    else:
-        args.add("-manifest", manifest)
-        inputs = depset([manifest], transitive = [inputs])
-    args.add_joined("-resourcePbs", r_pbs, join_with = ",")
-
-    ctx.actions.run(
-        executable = android_kit,
-        arguments = ["rstub", args],
-        inputs = inputs,
-        outputs = [r_srcjar],
-        mnemonic = "CompileTimeR",
-        progress_message = "Generating compile-time R %s" % r_srcjar.short_path,
-    )
-    return r_srcjar
-
 def _compile(
         ctx,
         out_compiled_resources = None,
@@ -1007,14 +965,6 @@
     )
     return aar
 
-def _validate(ctx, manifest, defined_assets, defined_assets_dir):
-    if ((defined_assets and not defined_assets_dir) or
-        (not defined_assets and defined_assets_dir)):
-        _log.error(_ASSET_DEFINITION_ERROR % ctx.label)
-
-    if not manifest:
-        _log.error(_MANIFEST_MISSING_ERROR % ctx.label)
-
 def _validate_resources(resource_files = None):
     for resource_file in resource_files:
         path_segments = resource_file.path.split("/")
diff --git a/test/rules/resources/test.bzl b/test/rules/resources/test.bzl
index 6fdec01..b4413b0 100644
--- a/test/rules/resources/test.bzl
+++ b/test/rules/resources/test.bzl
@@ -543,7 +543,6 @@
 
 def _package_resources_final_id_test(ctx):
     env = analysistest.begin(ctx)
-    target_under_test = analysistest.target_under_test(env)
     actions = analysistest.target_actions(env)
     found_final_r = False
     found_nonfinal_r = False
diff --git a/test/utils/asserts.bzl b/test/utils/asserts.bzl
index bdbd284..c0f93a5 100644
--- a/test/utils/asserts.bzl
+++ b/test/utils/asserts.bzl
@@ -146,18 +146,6 @@
         )
     return name
 
-def _build_expected_resources_node_info(string):
-    parts = string.split(":")
-    if len(parts) != 5:
-        fail("Error: malformed resources_node_info string: %s" % string)
-    return dict(
-        label = parts[0],
-        assets = parts[1].split(",") if parts[1] else [],
-        assets_dir = parts[2],
-        assets_symbols = parts[3],
-        compiled_resources = parts[4],
-    )
-
 def _expected_android_binary_native_libs_info_impl(ctx):
     return _ExpectedAndroidBinaryNativeInfo(
         transitive_native_libs_by_cpu_architecture = ctx.attr.transitive_native_libs_by_cpu_architecture,