genmoddep.awk: Add a test that we have no circular dependencies

This commit is contained in:
Vladimir Serbinenko 2015-11-08 20:00:27 +01:00
parent 7cc27aeda9
commit db97faec91

View file

@ -29,7 +29,7 @@ BEGIN {
} }
} }
else { else {
printf "error: %u: unrecognized input format\n", NR; printf "error: %u: unrecognized input format\n", NR >"/dev/stderr";
error++; error++;
} }
} }
@ -39,6 +39,8 @@ END {
if (error >= 1) if (error >= 1)
exit 1; exit 1;
total_depcount = 0
for (mod in modtab) { for (mod in modtab) {
# Remove duplications. # Remove duplications.
split(modtab[mod], depmods, " "); split(modtab[mod], depmods, " ");
@ -52,14 +54,42 @@ END {
uniqmods[depmod] = 1; uniqmods[depmod] = 1;
} }
modlist = "" modlist = ""
depcount[mod] = 0
for (depmod in uniqmods) { for (depmod in uniqmods) {
modlist = modlist " " depmod; modlist = modlist " " depmod;
inverse_dependencies[depmod] = inverse_dependencies[depmod] " " mod
depcount[mod]++
total_depcount++
} }
if (mod == "all_video") { if (mod == "all_video") {
continue; continue;
} }
printf "%s:%s\n", mod, modlist; printf "%s:%s\n", mod, modlist;
} }
# Check that we have no dependency circles
while (total_depcount != 0) {
something_done = 0
for (mod in depcount) {
if (depcount[mod] == 0) {
delete depcount[mod]
split(inverse_dependencies[mod], inv_depmods, " ");
for (ctr in inv_depmods) {
depcount[inv_depmods[ctr]]--
total_depcount--
}
delete inverse_dependencies[mod]
something_done = 1
}
}
if (something_done == 0) {
for (mod in depcount) {
circle = circle " " mod
}
printf "error: modules %s form a dependency circle\n", circle >"/dev/stderr";
exit 1
}
}
modlist = "" modlist = ""
while (getline <"video.lst") { while (getline <"video.lst") {
modlist = modlist " " $1; modlist = modlist " " $1;