Switch to Go modules (#56)

This switches atomic to Go modules. This has the effect of simplifying
the Makefile and the Travis build, as well as getting rid of the overly
complicated coverage script we copied here.

Tools dependencies (currently only golint) were added to the tools.go.

As a result of this change, we no longer support the non-vanity import path
github.com/uber-go/atomic. Users must use the vanity import path, or add a
`replace` directive.

Supersedes #40
This commit is contained in:
Abhinav Gupta
2019-10-29 15:04:38 -07:00
committed by GitHub
parent 187d219e0c
commit 473b9563f0
12 changed files with 115 additions and 138 deletions

3
.gitignore vendored
View File

@@ -1,6 +1,7 @@
/bin
.DS_Store .DS_Store
/vendor /vendor
/cover cover.html
cover.out cover.out
lint.log lint.log

View File

@@ -2,26 +2,26 @@ sudo: false
language: go language: go
go_import_path: go.uber.org/atomic go_import_path: go.uber.org/atomic
go: env:
- 1.11.x global:
- 1.12.x - GO111MODULE=on
matrix: matrix:
include: include:
- go: 1.12.x - go: 1.12.x
env: NO_TEST=yes LINT=yes - go: 1.13.x
env: LINT=1
cache: cache:
directories: directories:
- vendor - vendor
install: before_install:
- make install_ci - go version
script: script:
- test -n "$NO_TEST" || make test_ci - test -z "$LINT" || make lint
- test -n "$NO_TEST" || scripts/test-ubergo.sh - make cover
- test -z "$LINT" || make install_lint lint
after_success: after_success:
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)

View File

@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Changed
- With Go modules, only the `go.uber.org/atomic` import path is supported now.
If you need to use the old import path, please add a `replace` directive to
your `go.mod`.
## [1.4.0] - 2019-05-01 ## [1.4.0] - 2019-05-01
### Added ### Added
- Add `atomic.Error` type for atomic operations on `error` values. - Add `atomic.Error` type for atomic operations on `error` values.

View File

@@ -1,51 +1,35 @@
# Many Go tools take file globs or directories as arguments instead of packages. # Directory to place `go install`ed binaries into.
PACKAGE_FILES ?= *.go export GOBIN ?= $(shell pwd)/bin
# For pre go1.6 GOLINT = $(GOBIN)/golint
export GO15VENDOREXPERIMENT=1
GO_FILES ?= *.go
.PHONY: build .PHONY: build
build: build:
go build -i ./... go build ./...
.PHONY: install
install:
glide --version || go get github.com/Masterminds/glide
glide install
.PHONY: test .PHONY: test
test: test:
go test -cover -race ./... go test -race ./...
.PHONY: gofmt
gofmt:
$(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX))
gofmt -e -s -l $(GO_FILES) > $(FMT_LOG) || true
@[ ! -s "$(FMT_LOG)" ] || (echo "gofmt failed:" && cat $(FMT_LOG) && false)
.PHONY: install_ci $(GOLINT):
install_ci: install go install golang.org/x/lint/golint
go get github.com/wadey/gocovmerge
go get github.com/mattn/goveralls
go get golang.org/x/tools/cmd/cover
.PHONY: install_lint
install_lint:
go get golang.org/x/lint/golint
.PHONY: golint
golint: $(GOLINT)
$(GOLINT) ./...
.PHONY: lint .PHONY: lint
lint: lint: gofmt golint
@rm -rf lint.log
@echo "Checking formatting..."
@gofmt -d -s $(PACKAGE_FILES) 2>&1 | tee lint.log
@echo "Checking vet..."
@go vet ./... 2>&1 | tee -a lint.log
@echo "Checking lint..."
@golint $$(go list ./...) 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
@[ ! -s lint.log ]
.PHONY: cover
.PHONY: test_ci cover:
test_ci: install_ci build go test -coverprofile=cover.out -coverpkg ./... -v ./...
./scripts/cover.sh $(shell go list $(PACKAGES)) go tool cover -html=cover.out -o cover.html

View File

