Skip to content

Commit

Permalink
Add --summary and be more quiet by default (#100)
Browse files Browse the repository at this point in the history
* Add --summary and be more quiet by default

Changes to make abi3audit behave more like all compiler tools and be
quiet by default. The summary is now only output if there are violations
or ABI version mismatches. The only noise seen now when using abi3audit
in a build system is when there is something one should look at. The new
optional --summary argument will output the summary even if the reported
violations/ABI version mismatches are zero.

* Add missing type annotation

* Readme.md corrections for check-readme job
  • Loading branch information
wsfulton authored Jul 22, 2024
1 parent dd0ab17 commit 6742fdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Top-level:

<!-- @begin-abi3audit-help@ -->
```console
usage: abi3audit [-h] [--debug] [-v] [-R] [-o OUTPUT] [-S]
usage: abi3audit [-h] [--debug] [-v] [-R] [-o OUTPUT] [-s] [-S]
[--assume-minimum-abi3 ASSUME_MINIMUM_ABI3]
SPEC [SPEC ...]

Expand All @@ -104,6 +104,8 @@ options:
-R, --report generate a JSON report; uses --output
-o OUTPUT, --output OUTPUT
the path to write the JSON report to (default: stdout)
-s, --summary always output a summary even if there are no
violations/ABI version mismatches
-S, --strict fail the entire audit if an individual audit step
fails
--assume-minimum-abi3 ASSUME_MINIMUM_ABI3
Expand Down
25 changes: 18 additions & 7 deletions abi3audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@ def add(self, extractor: Extractor, so: SharedObject, result: AuditResult) -> No

self._abi3_violation_counts[so] += len(result.non_abi3_symbols)

def summarize_extraction(self, extractor: Extractor) -> str:
def summarize_extraction(self, extractor: Extractor, summary: bool) -> str | None:
spec_results = self._results[extractor]

if not spec_results:
return _yellow(f":person_shrugging: nothing auditable found in {extractor.spec}")

abi3_version_counts = sum(self._bad_abi3_version_counts[res.so] for res in spec_results)
abi3_violations = sum(self._abi3_violation_counts[res.so] for res in spec_results)
return (
f":information_desk_person: {extractor}: {len(spec_results)} extensions scanned; "
f"{_colornum(abi3_version_counts)} ABI version mismatches and "
f"{_colornum(abi3_violations)} ABI violations found"
)
if summary or abi3_violations > 0 or abi3_version_counts > 0:
return (
f":information_desk_person: {extractor}: {len(spec_results)} extensions scanned; "
f"{_colornum(abi3_version_counts)} ABI version mismatches and "
f"{_colornum(abi3_violations)} ABI violations found"
)
else:
return None

def json(self) -> dict[str, Any]:
"""
Expand Down Expand Up @@ -203,6 +206,12 @@ def main() -> None:
default=sys.stdout,
help="the path to write the JSON report to (default: stdout)",
)
parser.add_argument(
"-s",
"--summary",
action="store_true",
help="always output a summary even if there are no violations/ABI version mismatches",
)
parser.add_argument(
"-S",
"--strict",
Expand Down Expand Up @@ -250,7 +259,9 @@ def main() -> None:
if not result and args.verbose:
console.log(result)

console.log(results.summarize_extraction(extractor))
log_message = results.summarize_extraction(extractor, args.summary)
if log_message:
console.log(log_message)

if args.report:
print(json.dumps(results.json()), file=args.output)
Expand Down

0 comments on commit 6742fdf

Please sign in to comment.