build: make clippy Makefile rules nicer

These are easy to get subtly wrong, and doing so can cause
nondeterministic failures when racing in parallel builds.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2020-04-15 10:27:49 +02:00
parent ec8f987e91
commit 94cfb0692e
20 changed files with 181 additions and 88 deletions

View file

@ -110,6 +110,7 @@ dist_examples_DATA =
dist_yangmodels_DATA =
man_MANS =
vtysh_scan =
clippy_scan =
## libtool, the self-made GNU scourge
## ... this should fix relinking
@ -184,6 +185,7 @@ EXTRA_DIST += \
python/clidef.py \
python/clippy/__init__.py \
python/makevars.py \
python/makefile.py \
\
redhat/frr.logrotate \
redhat/frr.pam \

View file

@ -25,11 +25,10 @@ bfdd_libbfd_a_SOURCES = \
bfdd/ptm_adapter.c \
# end
bfdd/bfdd_vty_clippy.c: $(CLIPPY_DEPS)
bfdd/bfdd_vty.$(OBJEXT): bfdd/bfdd_vty_clippy.c
bfdd/bfdd_cli_clippy.c: $(CLIPPY_DEPS)
bfdd/bfdd_cli.$(OBJEXT): bfdd/bfdd_cli_clippy.c
clippy_scan += \
bfdd/bfdd_cli.c \
bfdd/bfdd_vty.c \
# end
noinst_HEADERS += \
bfdd/bfdctl.h \

View file

@ -217,18 +217,12 @@ bgpd_bgpd_bmp_la_SOURCES = bgpd/bgp_bmp.c
bgpd_bgpd_bmp_la_LIBADD = lib/libfrrcares.la
bgpd_bgpd_bmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
bgpd/bgp_evpn_vty_clippy.c: $(CLIPPY_DEPS)
bgpd/bgp_evpn_vty.$(OBJEXT): bgpd/bgp_evpn_vty_clippy.c
bgpd/bgp_vty_clippy.c: $(CLIPPY_DEPS)
bgpd/bgp_vty.$(OBJEXT): bgpd/bgp_vty_clippy.c
bgpd/bgp_route_clippy.c: $(CLIPPY_DEPS)
bgpd/bgp_route.$(OBJEXT): bgpd/bgp_route_clippy.c
bgpd/bgp_debug_clippy.c: $(CLIPPY_DEPS)
bgpd/bgp_debug.$(OBJEXT): bgpd/bgp_debug_clippy.c
bgpd/bgp_routemap_clippy.c: $(CLIPPY_DEPS)
bgpd/bgp_routemap.$(OBJEXT): bgpd/bgp_routemap_clippy.c
bgpd/bgp_rpki_clippy.c: $(CLIPPY_DEPS)
$(AUTOMAKE_DUMMY)bgpd/bgpd_bgpd_rpki_la-bgp_rpki.lo: bgpd/bgp_rpki_clippy.c
$(AUTOMAKE_DUMMY)bgpd/bgpd_rpki_la-bgp_rpki.lo: bgpd/bgp_rpki_clippy.c
bgpd/bgp_bmp_clippy.c: $(CLIPPY_DEPS)
bgpd/bgp_bmp.lo: bgpd/bgp_bmp_clippy.c
clippy_scan += \
bgpd/bgp_bmp.c \
bgpd/bgp_debug.c \
bgpd/bgp_evpn_vty.c \
bgpd/bgp_route.c \
bgpd/bgp_routemap.c \
bgpd/bgp_rpki.c \
bgpd/bgp_vty.c \
# end

View file

