From 9465272c281c602c758e51ed99f344c0686a899a Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 12 Jun 2015 12:19:56 -0700 Subject: [PATCH] Add new "validate-pkg" bundlescript This helps ensure that `github.com/docker/docker/pkg/...` is actually safe to use in isolation (ie, doesn't import anything from `github.com/docker/docker` except other things from `pkg` or vendored dependencies). Adding `github.com/docker/docker/utils` to the imports of `pkg/version/version.go`: ``` ---> Making bundle: validate-pkg (in bundles/1.7.0-dev/validate-pkg) These files import internal code: (either directly or indirectly) - pkg/version/version.go imports github.com/docker/docker/autogen/dockerversion - pkg/version/version.go imports github.com/docker/docker/utils ``` And then removing it again: ``` ---> Making bundle: validate-pkg (in bundles/1.7.0-dev/validate-pkg) Congratulations! "./pkg/..." is safely isolated from internal code. ``` Signed-off-by: Andrew "Tianon" Page --- Makefile | 2 +- hack/make.sh | 1 + hack/make/validate-pkg | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 hack/make/validate-pkg diff --git a/Makefile b/Makefile index aee240acee..628254ce68 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ test-docker-py: build $(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py validate: build - $(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-test validate-toml validate-vet + $(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-pkg validate-test validate-toml validate-vet shell: build $(DOCKER_RUN_DOCKER) bash diff --git a/hack/make.sh b/hack/make.sh index d719f3d830..2d6c7e5160 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -46,6 +46,7 @@ echo DEFAULT_BUNDLES=( validate-dco validate-gofmt + validate-pkg validate-test validate-toml validate-vet diff --git a/hack/make/validate-pkg b/hack/make/validate-pkg new file mode 100644 index 0000000000..d5843417e0 --- /dev/null +++ b/hack/make/validate-pkg @@ -0,0 +1,32 @@ +#!/bin/bash +set -e + +source "${MAKEDIR}/.validate" + +IFS=$'\n' +files=( $(validate_diff --diff-filter=ACMR --name-only -- 'pkg/*.go' || true) ) +unset IFS + +badFiles=() +for f in "${files[@]}"; do + IFS=$'\n' + badImports=( $(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/docker/docker/pkg/' | grep -E '^github.com/docker/docker' || true) ) + unset IFS + + for import in "${badImports[@]}"; do + badFiles+=( "$f imports $import" ) + done +done + +if [ ${#badFiles[@]} -eq 0 ]; then + echo 'Congratulations! "./pkg/..." is safely isolated from internal code.' +else + { + echo 'These files import internal code: (either directly or indirectly)' + for f in "${badFiles[@]}"; do + echo " - $f" + done + echo + } >&2 + false +fi