Repository: uber-go/dig
Pull request #250 (2019-10-30 14:18:44)

Migrate to Go modules
This change migrates Dig to Go modules. This has the effect of
simplifying the Makefile, and allows us to delete the glide.lock. We
will keep the glide.yaml around to provide constraints for our legacy
ecosystem.

Note to reviewers: Each commit is meant to be reviewed individually.

abhinav: Reverted the change we didn't want released. This is ready to review/merge now.

Patch:
diff --git a/.gitignore b/.gitignore
index 2324924..d651c35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/bin
 /vendor
 /.bench
 *.mem
diff --git a/.travis.yml b/.travis.yml
index 7509a5e..8f7ac47 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,17 +2,24 @@ language: go
 sudo: false
 go_import_path: go.uber.org/dig
 
+env:
+  global:
+    - GO111MODULE=on
+
 matrix:
   include:
-    - go: "1.11"
     - go: "1.12"
+    - go: "1.13"
       env: LINT=1
 
-cache:
-  directories:
-    - vendor
 install:
-  - make dependencies
+  - go mod download
+
 script:
-  - test -z "$LINT" && echo "Skipping lint" || make lint
-  - make ci
+  - test -z "$LINT" || make lint
+  - make test
+  - make bench
+
+after_success:
+  - make cover
+  - bash <(curl -s https://codecov.io/bash)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa440e0..e4ceb23 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
-- No changes yet.
+### Changed
+- Migrated to Go modules.
 
 ## [1.7.0] - 2019-01-04
 ### Added
diff --git a/Makefile b/Makefile
index 7f6aeb8..ccd8ec0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,52 +1,47 @@
+export GOBIN ?= $(shell pwd)/bin
+
 BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
-PKGS ?= $(shell glide novendor | grep -v examples)
-PKG_FILES ?= *.go
-GO_VERSION := $(shell go version | cut -d " " -f 3)
+GOLINT = $(GOBIN)/golint
+
+GO_FILES := $(shell \
+	find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
+	-o -name '*.go' -print | cut -b3-)
 
 .PHONY: all
-all: lint test
-
-.PHONY: dependencies
-dependencies:
-	@echo "Installing Glide and locked dependencies..."
-	glide --version || go get -u -f github.com/Masterminds/glide
-	glide install
-	@echo "Installing uber-license tool..."
-	command -v update-license >/dev/null || go get -u -f go.uber.org/tools/update-license
-	@echo "Installing golint..."
-	command -v golint >/dev/null || go get -u -f golang.org/x/lint/golint
-
-.PHONY: license
-license: dependencies
-	./check_license.sh | tee -a lint.log
+all: build lint test
+
+.PHONY: build
+build:
+	go build ./...
 
 .PHONY: lint
-lint:
+lint: $(GOLINT)
 	@rm -rf lint.log
 	@echo "Checking formatting..."
-	@gofmt -d -s $(PKG_FILES) 2>&1 | tee lint.log
-	@echo "Installing test dependencies for vet..."
-	@go test -i $(PKGS)
+	@gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
 	@echo "Checking vet..."
-	@go vet ./...| tee -a lint.log
+	@go vet ./... 2>&1 | tee -a lint.log
 	@echo "Checking lint..."
-	@$(foreach dir,$(PKGS),golint $(dir) 2>&1 | tee -a lint.log;)
+	@$(GOLINT) ./... 2>&1 | tee -a lint.log
 	@echo "Checking for unresolved FIXMEs..."
-	@git grep -i fixme | grep -v -e vendor -e Makefile | tee -a lint.log
+	@git grep -i fixme | grep -v -e Makefile | tee -a lint.log
 	@echo "Checking for license headers..."
-	@DRY_RUN=1 ./check_license.sh | tee -a lint.log
+	@./check_license.sh | tee -a lint.log
 	@[ ! -s lint.log ]
 
+$(GOLINT):
+	go install golang.org/x/lint/golint
+
 .PHONY: test
 test:
-	@.build/test.sh
+	go test -race ./...
 
-.PHONY: ci
-ci: SHELL := /bin/bash
-ci: test
-	bash <(curl -s https://codecov.io/bash)
+.PHONY: cover
+cover:
+	go test -race -coverprofile=cover.out -coverpkg=./... ./...
+	go tool cover -html=cover.out -o cover.html
 
 .PHONY: bench
 BENCH ?= .
 bench:
-	@$(foreach pkg,$(PKGS),go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) $(pkg);)
+	go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS)
diff --git a/check_license.sh b/check_license.sh
index e816285..345ac8b 100755
--- a/check_license.sh
+++ b/check_license.sh
@@ -1,23 +1,17 @@
-#!/bin/bash
+#!/bin/bash -e
 
