Merge pull request #5308 from hashicorp/phinze/doc-vendored-deps

Makefile/docs: Lock in 1.6 req, doc vendored deps
This commit is contained in:
James Nugent 2016-02-24 18:17:23 -05:00
commit 4a24a7701f
4 changed files with 67 additions and 34 deletions

View File

@ -41,15 +41,12 @@ vagrant ssh
# The current "terraform" directory is then sync'd into the gopath # The current "terraform" directory is then sync'd into the gopath
cd /opt/gopath/src/github.com/hashicorp/terraform/ cd /opt/gopath/src/github.com/hashicorp/terraform/
# Fetch dependencies
make updatedeps
# Verify unit tests pass # Verify unit tests pass
make test make test
# Build the release # Build the release
# This generates binaries for each platform and places them in the pkg folder # This generates binaries for each platform and places them in the pkg folder
make release make bin
``` ```
After running these commands, you should have binaries for all supported After running these commands, you should have binaries for all supported

View File

@ -1,4 +1,4 @@
TEST?=$$(GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/) TEST?=$$(go list ./... | grep -v /vendor/)
VETARGS?=-all VETARGS?=-all
default: test vet default: test vet
@ -19,7 +19,7 @@ quickdev: generate
# changes will require a rebuild of everything, in which case the dev # changes will require a rebuild of everything, in which case the dev
# target should be used. # target should be used.
core-dev: fmtcheck generate core-dev: fmtcheck generate
GO15VENDOREXPERIMENT=1 go install github.com/hashicorp/terraform go install github.com/hashicorp/terraform
# Shorthand for quickly testing the core of Terraform (i.e. "not providers") # Shorthand for quickly testing the core of Terraform (i.e. "not providers")
core-test: generate core-test: generate
@ -28,12 +28,12 @@ core-test: generate
# Shorthand for building and installing just one plugin for local testing. # Shorthand for building and installing just one plugin for local testing.
# Run as (for example): make plugin-dev PLUGIN=provider-aws # Run as (for example): make plugin-dev PLUGIN=provider-aws
plugin-dev: fmtcheck generate plugin-dev: fmtcheck generate
GO15VENDOREXPERIMENT=1 go install github.com/hashicorp/terraform/builtin/bins/$(PLUGIN) go install github.com/hashicorp/terraform/builtin/bins/$(PLUGIN)
mv $(GOPATH)/bin/$(PLUGIN) $(GOPATH)/bin/terraform-$(PLUGIN) mv $(GOPATH)/bin/$(PLUGIN) $(GOPATH)/bin/terraform-$(PLUGIN)
# test runs the unit tests # test runs the unit tests
test: fmtcheck generate test: fmtcheck generate
TF_ACC= GO15VENDOREXPERIMENT=1 go test $(TEST) $(TESTARGS) -timeout=30s -parallel=4 TF_ACC= go test $(TEST) $(TESTARGS) -timeout=30s -parallel=4
# testacc runs acceptance tests # testacc runs acceptance tests
testacc: fmtcheck generate testacc: fmtcheck generate
@ -42,30 +42,18 @@ testacc: fmtcheck generate
echo " make testacc TEST=./builtin/providers/aws"; \ echo " make testacc TEST=./builtin/providers/aws"; \
exit 1; \ exit 1; \
fi fi
TF_ACC=1 GO15VENDOREXPERIMENT=1 go test $(TEST) -v $(TESTARGS) -timeout 120m TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
# testrace runs the race checker # testrace runs the race checker
testrace: fmtcheck generate testrace: fmtcheck generate
TF_ACC= GO15VENDOREXPERIMENT=1 go test -race $(TEST) $(TESTARGS) TF_ACC= go test -race $(TEST) $(TESTARGS)
# updatedeps installs all the dependencies that Terraform needs to run
# and build.
updatedeps:
go get -u github.com/mitchellh/gox
go get -u golang.org/x/tools/cmd/stringer
go list ./... \
| xargs go list -f '{{join .Deps "\n"}}' \
| grep -v github.com/hashicorp/terraform \
| grep -v '/internal/' \
| sort -u \
| xargs go get -f -u -v
cover: cover:
@go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \ @go tool cover 2>/dev/null; if [ $$? -eq 3 ]; then \
go get -u golang.org/x/tools/cmd/cover; \ go get -u golang.org/x/tools/cmd/cover; \
fi fi
GO15VENDOREXPERIMENT=1 go test $(TEST) -coverprofile=coverage.out go test $(TEST) -coverprofile=coverage.out
GO15VENDOREXPERIMENT=1 go tool cover -html=coverage.out go tool cover -html=coverage.out
rm coverage.out rm coverage.out
# vet runs the Go source code static analysis tool `vet` to find # vet runs the Go source code static analysis tool `vet` to find
@ -75,7 +63,7 @@ vet:
go get golang.org/x/tools/cmd/vet; \ go get golang.org/x/tools/cmd/vet; \
fi fi
@echo "go tool vet $(VETARGS) ." @echo "go tool vet $(VETARGS) ."
@GO15VENDOREXPERIMENT=1 go tool vet $(VETARGS) $$(ls -d */ | grep -v vendor) ; if [ $$? -eq 1 ]; then \ @go tool vet $(VETARGS) $$(ls -d */ | grep -v vendor) ; if [ $$? -eq 1 ]; then \
echo ""; \ echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \ echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \ echo "and fix them if necessary before submitting the code for review."; \
@ -88,7 +76,7 @@ generate:
@which stringer ; if [ $$? -ne 0 ]; then \ @which stringer ; if [ $$? -ne 0 ]; then \
go get -u golang.org/x/tools/cmd/stringer; \ go get -u golang.org/x/tools/cmd/stringer; \
fi fi
GO15VENDOREXPERIMENT=1 go generate $$(GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/) go generate $$(go list ./... | grep -v /vendor/)
fmt: fmt:
gofmt -w . gofmt -w .

