pkglint: Static analyzer for pkgsrc
Roland Illig
Introduction
- NetBSD and pkgsrc are dying (once again).
- Goal: Higher quality.
- One way to achieve that: Static analysis.
History: pkglint in the year 2000
OK: checking pkg/COMMENT.
OK: checking pkg/DESCR.
WARN: pkg/DESCR exceeds 24 lines, make it shorter if possible.(currently 48 lines)
OK: checking Makefile.
WARN: possible use of absolute pathname "/LIBGEN/d", in Makefile.
FATAL: extra item "NOT_FOR_PLATFORM" placed in the MAINTAINER section.
WARN: please add HOMEPAGE if the package has one.
FATAL: no MAINTAINER listed in Makefile.
WARN: "HOMEPAGE" has to appear earlier in Makefile.
WARN: "MAINTAINER" has to appear earlier in Makefile.
WARN: "HOMEPAGE" has to appear earlier in Makefile.
OK: checking patches/patch-aa.
OK: checking patches/patch-ab.
OK: checking patches/patch-ac.
OK: checking patches/patch-ad.
OK: checking patches/patch-ae.
OK: checking patches/patch-af.
OK: checking patches/patch-ag.
OK: checking patches/patch-ah.
OK: checking files/patch-sum.
OK: checking files/md5.
2 fatal errors and 6 warnings found.
History: pkglint in the year 2004
OK: checking Makefile.
WARN: possible use of absolute pathname "/LIBGEN/d", in Makefile.
OK: checking ./PLIST.
OK: checking ./DESCR.
OK: checking patches/patch-aa.
OK: checking patches/patch-ab.
OK: checking patches/patch-ac.
OK: checking patches/patch-ae.
OK: checking patches/patch-af.
OK: checking distinfo.
0 fatal errors and 1 warnings found.
History: pkglint some days ago
$ pkglint
NOTE: Makefile:26: Please use the SUBST framework instead of ${SED} and ${MV}.
looks fine.
$ pkglint -Wall
NOTE: Makefile:8: Alignment of variable values should be done with tabs, not spaces.
NOTE: Makefile:26: Please use the SUBST framework instead of ${SED} and ${MV}.
WARN: Makefile:26: A semicolon should only be used to separate commands after switching to "set -e" mode.
WARN: Makefile:26: A semicolon should only be used to separate commands after switching to "set -e" mode.
WARN: Makefile:30--31: A semicolon should only be used to separate commands after switching to "set -e" mode.
WARN: patches/patch-aa:3: Comment expected.
WARN: patches/patch-ab:3: Comment expected.
WARN: patches/patch-ac:3: Comment expected.
WARN: patches/patch-ad:3: Comment expected.
WARN: patches/patch-ae:3: Comment expected.
WARN: patches/patch-af:3: Comment expected.
WARN: patches/patch-ag:3: Comment expected.
0 errors and 10 warnings found.
What can pkglint do?
- Detect classes of bugs that have happened somewhere in the past.
- Enforce a uniform layout and structure of pkgsrc packages.
- Notify package developers of bugs they haven't even heard of.
- Document and codify existing practice.
- Force new practice.
How to use pkglint (1/2)
$ pkglint --x
usage: pkglint [options] [package_directory]
options:
-C{check,...} Enable or disable specific checks
-F|--autofix Try to automatically fix some errors (experimental)
-I|--dumpmakefile Dump the Makefile after parsing
-R|--rcsidstring Set the allowed RCS Id strings
-V|--version print the version number of pkglint
-W{warn,...} enable or disable specific warnings
-d|--debug Print additional warnings that are mostly of use to pkglint's author
-e|--explain Explain the diagnostics or give further help
-g|--gcc-output-format Mimic the gcc output format
-h|--help print a detailed help message
-i|--import Prepare the import of a wip package
-q|--quiet Don't print a summary line when finishing
-r|--recursive Recursive---check subdirectories, too
-s|--source Show the source lines together with diagnostics
-v|--verbose print progress messages
--klickibunti Enable colored and precise diagnostics
How to use pkglint (2/2)
warnings: (use "warn" to enable, "no-warn" to disable)
all enable all warnings
none disable all warnings
absname (enabled) warn about use of absolute file names
directcmd (enabled) warn about use of direct command names instead of Make variables
extra (disabled) enable some extra warnings
order (enabled) warn if Makefile entries are unordered
plist-depr (disabled) warn about deprecated paths in PLISTs
plist-sort (disabled) warn about unsorted entries in PLISTs
quoting (disabled) warn about quoting issues
space (disabled) warn about inconsistent use of white-space
style (disabled) warn about stylistic issues
types (enabled) do some simple type checking in Makefiles
varorder (disabled) warn about the ordering of variables
How are the causes for the warnings fixed properly?
- Let's make this a live demo.
Future Directions
- Many more checks can be done.
- Binary packages can be checked, too (see Debian).
- TODO: Improve diagnostics and user documentation.
- Static analysis is only a small part of quality.