Refactoring and first steps to make multi OS compatible.

- Using cgofuse to be compatible with multiple OSes
- Refactor to make possible better testing
- Add a bunch of tests
- Add code coverage

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-09-27 21:23:47 +02:00
parent 89af681694
commit 45f10e2f81
27 changed files with 1291 additions and 440 deletions

View file

@ -5,11 +5,15 @@ BUILD := $(shell git rev-parse --short HEAD)
PROJECTNAME := $(shell basename "$(PWD)")
# Use linker flags to provide version/build settings
LDFLAGS=-ldflags "-X=main.Version=$(VERSION) -X=main.Build=$(BUILD)"
LDFLAGS=-X=main.Version=$(VERSION) -X=main.Build=$(BUILD) -linkmode external
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent
GOPATH=~/go
ORGPATH=$(GOPATH)/src/github.com/distribyted
REPOPATH=$(ORGPATH)/distribyted
## run: run from code.
run:
go run cmd/distribyted/main.go examples/conf_example.yaml
@ -19,13 +23,13 @@ build: go-generate go-build
## test: execute all tests.
test:
go test -v ./...
go test -v --race -coverprofile=coverage.out ./...
compile: go-generate go-compile
go-build:
@echo " > Building binary..."
go build $(LDFLAGS) -o bin/distribyted -tags "release" cmd/distribyted/main.go
go build -o bin/distribyted -tags "release" cmd/distribyted/main.go
go-generate:
@echo " > Generating code files..."
@ -33,23 +37,17 @@ go-generate:
go-compile:
@echo " > Compiling for several platforms..."
# 32-Bit Systems
# FreeBDS
#GOOS=freebsd GOARCH=386 go build $(LDFLAGS) -o bin/main-freebsd-386 -tags "release" cmd/distribyted/main.go
# MacOS
#GOOS=darwin GOARCH=386 go build $(LDFLAGS) -o bin/main-darwin-386 -tags "release" cmd/distribyted/main.go
# Linux
GOOS=linux GOARCH=386 go build $(LDFLAGS) -o bin/distribyted-linux-386 -tags "release" cmd/distribyted/main.go
# 64-Bit
# FreeBDS
#GOOS=freebsd GOARCH=amd64 go build $(LDFLAGS) -o bin/main-freebsd-amd64 -tags "release" cmd/distribyted/main.go
# MacOS
#GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o bin/main-darwin-amd64 -tags "release" cmd/distribyted/main.go
# Linux
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o bin/distribyted-linux-amd64 -tags "release" cmd/distribyted/main.go
# ARM
GOOS=linux GOARCH=arm GOARM=5 go build $(LDFLAGS) -o bin/distribyted-linux-arm -tags "release" cmd/distribyted/main.go
go get src.techknowlogick.com/xgo
docker pull billziss/xgo-cgofuse
mkdir -p $(ORGPATH)
ln -sfrnT . $(REPOPATH)
@echo " > Compiling for windows..."
GOPATH=$(GOPATH) xgo -out bin/distribyted-$(VERSION) -image=billziss/xgo-cgofuse -ldflags='-extldflags "-static" $(LDFLAGS)' -tags="release" -targets=windows/* $(REPOPATH)/cmd/distribyted/
@echo " > Compiling for linux..."
GOPATH=$(GOPATH) xgo -out bin/distribyted-$(VERSION) -image=billziss/xgo-cgofuse -ldflags='$(LDFLAGS)' -tags="release" -targets=linux/arm-7,linux/amd64,linux/386 $(REPOPATH)/cmd/distribyted/
@echo " > Compiling for darwin..."
GOPATH=$(GOPATH) xgo -out bin/distribyted-$(VERSION) -image=billziss/xgo-cgofuse -ldflags='$(LDFLAGS)' -tags="release" -targets=darwin/* $(REPOPATH)/cmd/distribyted/
.PHONY: help
all: help