Skip to content

Commit ebc7a1e

Browse files
committed
Issue mozilla-mobile#34: Add a way to enforce specific lints.
Before this commits no lints would actually fail the build because we only checked for compatibility. After this commit apilint runs the lint twice: - Once with only the existing api as argument to check for lints (with an optional filter for lints). - Once with both existing and new API to check for compatibility. This adds a new configuration: `apiLint.lintFilters` which allows consumers to set a list of prefixes of lints that can fail the build.
1 parent 1373d21 commit ebc7a1e

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ apiLint {
105105
currentApiRelativeFilePath = 'api.txt'
106106
jsonResultFileName = 'apilint-result.json'
107107
changelogFileName = null
108+
lintFilters = null
108109
}
109110
```
110111

@@ -122,3 +123,7 @@ contains the result of apilint.
122123

123124
<code><b>changelogFileName</b></code> Relative path to the changelog file,
124125
optional. See also [Changelog](#changelog).
126+
127+
<code><b>lintFilters</b></code> List of lints that fail the build, by default
128+
all lints can fail the build. Filters will match any error code that starts
129+
with the string specified, e.g. `GV` will match `GV1`, `GV2`, ...

apilint/src/main/groovy/org/mozilla/apilint/ApiLintPlugin.groovy

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,36 @@ class ApiLintPlugin implements Plugin<Project> {
4545

4646
apiGenerate.dependsOn variant.javaCompile
4747

48+
def apiCompatLint = project.task("apiCompatLint${name}", type: PythonExec) {
49+
description = "Runs API compatibility lint checks for variant ${name}"
50+
workingDir '.'
51+
scriptPath 'apilint.py'
52+
args '--show-noticed'
53+
args apiFile
54+
args currentApiFile
55+
args '--result-json'
56+
args project.file(
57+
"${variant.javaCompile.destinationDir}/${extension.jsonResultFileName}")
58+
}
59+
60+
apiCompatLint.dependsOn apiGenerate
61+
4862
def apiLint = project.task("apiLint${name}", type: PythonExec) {
4963
description = "Runs API lint checks for variant ${name}"
5064
group = 'Verification'
5165
workingDir '.'
5266
scriptPath 'apilint.py'
53-
args '--show-noticed'
54-
args apiFile
5567
args currentApiFile
5668
args '--result-json'
5769
args project.file(
5870
"${variant.javaCompile.destinationDir}/${extension.jsonResultFileName}")
71+
if (extension.lintFilters != null) {
72+
args '--filter-errors'
73+
args extension.lintFilters
74+
}
5975
}
6076

61-
apiLint.dependsOn apiGenerate
77+
apiLint.dependsOn apiCompatLint
6278
project.tasks.check.dependsOn apiLint
6379

6480
if (extension.changelogFileName) {
@@ -74,7 +90,7 @@ class ApiLintPlugin implements Plugin<Project> {
7490
}
7591

7692
apiChangelogCheck.dependsOn apiGenerate
77-
apiLint.dependsOn apiChangelogCheck
93+
apiCompatLint.dependsOn apiChangelogCheck
7894
}
7995

8096
def apiDiff = project.task("apiDiff${name}", type: Exec) {
@@ -107,7 +123,7 @@ class ApiLintPlugin implements Plugin<Project> {
107123
}
108124

109125
apiLintHelp.dependsOn apiDiff
110-
apiLint.finalizedBy apiLintHelp
126+
apiCompatLint.finalizedBy apiLintHelp
111127

112128
def apiUpdate = project.task("apiUpdateFile${name}", type: Copy) {
113129
description = "Updates the API file from the local one for variant ${name}"

apilint/src/main/groovy/org/mozilla/apilint/ApiLintPluginExtension.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class ApiLintPluginExtension {
88
String currentApiRelativeFilePath = 'api.txt'
99
String jsonResultFileName = 'apilint-result.json'
1010
String changelogFileName
11+
List<String> lintFilters
1112
}

apilint/src/main/resources/apilint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,8 @@ def matches_filter(filter_, failure):
16511651
filtered_fail[p] = cur_fail[p]
16521652
cur_fail = filtered_fail
16531653

1654-
dump_result_json(args, compat_fail, cur_noticed, cur_fail)
1654+
dump_result_json(args, compat_fail,
1655+
cur_noticed if args['show_noticed'] else [], cur_fail)
16551656

16561657
if compat_fail and len(compat_fail) != 0:
16571658
print("%s API compatibility issues %s\n" % ((format(fg=WHITE, bg=BLUE, bold=True), format(reset=True))))

0 commit comments

Comments
 (0)