Skip to content

Commit f146b42

Browse files
committed
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 <[email protected]>
1 parent 1edbb8c commit f146b42

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: hack/update-vendor-licenses.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ for PACKAGE in ${modules}; do
201201

202202
# if there are no files vendored under this package...
203203
if [[ -z "$(find "${DEPS_DIR}/${PACKAGE}" -mindepth 1 -maxdepth 1 -type f)" ]]; then
204-
# and we have the same number of submodules as subdirectories...
205-
if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq "$(echo "${modules}" | grep -cE "^${PACKAGE}/")" ]]; then
204+
# and we have at least the same number of submodules as subdirectories...
205+
if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -le "$(echo "${modules}" | grep -cE "^${PACKAGE}/")" ]]; then
206206
echo "Only submodules of ${PACKAGE} are vendored, skipping" >&2
207207
continue
208208
fi

0 commit comments

Comments
 (0)