View File

@ -33,10 +33,7 @@ If you wish to work on Terraform itself or any of its built-in providers, you'll
For local dev first make sure Go is properly installed, including setting up a [GOPATH](http://golang.org/doc/code.html#GOPATH). You will also need to add `$GOPATH/bin` to your `$PATH`. Next, install the following software packages, which are needed for some dependencies: For local dev first make sure Go is properly installed, including setting up a [GOPATH](http://golang.org/doc/code.html#GOPATH). You will also need to add `$GOPATH/bin` to your `$PATH`. Next, install the following software packages, which are needed for some dependencies:
- [Git](http://git-scm.com/) Next, using [Git](https://git-scm.com/), clone this repository into `$GOPATH/src/github.com/hashicorp/terraform`. All the necessary dependencies are either vendored or automatically installed, so you just need to type `make`. This will compile the code and then run the tests. If this exits with exit status 0, then everything is working!
- [Mercurial](http://mercurial.selenic.com/)
Next, clone this repository into `$GOPATH/src/github.com/hashicorp/terraform` and run `make`. This will compile dependencies and run the tests. If this exits with exit status 0, then everything is working!
```sh ```sh
$ make $ make
@ -70,6 +67,61 @@ If you're working on the core of Terraform, and only wish to rebuild that withou
$ make core-dev $ make core-dev
``` ```
### Dependencies
Terraform stores its dependencies under `vendor/`, which [Go 1.6+ will automatically recognize and load](https://golang.org/cmd/go/#hdr-Vendor_Directories). We use [`godep`](https://github.com/tools/godep) to manage the vendored dependencies.
If you're developing Terraform, there are a few tasks you might need to perform.
#### Adding a dependency
If you're adding a dependency. You'll need to vendor it in the same Pull Request as the code that depends on it. You should do this in a separate commit from your code, as makes PR review easier and Git history simpler to read in the future.
Because godep captures new dependencies from the local `$GOPATH`, you first need to `godep restore` from the master branch to ensure that the only diff is your new dependency.
Assuming your work is on a branch called `my-feature-branch`, the steps look like this:
```bash
# Get latest master branch's dependencies staged in local $GOPATH
git checkout master
git pull
godep restore -v # flag is optional, enables verbose output
# Capture the new dependency referenced from my-feature-branch
git checkout my-feature-branch
git rebase master
godep save ./...
# There should now be a diff in `vendor/` with added files for your dependency,
# and a diff in Godeps/Godeps.json with metadata for your dependency.
# Make a commit with your new dependencies added
git add -A
git commit -m "vendor: Capture new dependency upstream-pkg"
# Push to your branch (may need -f if you rebased)
git push origin my-feature-branch
```
#### Updating a dependency
If you're updating an existing dependency, godep provides a specific command to snag the newer version from your `$GOPATH`.
```bash
# Update the dependncy to the version currently in your $GOPATH
godep update github.com/some/dependency/...
# There should now be a diff in `vendor/` with changed files for your dependency,
# and a diff in Godeps/Godeps.json with metadata for the updated dependency.
# Make a commit with the updated dependency
git add -A
git commit -m "vendor: Update dependency upstream-pkg to 1.4.6"
# Push to your branch
git push origin my-feature-branch
```
### Acceptance Tests ### Acceptance Tests
Terraform also has a comprehensive [acceptance test](http://en.wikipedia.org/wiki/Acceptance_testing) suite covering most of the major features of the built-in providers. Terraform also has a comprehensive [acceptance test](http://en.wikipedia.org/wiki/Acceptance_testing) suite covering most of the major features of the built-in providers.

View File

@ -18,16 +18,12 @@ GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
XC_ARCH=${XC_ARCH:-"386 amd64 arm"} XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris} XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris}
# Use vendored dependencies
export GO15VENDOREXPERIMENT=1
# Delete the old dir # Delete the old dir
echo "==> Removing old directory..." echo "==> Removing old directory..."
rm -f bin/* rm -f bin/*
rm -rf pkg/* rm -rf pkg/*
mkdir -p bin/ mkdir -p bin/
# If its dev mode, only build for ourself # If its dev mode, only build for ourself
if [ "${TF_DEV}x" != "x" ]; then if [ "${TF_DEV}x" != "x" ]; then
XC_OS=$(go env GOOS) XC_OS=$(go env GOOS)