Browse code

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 <admwiggin@gmail.com>

Tianon Gravi authored on 2015/06/13 04:19:56
Showing 3 changed files
... ...
@@ -78,7 +78,7 @@ test-docker-py: build
78 78
 	$(DOCKER_RUN_DOCKER) hack/make.sh binary test-docker-py
79 79
 
80 80
 validate: build
81
-	$(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-test validate-toml validate-vet
81
+	$(DOCKER_RUN_DOCKER) hack/make.sh validate-dco validate-gofmt validate-pkg validate-test validate-toml validate-vet
82 82
 
83 83
 shell: build
84 84
 	$(DOCKER_RUN_DOCKER) bash
... ...
@@ -46,6 +46,7 @@ echo
46 46
 DEFAULT_BUNDLES=(
47 47
 	validate-dco
48 48
 	validate-gofmt
49
+	validate-pkg
49 50
 	validate-test
50 51
 	validate-toml
51 52
 	validate-vet
52 53
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+#!/bin/bash
1
+set -e
2
+
3
+source "${MAKEDIR}/.validate"
4
+
5
+IFS=$'\n'
6
+files=( $(validate_diff --diff-filter=ACMR --name-only -- 'pkg/*.go' || true) )
7
+unset IFS
8
+
9
+badFiles=()
10
+for f in "${files[@]}"; do
11
+	IFS=$'\n'
12
+	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) )
13
+	unset IFS
14
+
15
+	for import in "${badImports[@]}"; do
16
+		badFiles+=( "$f imports $import" )
17
+	done
18
+done
19
+
20
+if [ ${#badFiles[@]} -eq 0 ]; then
21
+	echo 'Congratulations! "./pkg/..." is safely isolated from internal code.'
22
+else
23
+	{
24
+		echo 'These files import internal code: (either directly or indirectly)'
25
+		for f in "${badFiles[@]}"; do
26
+			echo " - $f"
27
+		done
28
+		echo
29
+	} >&2
30
+	false
31
+fi