Skip to content

Commit

Permalink
ELEC-614: Moving to go modules (#35)
Browse files Browse the repository at this point in the history
* ELEC-614: Moving to go modules

* ELEC-614: Updated travis file and readme

* ELEC-614: Updating Makefile

Renaming the packages broken certain aspects of the makefile. As well,
since we're using modules, the go list command now works differently

* ELEC-614: Force module support
  • Loading branch information
mishazharov authored May 1, 2019
1 parent d08b242 commit 63ef01b
Show file tree
Hide file tree
Showing 28 changed files with 174 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ client/src/css/stylesheet.css*
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# Project-local glide vendor files
# Project-local vendor files
/vendor/

# Project-local test and coverage files
Expand Down
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ branches:
os:
- linux

go:
- "1.12"

env:
- GO111MODULE=on

before_install:
- curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
Expand All @@ -17,12 +23,6 @@ cache:
directories:
- "$HOME/.yarn-cache"

install:
- go get -v github.com/Masterminds/glide
- cd $GOPATH/src/github.com/Masterminds/glide && git checkout tags/v0.12.3 && go install
&& cd -
- glide install

before_script:
- nvm install 6
- npm install -g typescript
Expand Down
30 changes: 14 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ GOPATH := ${PWD}/.gopath~
GOBIN := $(GOPATH)/bin
BASE := $(GOPATH)/src/$(PACKAGE)

# Force Go modules to be enabled
export GO111MODULE=on

# use user-given PKG variable
# otherwise do `go list ./...`, but ignore files in vendor/ directory
# TODO: check if this is portable enough, otherwise we might need to rewrite this logic
PKGS = $(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "^$(PACKAGE)/vendor/"))
TESTPKGS = $(shell env GOPATH=$(GOPATH) $(GO) list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))
PKGS = $(or $(PKG),$(shell $(GO) list -m -f "{{ .Path }}" all | grep $(PACKAGE)))
TESTPKGS = $(shell $(GO) list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))

GO = go
GODOC = godoc
GOFMT = gofmt
GLIDE = glide
TIMEOUT = 15
V := 0
Q := $(if $(filter 1,$V),,@)

.PHONY: all
all: fmt lint vendor | $(BASE) ; $(info building executable...) @ ## Build program binary
$Q cd $(BASE) && $(GO) build \
$Q $(GO) build \
-tags release \
-ldflags '-X $(PACKAGE)/cmd.Version=$(VERSION) -X $(PACKAGE)/cmd.BuildDate=$(DATE)' \
-o bin/$(PACKAGE) main.go
Expand All @@ -45,7 +47,8 @@ $(GOBIN)/gocovmerge: | $(BASE) ; $(info building gocovmerge...)
$Q go get github.com/wadey/gocovmerge

GOCOV = $(GOBIN)/gocov
$(GOBIN)/gocov: | $(BASE) ; $(info building gocov...)
$(GOBIN)/gocov: | $(BASE) ; $(info building gocov...) @ ## Hack: https://github.com/golang/go/issues/27215#issuecomment-451342769
$Q go get github.com/axw/gocov
$Q go get github.com/axw/gocov/...

