Skip to content

Commit

Permalink
Use einride/build
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Larsson authored and christian-larsson committed Nov 19, 2018
1 parent bc6596d commit e8b8994
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "build"]
path = build
url = [email protected]:einride/build
91 changes: 14 additions & 77 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,88 +1,25 @@
# -------------
# Makefile
# -------------
#
# This Makefile is designed to run reproducible builds locally (on macOS and
# Linux) and on a CI server. Windows builds are not supported.
.PHONY: all
all: lint-go test
Uname := $(shell uname -s)
uname := $(shell uname -s | tr '[:upper:]' '[:lower:]')
all: go-test test

ifeq ($(Uname),Linux)
else ifeq ($(Uname),Darwin)
else
$(error This Makefile only supports Linux and OSX build agents)
endif

ifneq ($(shell uname -m),x86_64)
$(error This Makefile only supports x86_64 build agents)
endif

# -------------------------------------
# Download vendor dependencies with dep
# -------------------------------------

dep_version := 0.5.0
dep_dir := build/dep/$(dep_version)
dep := $(dep_dir)/dep

$(dep):
mkdir -p $(dep_dir)
curl -s -L https://github.com/golang/dep/releases/download/v$(dep_version)/dep-$(uname)-amd64 -o $(dep_dir)/dep
chmod +x $(dep_dir)/dep
include build/rules.mk
build/rules.mk:
git submodule update --init

vendor: $(dep) Gopkg.toml Gopkg.lock
$(dep) ensure
.PHONY: dep-ensure
dep-ensure: $(DEP)
$(DEP) ensure -v

# -------------------------------
# Lint Go code with GolangCI-Lint
# -------------------------------
golangci_lint_version := 1.10.2
golangci_lint_dir := build/golangci-lint/$(golangci_lint_version)
golangci_lint := $(golangci_lint_dir)/golangci-lint
.PHONY: dep-check
dep-check: $(DEP)
$(DEP) check

$(golangci_lint):
mkdir -p $(golangci_lint_dir)
curl -s -L https://github.com/golangci/golangci-lint/releases/download/v$(golangci_lint_version)/golangci-lint-$(golangci_lint_version)-$(uname)-amd64.tar.gz -o $(golangci_lint_dir)/archive.tar.gz
tar xzf $(golangci_lint_dir)/archive.tar.gz -C $(golangci_lint_dir) --strip 1

.PHONY: default
echo "Enter run-vlp16"

# Check linting
# Maligned disabled in golangci-lint since structs are so large anyway.
# Might want to look at optimising structs in the future.
.PHONY: lint-go
lint-go: vendor $(golangci_lint)
$(golangci_lint) run ./... --enable-all --disable=gas,dupl

# -------------------------------------
# Test
# -------------------------------------
.PHONY: go-test
go-test: $(GOLANGCI_LINT) dep-ensure
$(GOLANGCI_LINT) run --enable-all --disable=dupl

.PHONY: test
test: lint-go
test:
go test -race ./...
# -------------------------------------
# Build
# -------------------------------------

.PHONY: build-vlp16
build-vlp16:
go build ./cmd/vlp16

# -------------------------------------
# Run
# -------------------------------------

.PHONY: run-vlp16
run-vlp16: build-vlp16
./vlp16

# -------------------------------------
# Docs
# -------------------------------------

.PHONY: doc
doc:
Expand Down
1 change: 1 addition & 0 deletions build
Submodule build added at e2bd32
2 changes: 1 addition & 1 deletion cmd/vlp16/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net"

"github.com/einride/vlp-16-go/pkg/vlp16"
"github.com/einride/vlp-16-go"
)

const (
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions pkg/vlp16/packet_test.go → packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"testing"
"time"

"github.com/einride/vlp-16-go/pkg/vlp16"
"github.com/einride/vlp-16-go"
"github.com/stretchr/testify/require"
)

const testDataFile = "../../test/testdata"
const (
testDataFile = "test/testdata"
)

func TestPacket_ReadFrom_TestData(t *testing.T) {
testData, err := os.Open(testDataFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package vlp16

import (
"github.com/pkg/errors"
"time"

"github.com/pkg/errors"
)

type SphericalPointCloud struct {
Expand All @@ -21,7 +22,7 @@ type SphericalPoint struct {
func (cloud *SphericalPointCloud) UnmarshalPacket(packet *Packet) error {
for i := 0; i < len(packet.Blocks); i++ {
if err := cloud.parseBlock(i, packet); err != nil {
return errors.Wrap(err, "Error parsing Block")
return errors.Wrap(err, "error parsing Block")
}
// Duration is in nanoseconds and Velodyne timestamp in microseconds
cloud.Timestamp = time.Duration(packet.Timestamp) * time.Microsecond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func TestLastReflection(t *testing.T) {
test := assert.New(t)

cloud := SphericalPointCloud{}
err := cloud.UnmarshalPacket(&examplePacket)
err := cloud.UnmarshalPacket(&examplePacketLastReflection)
if err != nil {
test.Error(err)
}
test.Equal(cloud.SphericalPoints[0].LastReflection, true)
test.Equal(cloud.SphericalPoints[24].LastReflection, false)
}

var examplePacket = Packet{
var examplePacketLastReflection = Packet{
Blocks: [12]Block{
{
Azimuth: 0x2866,
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions pkg/vlp16/vlp16_test.go → vlp16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
testDataFile = "../../test/testdata"
testDataFile = "test/testdata"
)

func TestInterpolateAzimuth(t *testing.T) {
Expand Down Expand Up @@ -70,4 +69,3 @@ func TestDeg2Rad(t *testing.T) {
test.Equal(deg2Rad(90), math.Pi/2)
test.Equal(deg2Rad(180), math.Pi)
}

0 comments on commit e8b8994

Please sign in to comment.