@ -2402,7 +2402,13 @@ AM_CONDITIONAL([STATICD], [test "$enable_staticd" != "no"])
AM_CONDITIONAL([FABRICD], [test "$enable_fabricd" != "no"])
AM_CONDITIONAL([VRRPD], [test "$enable_vrrpd" != "no"])
AC_CONFIG_FILES([Makefile],[sed -e 's/^#AUTODERP# //' -i Makefile])
AC_CONFIG_FILES([Makefile],[
test "$enable_dev_build" = "yes" && makefile_devbuild="--dev-build"
${PYTHON} "${ac_abs_top_srcdir}/python/makefile.py" ${makefile_devbuild} || exit 1
], [
PYTHON="$PYTHON"
enable_dev_build="$enable_dev_build"
])
AC_CONFIG_FILES([
config.version

View file

@ -48,11 +48,10 @@ eigrpdheader_HEADERS = \
eigrpd/eigrpd.h \
# end
eigrpd/eigrp_vty_clippy.c: $(CLIPPY_DEPS)
eigrpd/eigrp_vty.$(OBJEXT): eigrpd/eigrp_vty_clippy.c
eigrpd/eigrp_cli_clippy.c: $(CLIPPY_DEPS)
eigrpd/eigrp_cli.$(OBJEXT): eigrpd/eigrp_cli_clippy.c
clippy_scan += \
eigrpd/eigrp_cli.c \
eigrpd/eigrp_vty.c \
# end
noinst_HEADERS += \
eigrpd/eigrp_const.h \

View file

@ -106,8 +106,9 @@ isisd_libisis_a_SOURCES = \
isisd/isis_cli.c \
#end
isisd/isis_cli_clippy.c: $(CLIPPY_DEPS)
isisd/isis_cli.$(OBJEXT): isisd/isis_cli_clippy.c
clippy_scan += \
isisd/isis_cli.c \
# end
isisd_isisd_LDADD = isisd/libisis.a $(ISIS_LDADD_COMMON)
isisd_isisd_SOURCES = $(ISIS_SOURCES)

View file

@ -40,8 +40,9 @@ ldpd_libldp_a_SOURCES = \
ldpd/util.c \
# end
ldpd/ldp_vty_cmds_clippy.c: $(CLIPPY_DEPS)
ldpd/ldp_vty_cmds.$(OBJEXT): ldpd/ldp_vty_cmds_clippy.c
clippy_scan += \
ldpd/ldp_vty_cmds.c \
# end
noinst_HEADERS += \
ldpd/control.h \

View file

@ -146,20 +146,15 @@ lib_libfrr_la_LIBADD += $(SQLITE3_LIBS)
lib_libfrr_la_SOURCES += lib/db.c
endif
lib/if_clippy.c: $(CLIPPY_DEPS)
lib/if.lo: lib/if_clippy.c
lib/plist_clippy.c: $(CLIPPY_DEPS)
lib/plist.lo: lib/plist_clippy.c
lib/nexthop_group_clippy.c: $(CLIPPY_DEPS)
lib/nexthop_group.lo: lib/nexthop_group_clippy.c
lib/northbound_cli_clippy.c: $(CLIPPY_DEPS)
lib/northbound_cli.lo: lib/northbound_cli_clippy.c
lib/routemap_cli_clippy.c: $(CLIPPY_DEPS)
lib/routemap_cli.lo: lib/routemap_cli_clippy.c
lib/vty_clippy.c: $(CLIPPY_DEPS)
lib/vty.lo: lib/vty_clippy.c
lib/log_vty_clippy.c: $(CLIPPY_DEPS)
lib/log_vty.lo: lib/log_vty_clippy.c
clippy_scan += \
lib/if.c \
lib/log_vty.c \
lib/nexthop_group.c \
lib/northbound_cli.c \
lib/plist.c \
lib/routemap_cli.c \
lib/vty.c \
# end
pkginclude_HEADERS += \
lib/agg_table.h \

View file

@ -72,8 +72,9 @@ ospfdheader_HEADERS = \
# end
endif
ospfd/ospf_vty_clippy.c: $(CLIPPY_DEPS)
ospfd/ospf_vty.$(OBJEXT): ospfd/ospf_vty_clippy.c
clippy_scan += \
ospfd/ospf_vty.c \
# end
noinst_HEADERS += \
ospfd/ospf_abr.h \

View file

@ -33,11 +33,10 @@ noinst_HEADERS += \
pbrd/pbr_vrf.h \
# end
pbrd/pbr_vty_clippy.c: $(CLIPPY_DEPS)
pbrd/pbr_vty.$(OBJEXT): pbrd/pbr_vty_clippy.c
pbrd/pbr_debug_clippy.c: $(CLIPPY_DEPS)
pbrd/pbr_debug.$(OBJEXT): pbrd/pbr_debug_clippy.c
clippy_scan += \
pbrd/pbr_debug.c \
pbrd/pbr_vty.c \
# end
pbrd_pbrd_SOURCES = pbrd/pbr_main.c
pbrd_pbrd_LDADD = pbrd/libpbr.a lib/libfrr.la $(LIBCAP)

View file

@ -123,8 +123,9 @@ noinst_HEADERS += \
pimd/mtracebis_routeget.h \
# end
pimd/pim_cmd_clippy.c: $(CLIPPY_DEPS)
pimd/pim_cmd.$(OBJEXT): pimd/pim_cmd_clippy.c
clippy_scan += \
pimd/pim_cmd.c \
# end
pimd_pimd_LDADD = pimd/libpim.a lib/libfrr.la $(LIBCAP)
pimd_pimd_SOURCES = pimd/pim_main.c

100
python/makefile.py Normal file
View file

@ -0,0 +1,100 @@
#!/usr/bin/python3
#
# FRR extended automake/Makefile functionality helper
#
# This script is executed on/after generating Makefile to add some pieces for
# clippy.
import sys
import os
import subprocess
import re
import argparse
from string import Template
argp = argparse.ArgumentParser(description = 'FRR Makefile extensions')
argp.add_argument('--dev-build', action = 'store_const', const = True,
help = 'run additional developer checks')
args = argp.parse_args()
with open('Makefile', 'r') as fd:
before = fd.read()
nolinecont = before.replace('\\\n', '')
m = re.search('^clippy_scan\s*=([^#]*)(?:#.*)?$', nolinecont, flags=re.MULTILINE)
if m is None:
sys.stderr.write('failed to parse Makefile.in\n')
sys.exit(2)
clippy_scan = m.group(1).strip().split()
for clippy_file in clippy_scan:
assert clippy_file.endswith('.c')
# check for files using clippy but not listed in clippy_scan
if args.dev_build:
basepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if os.path.exists(os.path.join(basepath, '.git')):
clippy_ref = subprocess.check_output([
'git', '-C', basepath, 'grep', '-l', '-P', '^#\s*include.*_clippy.c', '--', '**.c']).decode('US-ASCII')
clippy_ref = set(clippy_ref.splitlines())
missing = clippy_ref - set(clippy_scan)
if len(missing) > 0:
sys.stderr.write('error: files seem to be using clippy, but not listed in "clippy_scan" in subdir.am:\n\t%s\n' % ('\n\t'.join(sorted(missing))))
sys.exit(1)
clippydep = Template('''
${clippybase}.$$(OBJEXT): ${clippybase}_clippy.c
${clippybase}.lo: ${clippybase}_clippy.c
${clippybase}_clippy.c: $$(CLIPPY_DEPS)''')
clippyauxdep = Template('''# clippy{
# auxiliary clippy target
${target}: ${clippybase}_clippy.c
# }clippy''')
lines = before.splitlines()
autoderp = '#AUTODERP# '
out_lines = []
make_rule_re = re.compile('^([^:\s]+):\s*([^:\s]+)\s*($|\n)')
while lines:
line = lines.pop(0)
if line.startswith(autoderp):
line = line[len(autoderp):]
if line == '# clippy{':
while lines:
line = lines.pop(0)
if line == '# }clippy':
break
continue
if line.startswith('#'):
out_lines.append(line)
continue
m = make_rule_re.match(line)
if m is None:
out_lines.append(line)
continue
if m.group(2) in clippy_scan:
out_lines.append(clippyauxdep.substitute(target=m.group(1), clippybase=m.group(2)[:-2]))
out_lines.append(line)
out_lines.append('# clippy{\n# main clippy targets')
for clippy_file in clippy_scan:
out_lines.append(clippydep.substitute(clippybase = clippy_file[:-2]))
out_lines.append('# }clippy')
out_lines.append('')
after = '\n'.join(out_lines)
if after == before:
sys.exit(0)
with open('Makefile.pyout', 'w') as fd:
fd.write(after)
os.rename('Makefile.pyout', 'Makefile')

View file

@ -35,8 +35,9 @@ ripd_librip_a_SOURCES = \
ripd/ripd.c \
# end
ripd/rip_cli_clippy.c: $(CLIPPY_DEPS)
ripd/rip_cli.$(OBJEXT): ripd/rip_cli_clippy.c
clippy_scan += \
ripd/rip_cli.c \
# end
noinst_HEADERS += \
ripd/rip_debug.h \

View file

@ -30,8 +30,9 @@ ripngd_libripng_a_SOURCES = \
ripngd/ripngd.c \
# end
ripngd/ripng_cli_clippy.c: $(CLIPPY_DEPS)
ripngd/ripng_cli.$(OBJEXT): ripngd/ripng_cli_clippy.c
clippy_scan += \
ripngd/ripng_cli.c \
# end
noinst_HEADERS += \
ripngd/ripng_debug.h \

View file

@ -24,8 +24,9 @@ noinst_HEADERS += \
sharpd/sharp_zebra.h \
# end
sharpd/sharp_vty_clippy.c: $(CLIPPY_DEPS)
sharpd/sharp_vty.$(OBJEXT): sharpd/sharp_vty_clippy.c
clippy_scan += \
sharpd/sharp_vty.c \
# end
sharpd_sharpd_SOURCES = sharpd/sharp_main.c
sharpd_sharpd_LDADD = sharpd/libsharp.a lib/libfrr.la $(LIBCAP)

View file

@ -30,8 +30,9 @@ noinst_HEADERS += \
staticd/static_vrf.h \
# end
staticd/static_vty_clippy.c: $(CLIPPY_DEPS)
staticd/static_vty.$(OBJEXT): staticd/static_vty_clippy.c
clippy_scan += \
staticd/static_vty.c \
# end
staticd_staticd_SOURCES = staticd/static_main.c
staticd_staticd_LDADD = staticd/libstatic.a lib/libfrr.la $(LIBCAP)

View file

@ -38,13 +38,10 @@ else
TESTS_OSPF6D =
endif
tests/lib/cli/test_cli_clippy.c: $(CLIPPY_DEPS)
tests/lib/cli/tests_lib_cli_test_cli-test_cli.$(OBJEXT): tests/lib/cli/test_cli_clippy.c
tests/lib/cli/test_cli-test_cli.$(OBJEXT): tests/lib/cli/test_cli_clippy.c
tests/ospf6d/test_lsdb_clippy.c: $(CLIPPY_DEPS)
tests/ospf6d/tests_ospf6d_test_lsdb-test_lsdb.$(OBJEXT): tests/ospf6d/test_lsdb_clippy.c
tests/ospf6d/test_lsdb-test_lsdb.$(OBJEXT): tests/ospf6d/test_lsdb_clippy.c
clippy_scan += \
tests/lib/cli/test_cli.c \
tests/ospf6d/test_lsdb.c \
# end
check_PROGRAMS = \
tests/lib/cxxcompat \

View file

@ -31,8 +31,9 @@ noinst_HEADERS += \
vrrpd/vrrp_zebra.h \
# end
vrrpd/vrrp_vty_clippy.c: $(CLIPPY_DEPS)
vrrpd/vrrp_vty.$(OBJEXT): vrrpd/vrrp_vty_clippy.c
clippy_scan += \
vrrpd/vrrp_vty.c \
# end
vrrpd_vrrpd_SOURCES = vrrpd/vrrp_main.c
vrrpd_vrrpd_LDADD = vrrpd/libvrrp.a lib/libfrr.la @LIBCAP@

View file

@ -20,5 +20,6 @@ watchfrr_watchfrr_SOURCES = \
watchfrr/watchfrr_vty.c \
# end
watchfrr/watchfrr_vty_clippy.c: $(CLIPPY_DEPS)
watchfrr/watchfrr_vty.$(OBJEXT): watchfrr/watchfrr_vty_clippy.c
clippy_scan += \
watchfrr/watchfrr_vty.c \
# end

View file

@ -109,22 +109,14 @@ zebra_zebra_SOURCES = \
zebra/zebra_gr.c \
# end
zebra/debug_clippy.c: $(CLIPPY_DEPS)
zebra/debug.$(OBJEXT): zebra/debug_clippy.c
zebra/zebra_mlag_vty_clippy.c: $(CLIPPY_DEPS)
zebra/zebra_mlag_vty.$(OBJEXT): zebra/zebra_mlag_vty_clippy.c
zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS)
zebra/interface_clippy.c: $(CLIPPY_DEPS)
zebra/interface.$(OBJEXT): zebra/interface_clippy.c
zebra/zebra_vty.$(OBJEXT): zebra/zebra_vty_clippy.c
zebra/zebra_routemap_clippy.c: $(CLIPPY_DEPS)
zebra/zebra_routemap.$(OBJEXT): zebra/zebra_routemap_clippy.c
zebra/rtadv_clippy.c: $(CLIPPY_DEPS)
zebra/rtadv.$(OBJEXT): zebra/rtadv_clippy.c
clippy_scan += \
zebra/debug.c \
zebra/interface.c \
zebra/rtadv.c \
zebra/zebra_mlag_vty.c \
zebra/zebra_routemap.c \
zebra/zebra_vty.c \
# end
noinst_HEADERS += \
zebra/connected.h \