GOCOVXML = $(GOBIN)/gocov-xml
Expand Down Expand Up @@ -94,10 +97,10 @@ test-coverage-tools: | $(GOCOVMERGE) $(GOCOV) $(GOCOVXML)
test-coverage: COVERAGE_DIR := $(CURDIR)/test/coverage.$(shell date +%F_%H-%M-%S)
test-coverage: fmt lint vendor test-coverage-tools | $(BASE) ; $(info running coverage tests...) @ ## Run coverage tests
$Q mkdir -p $(COVERAGE_DIR)/coverage
$Q cd $(BASE) && for pkg in $(TESTPKGS); do \
$Q for pkg in $(TESTPKGS); do \
$(GO) test \
-coverpkg=$$($(GO) list -f '{{ join .Deps "\n" }}' $$pkg | \
grep '^$(PACKAGE)/' | grep -v '^$(PACKAGE)/vendor/' | \
grep '$(PACKAGE)/' | grep -v '$(PACKAGE)/vendor/' | \
tr '\n' ',')$$pkg \
-covermode=$(COVERAGE_MODE) \
-coverprofile="$(COVERAGE_DIR)/coverage/`echo $$pkg | tr "/" "-"`.cover" $$pkg || exit 1; \
Expand All @@ -108,7 +111,7 @@ test-coverage: fmt lint vendor test-coverage-tools | $(BASE) ; $(info running co

.PHONY: lint
lint: vendor | $(BASE) $(GOLINT) ; $(info running golint...) @ ## Run golint
$Q cd $(BASE) && ret=0 && for pkg in $(PKGS); do \
$Q ret=0 && for pkg in $(PKGS); do \
test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \
done ; exit $$ret

Expand All @@ -118,17 +121,11 @@ fmt: ; $(info running gofmt...) @ ## Run gofmt on all source files
$(GOFMT) -l -w $$d/*.go || ret=$$? ; \
done ; exit $$ret


#########################
# Dependency management #
#########################
glide.lock: glide.yaml | $(BASE) ; $(info updating dependencies...)
$Q cd $(BASE) && $(GLIDE) update
@touch $@
vendor: glide.lock | $(BASE) ; $(info retrieving dependencies...)
$Q cd $(BASE) && $(GLIDE) --quiet install
@ln -sf . vendor/src
@touch $@
vendor: | $(BASE) ; $(info retrieving dependencies...)
$(GO) mod vendor


#################
Expand All @@ -139,6 +136,7 @@ clean: ; $(info cleaning...) @ ## Cleanup everything
@rm -rf $(GOPATH)
@rm -rf bin
@rm -rf test/tests.* test/coverage.*
@rm -rf vendor

.PHONY: help
help:
Expand Down
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,12 @@ export GOPATH=$HOME/shared/go

If you haven't changed the shell, you will also need to edit the GOPATH in your Bash profile. In `~/.bashrc`, locate the line near the bottom of the file that starts with `export GOPATH=`, and modify the line to say `export GOPATH=/home/vagrant/shared/go`.

We use [Glide](https://github.com/Masterminds/glide) to manage vendored
dependencies.

When installing Glide, it may complain that you do not have a `bin` folder in your $GOPATH. Rectify this by creating a bin folder, setting $GOBIN, then adding it to your path.

```bash
cd $GOPATH && mkdir bin
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
```

Once you've installed Glide, get and compile the code.
Once you've set up the GOPATH variable, get and compile the code. Please note that since we're using [go modules](https://github.com/golang/go/wiki/Modules) for dependency management, the telemetry repository should not be located under GOPATH.

```bash
go get -d github.com/uw-midsun/telemetry
cd $GOPATH/src/github.com/uw-midsun/telemetry
cd ~/shared
git clone https://github.com/uw-midsun/telemetry.git
cd telemetry
make
```

Expand Down
38 changes: 0 additions & 38 deletions glide.lock

This file was deleted.

12 changes: 0 additions & 12 deletions glide.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module github.com/uw-midsun/telemetry

go 1.12

require (
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737 // indirect
github.com/axw/gocov v0.0.0-20170322000131-3a69a0d2a4ef // indirect
github.com/go-chi/chi v0.0.0-20170216185340-5917107c1cec // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v0.0.0-20180612185929-5831880292e7 // indirect
github.com/gorilla/websocket v0.0.0-20170218162710-3f3e394da2b8 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4 // indirect
github.com/mattn/go-sqlite3 v0.0.0-20170305140206-eac1dfa2a61e // indirect
github.com/mrVanboy/go-simple-cobs v0.0.0-20180102074149-bc19984395e8 // indirect
github.com/pkg/errors v0.0.0-20161029093637-248dadf4e906 // indirect
github.com/spf13/cobra v0.0.0-20170217164507-ee4055870c2d // indirect
github.com/spf13/pflag v0.0.0-20160820154156-103ce5cd2042 // indirect
github.com/uw-midsun/telemetry/pkg/canmsgdefs v0.0.0 // indirect
github.com/uw-midsun/telemetry/pkg/cli v0.0.0
github.com/uw-midsun/telemetry/pkg/db v0.0.0 // indirect
github.com/uw-midsun/telemetry/pkg/msgs v0.0.0 // indirect
github.com/uw-midsun/telemetry/pkg/protos v0.0.0-00010101000000-000000000000 // indirect
github.com/uw-midsun/telemetry/pkg/pubsub v0.0.0-00010101000000-000000000000 // indirect
github.com/uw-midsun/telemetry/pkg/sources/fake v0.0.0-00010101000000-000000000000 // indirect
github.com/uw-midsun/telemetry/pkg/sources/serial v0.0.0-00010101000000-000000000000 // indirect
github.com/uw-midsun/telemetry/pkg/util/randutil v0.0.0-00010101000000-000000000000 // indirect
github.com/uw-midsun/telemetry/pkg/ws v0.0.0-00010101000000-000000000000 // indirect
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad // indirect
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
golang.org/x/sync v0.0.0-20190412183630-56d357773e84 // indirect
)

replace github.com/uw-midsun/telemetry/pkg/cli => ./pkg/cli

replace github.com/uw-midsun/telemetry/pkg/db => ./pkg/db

replace github.com/uw-midsun/telemetry/pkg/msgs => ./pkg/msgs

replace github.com/uw-midsun/telemetry/pkg/canmsgdefs => ./pkg/canmsgdefs

replace github.com/uw-midsun/telemetry/pkg/protos => ./pkg/protos

replace github.com/uw-midsun/telemetry/pkg/pubsub => ./pkg/pubsub

replace github.com/uw-midsun/telemetry/pkg/sources/fake => ./pkg/sources/fake

replace github.com/uw-midsun/telemetry/pkg/sources/serial => ./pkg/sources/serial

replace github.com/uw-midsun/telemetry/pkg/util/randutil => ./pkg/util/randutil

replace github.com/uw-midsun/telemetry/pkg/ws => ./pkg/ws
44 changes: 44 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737 h1:JZHBkt0GhM+ARQykshqpI49yaWCHQbJonH3XpDTwMZQ=
github.com/AlekSi/gocov-xml v0.0.0-20190121064608-3a14fb1c4737/go.mod h1:w1KSuh2JgIL3nyRiZijboSUwbbxOrTzWwyWVFUHtXBQ=
github.com/axw/gocov v0.0.0-20170322000131-3a69a0d2a4ef h1:kh7Fi8sfEY7aCl42VEEvGv7lez2YCOmO120N1fASWGc=
github.com/axw/gocov v0.0.0-20170322000131-3a69a0d2a4ef/go.mod h1:pc6XrbIn8RLeVSNzXCZKXNst+RTE5Ju/nySYl1Wc0B4=
github.com/go-chi/chi v0.0.0-20170216185340-5917107c1cec h1:vtn7pnCfgrvNi3h1CcUgwtJ0DN1PCGGudfGDotR2Iks=
github.com/go-chi/chi v0.0.0-20170216185340-5917107c1cec/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/protobuf v0.0.0-20180612185929-5831880292e7 h1:swaFJZm8TbtHskgBqkrUK1Q5W6l0yKZSh5jlHaA9ldQ=
github.com/golang/protobuf v0.0.0-20180612185929-5831880292e7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gorilla/websocket v0.0.0-20170218162710-3f3e394da2b8 h1:UrjxDZdgSDgal3gEEH1Ug7EHBIuYln8lSN7rwNkkLlI=
github.com/gorilla/websocket v0.0.0-20170218162710-3f3e394da2b8/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4 h1:G2ztCwXov8mRvP0ZfjE6nAlaCX2XbykaeHdbT6KwDz0=
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4/go.mod h1:2RvX5ZjVtsznNZPEt4xwJXNJrM3VTZoQf7V6gk0ysvs=
github.com/mattn/go-sqlite3 v0.0.0-20170305140206-eac1dfa2a61e h1:AI4kVwkgPj55D76TxcJHTNl3y7TiOZ0IDpEiwunOexI=
github.com/mattn/go-sqlite3 v0.0.0-20170305140206-eac1dfa2a61e/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mrVanboy/go-simple-cobs v0.0.0-20180102074149-bc19984395e8 h1:6e7FpwhHlRWVOOHiFTpajP0EHNYFLDw54ZMlx2mmdGk=
github.com/mrVanboy/go-simple-cobs v0.0.0-20180102074149-bc19984395e8/go.mod h1:EPw4BDT6S3WhWibsK568dLX1jNY76uo/JGIAeef4sBM=
github.com/pkg/errors v0.0.0-20161029093637-248dadf4e906 h1:aXc/AM323HlkOXjl3QuSO06wbXK45HrzBT+pwVOufXg=
github.com/pkg/errors v0.0.0-20161029093637-248dadf4e906/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/cobra v0.0.0-20170217164507-ee4055870c2d h1:ypp9F1Q6OvwCUqqlgX/6E8FOzcJLwVJR5P0bVW9V8AU=
github.com/spf13/cobra v0.0.0-20170217164507-ee4055870c2d/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v0.0.0-20160820154156-103ce5cd2042 h1:VWlVV19lRdqmaPmY4E9ZPm1jN+7q6AUdRaKZG5HO5zw=
github.com/spf13/pflag v0.0.0-20160820154156-103ce5cd2042/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad h1:W0LEBv82YCGEtcmPA3uNZBI33/qF//HAAs3MawDjRa0=
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad/go.mod h1:Hy8o65+MXnS6EwGElrSRjUzQDLXreJlzYLlWiHtt8hM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20170308210134-a6577fac2d73 h1:5kGFsglTK4KqaHYb/WCmYmj+Gm1+dzbilbtzruHj6dw=
golang.org/x/net v0.0.0-20170308210134-a6577fac2d73/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84 h1:IqXQ59gzdXv58Jmm2xn0tSOR9i6HqroaOFRQ3wR/dJQ=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43 h1:PvnWIWTbA7gsEBkKjt0HV9hckYfcqYv8s/ju7ArZ0do=
golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
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=
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"flag"
"telemetry/pkg/cli"
"github.com/uw-midsun/telemetry/pkg/cli"
)

func main() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/canmsgdefs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module canmsgdefs

go 1.12
3 changes: 3 additions & 0 deletions pkg/cli/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module cli

go 1.12
10 changes: 5 additions & 5 deletions pkg/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"os/exec"
"path/filepath"

"github.com/go-chi/chi"
log "github.com/golang/glog"
"github.com/pressly/chi"
"github.com/spf13/cobra"

"telemetry/pkg/db"
"telemetry/pkg/msgs"
"telemetry/pkg/pubsub"
"telemetry/pkg/ws"
"github.com/uw-midsun/telemetry/pkg/db"
"github.com/uw-midsun/telemetry/pkg/msgs"
"github.com/uw-midsun/telemetry/pkg/pubsub"
"github.com/uw-midsun/telemetry/pkg/ws"
)

var startCmd = &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/can_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
log "github.com/golang/glog"
_ "github.com/mattn/go-sqlite3" // DB impl

"telemetry/pkg/msgs"
"telemetry/pkg/pubsub"
"github.com/uw-midsun/telemetry/pkg/msgs"
"github.com/uw-midsun/telemetry/pkg/pubsub"
)

// RunDb creates a table and sinks all "CAN" pubsub messages into it via the WriteMsg method.
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/can_db_linux_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

log "github.com/golang/glog"

"telemetry/pkg/msgs"
"telemetry/pkg/pubsub"
"github.com/uw-midsun/telemetry/pkg/msgs"
"github.com/uw-midsun/telemetry/pkg/pubsub"
)

// RunDb on ARM uses a logfile since there is no sqlite driver for armeabi-v7a.
Expand Down
3 changes: 3 additions & 0 deletions pkg/db/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module candb

go 1.12
2 changes: 1 addition & 1 deletion pkg/db/sql_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"time"

"telemetry/pkg/msgs"
"github.com/uw-midsun/telemetry/pkg/msgs"
)

// WriteMsg commits a CAN message to the database.
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/sql_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package candb
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
"telemetry/pkg/msgs"
"github.com/uw-midsun/telemetry/pkg/msgs"
"testing"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/msgs/can_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
log "github.com/golang/glog"
"github.com/golang/protobuf/proto"

canpb "telemetry/pkg/protos"
canpb "github.com/uw-midsun/telemetry/pkg/protos"
)

// CAN describes a single message from the CAN bus. This assumes network layer CAN! ID is the
Expand Down
3 changes: 3 additions & 0 deletions pkg/msgs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module msgs

go 1.12
3 changes: 3 additions & 0 deletions pkg/protos/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module protos

go 1.12
Loading

0 comments on commit 63ef01b

Please sign in to comment.