Skip to content

Commit c5e0f61

Browse files
committed
Pass merged manifest to Android Lint
1 parent 012f2b1 commit c5e0f61

14 files changed

+120
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ bazel-*
22
.bazelrc.user
33
.idea/
44
.ijwb/
5+
.aswb/

examples/simple-android/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44

55
<uses-sdk android:minSdkVersion="23"/>
66

7+
<application>
8+
<activity
9+
android:name=".TestActivity"
10+
android:exported="true" />
11+
</application>
12+
713
</manifest>

examples/simple-android/BUILD.bazel

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,53 @@
1-
load("@rules_android//android:rules.bzl", "android_library")
1+
load("@rules_android//android:rules.bzl", "android_binary", "android_library")
22
load("@rules_android_lint//rules:defs.bzl", "android_lint", "android_lint_test")
33
load("@rules_android_lint//toolchains:toolchain.bzl", "android_lint_toolchain")
44

55
android_library(
66
name = "lib",
7+
srcs = ["TestActivity.java"],
8+
custom_package = "com.rules.android.lint.examples",
9+
manifest = "LibManifest.xml",
10+
)
11+
12+
android_binary(
13+
name = "bin",
714
srcs = ["Foo.java"],
815
custom_package = "com.rules.android.lint.examples",
16+
manifest = "AndroidManifest.xml",
17+
deps = [
18+
":lib",
19+
],
920
)
1021

1122
android_lint(
1223
name = "lib_lint",
13-
srcs = ["Foo.java"],
24+
srcs = ["TestActivity.java"],
1425
android_lint_config = "lint.xml",
1526
lib = ":lib",
27+
manifest = "LibManifest.xml",
1628
)
1729

1830
android_lint_test(
1931
name = "lib_lint_test",
20-
srcs = ["Foo.java"],
32+
srcs = ["TestActivity.java"],
2133
baseline = "lib_lint_test_lint_baseline.xml",
2234
lib = ":lib",
35+
manifest = "LibManifest.xml",
36+
)
37+
38+
android_lint(
39+
name = "bin_lint",
40+
srcs = ["Foo.java"],
41+
android_lint_config = "lint.xml",
42+
lib = ":bin",
43+
manifest = "AndroidManifest.xml",
44+
)
45+
46+
android_lint_test(
47+
name = "bin_lint_test",
48+
srcs = ["Foo.java"],
49+
baseline = "bin_lint_test_lint_baseline.xml",
50+
lib = ":bin",
2351
)
2452

