Skip to content

Commit

Permalink
Use Makefile dependencies to manage builds. Also build in build infor…
Browse files Browse the repository at this point in the history
…mation into the binary
  • Loading branch information
olabiniV2 committed Apr 29, 2020
1 parent 4238b61 commit e26479a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ current-short-git-version
/mumble
packaging/ubuntu/ubuntu/DEBIAN/control
publish-linux-packages/wahay*
/.build-tools
62 changes: 41 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
GTK_VERSION=$(shell pkg-config --modversion gtk+-3.0 | tr . _ | cut -d '_' -f 1-2)
GTK_BUILD_TAG="gtk_$(GTK_VERSION)"

GIT_VERSION=$(shell git rev-parse HEAD)
GIT_SHORT_VERSION=$(shell git rev-parse --short HEAD)
TAG_VERSION=$(shell git tag -l --contains $$GIT_VERSION | tail -1)
CURRENT_DATE=$(shell date "+%Y-%m-%d")
GIT_VERSION := $(shell git rev-parse HEAD)
GIT_SHORT_VERSION := $(shell git rev-parse --short HEAD)
TAG_VERSION := $(shell git tag -l --contains $$GIT_VERSION | tail -1)
CURRENT_DATE := $(shell date "+%Y-%m-%d")
BUILD_TIMESTAMP := $(shell TZ='America/Guayaquil' date '+%Y-%m-%d %H:%M:%S')

GOPATH_SINGLE=$(shell echo $${GOPATH%%:*})

BUILD_DIR=bin
BUILD_DIR := bin
BUILD_TOOLS_DIR := .build-tools

.PHONY: default check-deps gen-ui-defs deps optional-deps test test-clean run-coverage clean-cover cover cover-ci build build-ci lint gosec ineffassign vet errcheck golangci-lint quality all clean
PKGS := $(shell go list ./... | grep -v /vendor)
SRC_DIRS := . $(addprefix .,$(subst github.com/digitalautonomy/wahay,,$(PKGS)))
SRC_TEST := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*_test.go))
SRC_ALL := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.go))
SRC := $(filter-out $(SRC_TEST), $(SRC_ALL))

default: gen-ui-defs build
.PHONY: default check-deps gen-ui-defs deps optional-deps test test-clean run-coverage clean-cover cover cover-ci build-ci lint gosec ineffassign vet errcheck golangci-lint quality all clean

check-deps:
@type esc >/dev/null 2>&1 || (echo "The program 'esc' is required but not available. Please install it by running 'make deps'." && exit 1)

gen-ui-defs: check-deps
cd gui && make generate-ui
default: build

gen-ui-locale: check-deps
gen-ui-locale:
cd gui && make generate-locale

gen-client-files: check-deps
cd client && make

deps:
go get -u github.com/modocache/gover
go get -u github.com/rosatolen/esc
Expand Down Expand Up @@ -61,16 +60,37 @@ cover-ci: run-coverage
go tool cover -html=.coverprofiles/gover.coverprofile -o coverage.html
go tool cover -func=.coverprofiles/gover.coverprofile

build:
go build -i -tags $(GTK_BUILD_TAG) -o $(BUILD_DIR)/wahay
$(BUILD_DIR)/wahay: gui/definitions.go client/gen_client_files.go $(SRC)
go build -ldflags "-X 'main.BuildTimestamp=$(BUILD_TIMESTAMP)' -X 'main.BuildCommit=$(GIT_VERSION)' -X 'main.BuildShortCommit=$(GIT_SHORT_VERSION)' -X 'main.Build=$(TAG_VERSION)'" -i -tags $(GTK_BUILD_TAG) -o $(BUILD_DIR)/wahay

build-ci:
build: $(BUILD_DIR)/wahay

build-ci: $(BUILD_DIR)/wahay
ifeq ($(TAG_VERSION),)
go build -i -tags $(GTK_BUILD_TAG) -o $(BUILD_DIR)/wahay-$(CURRENT_DATE)-$(GIT_SHORT_VERSION)
cp $(BUILD_DIR)/wahay $(BUILD_DIR)/wahay-$(CURRENT_DATE)-$(GIT_SHORT_VERSION)
else
go build -i -tags $(GTK_BUILD_TAG) -o $(BUILD_DIR)/wahay-$(TAG_VERSION)-$(GIT_SHORT_VERSION)
cp $(BUILD_DIR)/wahay $(BUILD_DIR)/wahay-$(TAG_VERSION)-$(GIT_SHORT_VERSION)
endif


clean:
$(RM) -rf $(BUILD_DIR)/wahay
$(RM) -rf $(BUILD_TOOLS_DIR)

$(BUILD_TOOLS_DIR):
mkdir -p $@