-set -eo pipefail
+ERROR_COUNT=0
+while read -r file
+do
+	case "$(head -1 "${file}")" in
+		*"Copyright (c) "*" Uber Technologies, Inc.")
+			# everything's cool
+			;;
+		*)
+			echo "$file is missing license header."
+			(( ERROR_COUNT++ ))
+			;;
+	esac
+done < <(git ls-files "*\.go")
 
-run_update_license() {
-  # doing this because of SC2046 warning
-  for file in $(git ls-files | grep '\.go$'); do
-    update-license $@ "${file}"
-  done
-}
-
-if [ -z "${DRY_RUN}" ]; then
-  run_update_license
-else
-  DRY_OUTPUT="$(run_update_license --dry)"
-  if [ -n "${DRY_OUTPUT}" ]; then
-    echo "The following files do not have correct license headers."
-    echo "Please run make license and amend your commit."
-    echo
-    echo "${DRY_OUTPUT}"
-    exit 1
-  fi
-fi
+exit $ERROR_COUNT
diff --git a/glide.lock b/glide.lock
deleted file mode 100644
index f9d2784..0000000
--- a/glide.lock
+++ /dev/null
@@ -1,17 +0,0 @@
-hash: b6270b9f130f8c89f82156ca8d44cb16a3311c7a04746f2805f02c2f72bb58ec
-updated: 2017-10-25T09:30:43.315666535-07:00
-imports: []
-testImports:
-- name: github.com/davecgh/go-spew
-  version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
-  subpackages:
-  - spew
-- name: github.com/pmezard/go-difflib
-  version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
-  subpackages:
-  - difflib
-- name: github.com/stretchr/testify
-  version: d77da356e56a7428ad25149ca77381849a6a5232
-  subpackages:
-  - assert
-  - require
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..5338318
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,9 @@
+module go.uber.org/dig
+
+go 1.13
+
+require (
+	github.com/stretchr/testify v1.4.0
+	golang.org/x/lint v0.0.0-20190930215403-16217165b5de
+	golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab // indirect
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..75d9260
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,24 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
+golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab h1:tpc/nJ4vD66vAk/2KN0sw/DvQIz2sKmCpWvyKtPmfMQ=
+golang.org/x/tools v0.0.0-20191030062658-86caa796c7ab/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/tools.go b/tools.go
new file mode 100644
index 0000000..400f81f
--- /dev/null
+++ b/tools.go
@@ -0,0 +1,27 @@
+// Copyright (c) 2019 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// +build tools
+
+package dig
+
+import (
+	_ "golang.org/x/lint/golint"
+)


Test patch:
diff --git a/.build/test.sh b/.build/test.sh
deleted file mode 100755
index c96ba3a..0000000
--- a/.build/test.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-echo "" > coverage.txt
-
-# aggregate coverage from multiple packages
-for d in $(go list ./... | grep -v vendor); do
-    go test -race -coverprofile=profile.out -covermode=atomic $d
-    if [ -f profile.out ]; then
-        cat profile.out >> coverage.txt
-        rm profile.out
-    fi
-done
diff --git a/dig_test.go b/dig_test.go
index 6790d13..e56006c 100644
--- a/dig_test.go
+++ b/dig_test.go
@@ -864,7 +864,7 @@ func TestEndToEndSuccess(t *testing.T) {
 		err := c.Invoke(func(B) {})
 		require.Error(t, err, "invoking with B param should error out")
 		assertErrorMatches(t, err,
-			`missing dependencies for function "go.uber.org/dig".TestEndToEndSuccess.func\S+ \(\S+/src/go.uber.org/dig/dig_test.go:\d+\):`,
+			`missing dependencies for function "go.uber.org/dig".TestEndToEndSuccess.func\S+ \(\S+/dig_test.go:\d+\):`,
 			"type dig.B is not in the container,",
 			"did you mean to Provide it?",
 		)
diff --git a/internal/digreflect/func_test.go b/internal/digreflect/func_test.go
index a2bdbab..aeba7dc 100644
--- a/internal/digreflect/func_test.go
+++ b/internal/digreflect/func_test.go
@@ -62,56 +62,56 @@ func TestInspectFunc(t *testing.T) {
 			give:           SomeExportedFunction,
 			wantName:       "SomeExportedFunction",
 			wantPackage:    "go.uber.org/dig/internal/digreflect",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/func_test.go",
+			wantFileSuffix: "/internal/digreflect/func_test.go",
 		},
 		{
 			desc:           "unexported function",
 			give:           unexportedFunction,
 			wantName:       "unexportedFunction",
 			wantPackage:    "go.uber.org/dig/internal/digreflect",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/func_test.go",
+			wantFileSuffix: "/internal/digreflect/func_test.go",
 		},
 		{
 			desc:           "nested function",
 			give:           nested1,
 			wantName:       "nestedFunctions.func1",
 			wantPackage:    "go.uber.org/dig/internal/digreflect",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/func_test.go",
+			wantFileSuffix: "/internal/digreflect/func_test.go",
 		},
 		{
 			desc:           "second nested function",
 			give:           nested2,
 			wantName:       "nestedFunctions.func2",
 			wantPackage:    "go.uber.org/dig/internal/digreflect",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/func_test.go",
+			wantFileSuffix: "/internal/digreflect/func_test.go",
 		},
 		{
 			desc:           "nested inside a nested function",
 			give:           nested3,
 			wantName:       "nestedFunctions.func2.1",
 			wantPackage:    "go.uber.org/dig/internal/digreflect",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/func_test.go",
+			wantFileSuffix: "/internal/digreflect/func_test.go",
 		},
 		{
 			desc:           "inside a .git package",
 			give:           myrepository.Hello,
 			wantName:       "Hello",
 			wantPackage:    "go.uber.org/dig/internal/digreflect/tests/myrepository.git",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/tests/myrepository.git/hello.go",
+			wantFileSuffix: "/internal/digreflect/tests/myrepository.git/hello.go",
 		},
 		{
 			desc:           "subpackage of a .git package",
 			give:           mypackage.Add,
 			wantName:       "Add",
 			wantPackage:    "go.uber.org/dig/internal/digreflect/tests/myrepository.git/mypackage",
-			wantFileSuffix: "go.uber.org/dig/internal/digreflect/tests/myrepository.git/mypackage/add.go",
+			wantFileSuffix: "/internal/digreflect/tests/myrepository.git/mypackage/add.go",
 		},
 		{
-			desc:           "vendored dependency",
+			desc:           "dependency",
 			give:           assert.Contains,
 			wantName:       "Contains",
 			wantPackage:    "github.com/stretchr/testify/assert",
-			wantFileSuffix: "go.uber.org/dig/vendor/github.com/stretchr/testify/assert/assertions.go",
+			wantFileSuffix: "/assert/assertions.go",
 		},
 	}
 
@@ -121,7 +121,7 @@ func TestInspectFunc(t *testing.T) {
 			assert.Equal(t, tt.wantName, f.Name, "function name did not match")
 			assert.Equal(t, tt.wantPackage, f.Package, "package name did not match")
 
-			assert.True(t, strings.HasSuffix(f.File, "src/"+tt.wantFileSuffix),
+			assert.True(t, strings.HasSuffix(f.File, tt.wantFileSuffix),
 				"file path %q does not end with src/%v", f.File, tt.wantFileSuffix)
 			assert.Contains(t, f.String(), tt.wantFileSuffix, "file path not in String output")
 		})