Skip to content

Commit

Permalink
Issue mozilla-mobile#34: Add a way to enforce specific lints.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agi committed Dec 5, 2018
1 parent 1373d21 commit ebc7a1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ apiLint {
currentApiRelativeFilePath = 'api.txt'
jsonResultFileName = 'apilint-result.json'
changelogFileName = null
lintFilters = null
}
```

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

<code><b>changelogFileName</b></code> Relative path to the changelog file,
optional. See also [Changelog](#changelog).

<code><b>lintFilters</b></code> List of lints that fail the build, by default
all lints can fail the build. Filters will match any error code that starts
with the string specified, e.g. `GV` will match `GV1`, `GV2`, ...
26 changes: 21 additions & 5 deletions apilint/src/main/groovy/org/mozilla/apilint/ApiLintPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,36 @@ class ApiLintPlugin implements Plugin<Project> {

apiGenerate.dependsOn variant.javaCompile

def apiCompatLint = project.task("apiCompatLint${name}", type: PythonExec) {
description = "Runs API compatibility lint checks for variant ${name}"
workingDir '.'
scriptPath 'apilint.py'
args '--show-noticed'
args apiFile
args currentApiFile
args '--result-json'
args project.file(
"${variant.javaCompile.destinationDir}/${extension.jsonResultFileName}")
}

apiCompatLint.dependsOn apiGenerate

def apiLint = project.task("apiLint${name}", type: PythonExec) {
description = "Runs API lint checks for variant ${name}"
group = 'Verification'
workingDir '.'
scriptPath 'apilint.py'
args '--show-noticed'
args apiFile
args currentApiFile
args '--result-json'
args project.file(
"${variant.javaCompile.destinationDir}/${extension.jsonResultFileName}")
if (extension.lintFilters != null) {
args '--filter-errors'
args extension.lintFilters
}
}

apiLint.dependsOn apiGenerate
apiLint.dependsOn apiCompatLint
project.tasks.check.dependsOn apiLint

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

apiChangelogCheck.dependsOn apiGenerate
apiLint.dependsOn apiChangelogCheck
apiCompatLint.dependsOn apiChangelogCheck
}

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

apiLintHelp.dependsOn apiDiff
apiLint.finalizedBy apiLintHelp
apiCompatLint.finalizedBy apiLintHelp

def apiUpdate = project.task("apiUpdateFile${name}", type: Copy) {
description = "Updates the API file from the local one for variant ${name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class ApiLintPluginExtension {
String currentApiRelativeFilePath = 'api.txt'
String jsonResultFileName = 'apilint-result.json'
String changelogFileName
List<String> lintFilters
}
3 changes: 2 additions & 1 deletion apilint/src/main/resources/apilint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,8 @@ def matches_filter(filter_, failure):
filtered_fail[p] = cur_fail[p]
cur_fail = filtered_fail

dump_result_json(args, compat_fail, cur_noticed, cur_fail)
dump_result_json(args, compat_fail,
cur_noticed if args['show_noticed'] else [], cur_fail)

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

0 comments on commit ebc7a1e

Please sign in to comment.