$(BUILD_TOOLS_DIR)/esc: $(BUILD_TOOLS_DIR)
@type esc >/dev/null 2>&1 || (echo "The program 'esc' is required but not available. Please install it by running 'make deps'." && exit 1)
@cp `which esc` $(BUILD_TOOLS_DIR)/esc

client/gen_client_files.go: $(BUILD_TOOLS_DIR)/esc client/files/* client/files/.*
(cd client; go generate -x client.go)

gui/definitions.go: $(BUILD_TOOLS_DIR)/esc gui/definitions/* gui/styles/* gui/images/* gui/images/help/* gui/config_files/*
(cd gui; go generate -x ui_reader.go)


# QUALITY TOOLS

lint:
Expand Down
2 changes: 0 additions & 2 deletions client/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package client

//go:generate esc -o gen_client_files.go -pkg client -ignore "Makefile" files
//go:generate ../.build-tools/esc -o gen_client_files.go -pkg client -ignore "Makefile" files

import (
"errors"
Expand Down
9 changes: 4 additions & 5 deletions client/gen_client_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var _escData = map[string]*_escFile{
"/files/.mumble.sqlite": {
local: "files/.mumble.sqlite",
size: 122880,
modtime: 1585838734,
modtime: 1588190338,
compressed: `
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAKAAAAB4AAAAAAAAAAAAAACMAAAAEAAAAAAAAAAAAAAAB
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAC4csA0AAAAdA58ADzkO5w6HDjINvA0Z
Expand Down Expand Up @@ -2240,17 +2240,16 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

"/files/mumble.ini": {
local: "files/mumble.ini",
size: 426,
modtime: 1585932512,
size: 412,
modtime: 1588192130,
compressed: `
IyBNdW1ibGUgY29uZmlndXJhdGlvbiB0byBiZSB1c2VkIGluIFdhaGF5CltHZW5lcmFsXQpsYXN0dXBk
YXRlPTIKCltuZXRdCnRjcG9ubHk9dHJ1ZQojQ0VSVElGSUNBVEUKCltvdmVybGF5XQplbmFibGU9ZmFs
c2UKdmVyc2lvbj0xLjMuMAoKW3ByaXZhY3ldCmhpZGVvcz10cnVlCgpbYXVkaW9dCmlucHV0PVB1bHNl
QXVkaW8Kb3V0cHV0PVB1bHNlQXVkaW8KcXVhbGl0eT0xNjAwMAp0cmFuc21pdD0yCgpbc2hvcnRjdXRz
XQoxXGRhdGE9QEludmFsaWQoKQoxXGluZGV4PTEKMVxrZXlzPUBWYXJpYW50KFwwXDBcMFx0XDBcMFww
XHgxXDBcMFwwXHgyXDBcMFwwaSkKMVxzdXBwcmVzcz1mYWxzZQpzaXplPTEKClt1aV0KV2luZG93TGF5
b3V0PTEKYWx3YXlzb250b3A9MQphc2tvbnF1aXQ9ZmFsc2UKZHJhZz0xCmxhbmd1YWdlPWVzCnVzYWdl
PWZhbHNl
b3V0PTEKYXNrb25xdWl0PWZhbHNlCmRyYWc9MQpsYW5ndWFnZT1lcwp1c2FnZT1mYWxzZQ==
`,
},

Expand Down
9 changes: 0 additions & 9 deletions gui/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
generate-ui:
go generate -x ui_reader.go

generate-locale:
# This beautiful code is necessary because gotext
# will barf if the golang.org/x/text/message package
Expand All @@ -9,9 +6,3 @@ generate-locale:
rm -rf ../vendor/golang.org/x/text
go generate -x i18n.go
git checkout ../vendor/golang.org/x/text

touch:
ls definitions/*.xml | xargs -n1 touch

doctor: touch generate
git diff --exit-code .
2 changes: 1 addition & 1 deletion gui/ui_generate.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

esc -o definitions.go -modtime 1489449600 -pkg gui -ignore "Makefile" definitions/ styles/ images/ config_files/
../.build-tools/esc -o definitions.go -modtime 1489449600 -pkg gui -ignore "Makefile" definitions/ styles/ images/ config_files/
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (
log "github.com/sirupsen/logrus"
)

// BuildCommit contains which commit the build was based on
var BuildCommit = "UNKNOWN"

// BuildShortCommit contains which commit in short format the build was based on
var BuildShortCommit = "UNKNOWN"

// BuildTag contains which tag - if any - the build was based on
var BuildTag = "(no tag)"

// BuildTimestamp contains the timestamp in Ecuador time zone when the build was made
var BuildTimestamp = "UNKNOWN"

func initializeLogging() {
log.SetLevel(log.InfoLevel)
if *config.Debug {
Expand Down

0 comments on commit e26479a

Please sign in to comment.