@@ -3,9 +3,22 @@
Simple wrappers for primitive types to enforce atomic access. Simple wrappers for primitive types to enforce atomic access.
## Installation ## Installation
`go get -u go.uber.org/atomic`
```shell
$ go get -u go.uber.org/atomic@v1
```
Note: If you are using Go modules, this package will fail to compile with the
import path `github.com/uber-go/atomic`. To continue using that import path,
you will have to add a `replace` directive to your `go.mod`, replacing
`github.com/uber-go/atomic` with `go.uber.org/atomic`.
```shell
$ go mod edit -replace github.com/uber-go/atomic=go.uber.org/atomic@v1
```
## Usage ## Usage
The standard library's `sync/atomic` is powerful, but it's easy to forget which The standard library's `sync/atomic` is powerful, but it's easy to forget which
variables must be accessed atomically. `go.uber.org/atomic` preserves all the variables must be accessed atomically. `go.uber.org/atomic` preserves all the
functionality of the standard library, but wraps the primitive types to functionality of the standard library, but wraps the primitive types to
@@ -21,9 +34,11 @@ atom.CAS(40, 11)
See the [documentation][doc] for a complete API specification. See the [documentation][doc] for a complete API specification.
## Development Status ## Development Status
Stable. Stable.
___ ---
Released under the [MIT License](LICENSE.txt). Released under the [MIT License](LICENSE.txt).
[doc-img]: https://godoc.org/github.com/uber-go/atomic?status.svg [doc-img]: https://godoc.org/github.com/uber-go/atomic?status.svg

17
glide.lock generated
View File

@@ -1,17 +0,0 @@
hash: f14d51408e3e0e4f73b34e4039484c78059cd7fc5f4996fdd73db20dc8d24f53
updated: 2016-10-27T00:10:51.16960137-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

View File

@@ -1,6 +0,0 @@
package: go.uber.org/atomic
testImport:
- package: github.com/stretchr/testify
subpackages:
- assert
- require

10
go.mod Normal file
View File

@@ -0,0 +1,10 @@
module go.uber.org/atomic
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/lint v0.0.0-20190930215403-16217165b5de
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c // indirect
)
go 1.13

22
go.sum Normal file
View File

@@ -0,0 +1,22 @@
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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/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.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
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-20191029041327-9cc4af7d6b2c h1:IGkKhmfzcztjm6gYkykvu/NiS8kaqbCWAEWWAyf8J5U=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@@ -1,40 +0,0 @@
#!/bin/bash
set -e
COVER=cover
ROOT_PKG=go.uber.org/atomic
if [[ -d "$COVER" ]]; then
rm -rf "$COVER"
fi
mkdir -p "$COVER"
i=0
for pkg in "$@"; do
i=$((i + 1))
extracoverpkg=""
if [[ -f "$GOPATH/src/$pkg/.extra-coverpkg" ]]; then
extracoverpkg=$( \
sed -e "s|^|$pkg/|g" < "$GOPATH/src/$pkg/.extra-coverpkg" \
| tr '\n' ',')
fi
coverpkg=$(go list -json "$pkg" | jq -r '
.Deps
| map(select(startswith("'"$ROOT_PKG"'")))
| map(select(contains("/vendor/") | not))
| . + ["'"$pkg"'"]
| join(",")
')
if [[ -n "$extracoverpkg" ]]; then
coverpkg="$extracoverpkg$coverpkg"
fi
go test \
-coverprofile "$COVER/cover.${i}.out" -coverpkg "$coverpkg" \
-v "$pkg"
done
gocovmerge "$COVER"/*.out > cover.out

View File

@@ -1,26 +0,0 @@
#!/bin/bash
set -euox pipefail
IFS=$'\n\t'
# This script creates a fake GOPATH, symlinks in the current
# directory as uber-go/atomic and verifies that tests still pass.
WORK_DIR=`mktemp -d`
function cleanup {
rm -rf "$WORK_DIR"
}
trap cleanup EXIT
export GOPATH="$WORK_DIR"
PKG_PARENT="$WORK_DIR/src/github.com/uber-go"
PKG_DIR="$PKG_PARENT/atomic"
mkdir -p "$PKG_PARENT"
cp -R `pwd` "$PKG_DIR"
cd "$PKG_DIR"
# The example imports go.uber.org, fix the import.
sed -e 's/go.uber.org\/atomic/github.com\/uber-go\/atomic/' -i="" example_test.go
make test

28
tools.go Normal file
View File

@@ -0,0 +1,28 @@
// 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 atomic
import (
// Tools used during development.
_ "golang.org/x/lint/golint"
)