Browse code

hack: allow pkg/ to import internal/ packages

The pkg-imports validation prevents reusable library packages from
depending on the whole daemon, accidentally or intentionally. The
allowlist is overly restrictive as it also prevents us from reusing code
in both pkg/ and daemon/ unless that code is also made into a reusable
library package under pkg/. Allow pkg/ packages to import internal/
packages which do not transitively depend on disallowed packages.

Signed-off-by: Cory Snider <csnider@mirantis.com>

Cory Snider authored on 2022/10/14 05:21:10
Showing 2 changed files
... ...
@@ -269,6 +269,7 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) {
269 269
         # Filter out what we are looking for
270 270
         $imports = @() + $imports -NotMatch "^github.com/docker/docker/pkg/" `
271 271
                                   -NotMatch "^github.com/docker/docker/vendor" `
272
+                                  -NotMatch "^github.com/docker/docker/internal" `
272 273
                                   -Match "^github.com/docker/docker" `
273 274
                                   -Replace "`n", ""
274 275
         $imports | ForEach-Object{ $badFiles+="$file imports $_`n" }
... ...
@@ -17,7 +17,12 @@ for f in "${files[@]}"; do
17 17
 		continue
18 18
 	fi
19 19
 	IFS=$'\n'
20
-	badImports=($(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/docker/docker/pkg/' | grep -vE '^github.com/docker/docker/vendor' | grep -E '^github.com/docker/docker' || true))
20
+	badImports=($(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u \
21
+		| grep -vE '^github.com/docker/docker/pkg/' \
22
+		| grep -vE '^github.com/docker/docker/vendor' \
23
+		| grep -vE '^github.com/docker/docker/internal' \
24
+		| grep -E '^github.com/docker/docker' \
25
+		|| true))
21 26
 	unset IFS
22 27
 
23 28
 	for import in "${badImports[@]}"; do