From f146b4287f5dd9b12697afad58d4385ec434d7b5 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Tue, 3 Jan 2023 16:42:21 +0100 Subject: [PATCH] Licensing: skip modules with fewer subdirs than mods This came up when updating go-oidc. After updating go-oidc (with its dependency tree), cloud.google.com/go was no longer used as a package import, but still listed in the module dependency graph; as a result, "go mod vendor" no longer pulled in cloud.google.com/go itself, but update-vendor-licenses.sh still wanted a license file for it since it appeared in the list of modules. This scenario is already supposed to be handled: when a module doesn't contain any *files* as first-level content, if the number of subdirectories it contains *equals* the number of submodules it contains (excluding itself), the module is skipped. This fails for cloud.google.com/go because several submodules are included in the module dependency graph but aren't actually used, and therefore not vendored. Updating the test to check that the number of subdirectories is less than or equal to the number of expected submodules fixes this. The correct fix would be to process the submodules first, keeping a note of which ones really have content, then check that the top-level module only contains subdirectories corresponding to those modules; but it's not clear to me that this is worth the effort (especially in a shell script). Signed-off-by: Stephen Kitt --- hack/update-vendor-licenses.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/update-vendor-licenses.sh b/hack/update-vendor-licenses.sh index fcbcf982877..2f6ce5e0d86 100755 --- a/hack/update-vendor-licenses.sh +++ b/hack/update-vendor-licenses.sh @@ -201,8 +201,8 @@ for PACKAGE in ${modules}; do # if there are no files vendored under this package... if [[ -z "$(find "${DEPS_DIR}/${PACKAGE}" -mindepth 1 -maxdepth 1 -type f)" ]]; then - # and we have the same number of submodules as subdirectories... - if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq "$(echo "${modules}" | grep -cE "^${PACKAGE}/")" ]]; then + # and we have at least the same number of submodules as subdirectories... + if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -le "$(echo "${modules}" | grep -cE "^${PACKAGE}/")" ]]; then echo "Only submodules of ${PACKAGE} are vendored, skipping" >&2 continue fi