2553
android_lint_toolchain(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.rules.android.lint.examples">
4+
5+
<uses-sdk android:minSdkVersion="1"
6+
android:targetSdkVersion="1" />
7+
</manifest>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.rules.android.lint.examples;
2+
3+
import android.app.Activity;
4+
5+
public class TestActivity extends Activity {
6+
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
android_sdk_repository(name = "androidsdk")
2+
android_ndk_repository(name = "androidndk")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<issues format="6" by="lint 8.3.0-alpha09">
3+
4+
<issue
5+
id="DefaultLocale"
6+
severity="Error"
7+
message="Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
8+
category="Correctness"
9+
priority="6"
10+
summary="Implied default locale in case conversion"
11+
explanation="Calling `String#toLowerCase()` or `#toUpperCase()` **without specifying an explicit locale** is a common source of bugs. The reason for that is that those methods will use the current locale on the user&apos;s device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for `i` is **not** `I`.&#xA;&#xA;If you want the methods to just perform ASCII replacement, for example to convert an enum name, call `String#toUpperCase(Locale.US)` instead. If you really want to use the current locale, call `String#toUpperCase(Locale.getDefault())` instead."
12+
url="https://developer.android.com/reference/java/util/Locale.html#default_locale"
13+
urls="https://developer.android.com/reference/java/util/Locale.html#default_locale"
14+
errorLine1=" System.out.println(&quot;WRONG&quot;.toUpperCase());"
15+
errorLine2=" ~~~~~~~~~~~">
16+
<location
17+
file="Foo.java"
18+
line="6"
19+
column="32"/>
20+
</issue>
21+
22+
</issues>

examples/simple-android/lib_lint_test_lint_baseline.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
<issues format="6" by="lint 8.3.0-alpha09">
33

44
<issue
5-
id="DefaultLocale"
6-
severity="Error"
7-
message="Implicitly using the default locale is a common source of bugs: Use `toUpperCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
8-
category="Correctness"
9-
priority="6"
10-
summary="Implied default locale in case conversion"
11-
explanation="Calling `String#toLowerCase()` or `#toUpperCase()` **without specifying an explicit locale** is a common source of bugs. The reason for that is that those methods will use the current locale on the user&apos;s device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for `i` is **not** `I`.&#xA;&#xA;If you want the methods to just perform ASCII replacement, for example to convert an enum name, call `String#toUpperCase(Locale.US)` instead. If you really want to use the current locale, call `String#toUpperCase(Locale.getDefault())` instead."
12-
url="https://developer.android.com/reference/java/util/Locale.html#default_locale"
13-
urls="https://developer.android.com/reference/java/util/Locale.html#default_locale"
14-
errorLine1=" System.out.println(&quot;WRONG&quot;.toUpperCase());"
15-
errorLine2=" ~~~~~~~~~~~">
5+
id="ExpiredTargetSdkVersion"
6+
severity="Fatal"
7+
message="Google Play requires that apps target API level 33 or higher."
8+
category="Compliance"
9+
priority="8"
10+
summary="TargetSdkVersion No Longer Supported"
11+
explanation="Configuring your app to target a recent API level ensures that users benefit from significant security and performance improvements, while still allowing your app to run on older Android versions (down to the `minSdkVersion`).&#xA;&#xA;To update your `targetSdkVersion`, follow the steps from &quot;Meeting Google Play requirements for target API level&quot;, https://developer.android.com/distribute/best-practices/develop/target-sdk.html"
12+
url="https://support.google.com/googleplay/android-developer/answer/113469#targetsdk"
13+
urls="https://support.google.com/googleplay/android-developer/answer/113469#targetsdk,https://developer.android.com/distribute/best-practices/develop/target-sdk.html"
14+
errorLine1=" android:targetSdkVersion=&quot;1&quot; />"
15+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
1616
<location
17-
file="Foo.java"
17+
file="bazel-out/darwin_arm64-fastbuild/bin/AndroidManifest.xml"
1818
line="6"
19-
column="32"/>
19+
column="9"/>
2020
</issue>
2121

2222
</issues>

rules/impl.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def _run_android_lint(
2424
deps,
2525
resource_files,
2626
manifest,
27+
merged_manifest,
2728
compile_sdk_version,
2829
java_language_level,
2930
kotlin_language_level,
@@ -87,6 +88,9 @@ def _run_android_lint(
8788
if manifest:
8889
args.add("--android-manifest", manifest)
8990
inputs.append(manifest)
91+
if merged_manifest:
92+
args.add("--android-merged-manifest", merged_manifest)
93+
inputs.append(merged_manifest)
9094
if not regenerate and baseline:
9195
args.add("--baseline-file", baseline)
9296
inputs.append(baseline)
@@ -171,6 +175,10 @@ def process_android_lint_issues(ctx, regenerate):
171175
manifest = ctx.actions.declare_file("AndroidManifest.xml")
172176
ctx.actions.symlink(output = manifest, target_file = ctx.file.manifest)
173177

178+
merged_manifest = None
179+
if ctx.attr.lib and AndroidManifestInfo in ctx.attr.lib and AndroidBinaryData in ctx.attr.lib:
180+
merged_manifest = ctx.attr.lib[AndroidManifestInfo].manifest
181+
174182
# Collect the transitive classpath jars to run lint against.
175183
deps = []
176184
for dep in ctx.attr.deps:
@@ -205,6 +213,7 @@ def process_android_lint_issues(ctx, regenerate):
205213
deps = depset(transitive = deps),
206214
resource_files = ctx.files.resource_files,
207215
manifest = manifest,
216+
merged_manifest = merged_manifest,
208217
compile_sdk_version = _utils.get_android_lint_toolchain(ctx).compile_sdk_version,
209218
java_language_level = _utils.get_android_lint_toolchain(ctx).java_language_level,
210219
kotlin_language_level = _utils.get_android_lint_toolchain(ctx).kotlin_language_level,

src/cli/AndroidLintActionArgs.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ internal class AndroidLintActionArgs(
5050
transform = argsParserPathTransformer,
5151
).default { null }
5252

53+
val androidMergedManifest: Path? by parser.storing(
54+
names = arrayOf("--android-merged-manifest"),
55+
help = "Merged android manifest for Android Binary targets",
56+
transform = argsParserPathTransformer,
57+
).default { null }
58+
5359
val baselineFile: Path? by parser.storing(
5460
names = arrayOf("--baseline-file"),
5561
help = "",

0 commit comments

Comments
 (0)