Skip to content

Commit

Permalink
Use Glide to manage Go dependencies
Browse files Browse the repository at this point in the history
Currently the Go dependencies of the project are running 'go get',
from the Makefile. This doesn't scale well for adding other
dependencies. To simplify that this patch changes the project so that it
uses Glide to manage dependencies:

  https://glide.sh

If Glide isn't installed it will be installed automatically when running
the build.

Change-Id: Iae3eb9ddd399502b7afdbd8e2f5ed5ecadca335e
Signed-off-by: Juan Hernandez <[email protected]>
  • Loading branch information
jhernand committed Jun 26, 2017
1 parent 4f6b388 commit 20e6f1e
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/exported-artifacts/
/tools/bin/
/tools/pkg/
/tools/src/gopkg.in/
vendor/
56 changes: 38 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,56 @@
# probably the right place. Look at 'tools/src/ovirt/cmd/build/build.go'
# instead, as that is the starting point for the main build process.

.PHONY: all clean
# The root of the Go source code:
ROOT=$(PWD)/tools

# Go path:
GOPATH="$(PWD)/tools"
# Locations of the Go and Glide binaries:
GO_BINARY=go
GLIDE_BINARY=$(ROOT)/bin/glide

# Go dependencies:
GODEPS=\
gopkg.in/ini.v1 \
$(NULL)
# Location of the Glide project:
GLIDE_PROJECT=$(shell find tools/src -name glide.yaml -print -quit)

# Rule to build the from its source code:
tools/bin/tool: $(shell find tools/src -type f)
for godep in $(GODEPS); do \
GOPATH="$(GOPATH)" go get $${godep}; \
done
GOPATH="$(GOPATH)" go build -o $@ tools/src/*.go
# Location of the generated tool:
TOOL_BINARY=$(ROOT)/bin/ovc

build: tools/bin/tool
# Install Glide if necessary:
$(GLIDE_BINARY):
mkdir -p `dirname $(GLIDE_BINARY)`
GOPATH="$(ROOT)"; \
export GOPATH; \
PATH="$(ROOT)/bin:$${PATH}"; \
export PATH; \
curl https://glide.sh/get | sh

# Rule to build the tool from its source code:
$(TOOL_BINARY): $(GLIDE_BINARY) $(shell find tools/src -type f)
GOPATH="$(ROOT)"; \
export GOPATH; \
pushd $$(dirname $(GLIDE_PROJECT)); \
$(GLIDE_BINARY) install && \
$(GO_BINARY) build -o $@ *.go || \
exit 1; \
popd \

.PHONY: build
build: $(TOOL_BINARY)
$< $@ 2>&1 | tee $@.log

save: tools/bin/tool
.PHONY: save
save: $(TOOL_BINARY)
$< $@ 2>&1 | tee $@.log

push: tools/bin/tool
.PHONY: push
push: $(TOOL_BINARY)
$< $@ 2>&1 | tee $@.log

deploy: tools/bin/tool
.PHONY: deploy
deploy: $(TOOL_BINARY)
$< $@ 2>&1 | tee $@.log

clean: tools/bin/tool
.PHONY: deploy
clean: $(TOOL_BINARY)
$< $@ 2>&1 | tee $@.log
rm -rf tools/{bin,pkg}
docker images --filter dangling=true --quiet | xargs -r docker rmi --force
2 changes: 1 addition & 1 deletion tools/src/build.go → tools/src/ovc/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package main
import (
"fmt"

"ovirt/build"
"ovc/build"
)

func buildTool(project *build.Project) error {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"path/filepath"
"regexp"

"gopkg.in/ini.v1"
"github.com/go-ini/ini"
)

// Project contains the project configuration.
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/src/clean.go → tools/src/ovc/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package main
import (
"fmt"

"ovirt/build"
"ovc/build"
)

func cleanTool(project *build.Project) error {
Expand Down
2 changes: 1 addition & 1 deletion tools/src/deploy.go → tools/src/ovc/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"strconv"
"strings"

"ovirt/build"
"ovc/build"
)

// The name of the project.
Expand Down
6 changes: 6 additions & 0 deletions tools/src/ovc/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tools/src/ovc/glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package: ovc
import:
- package: github.com/go-ini/ini
version: v1.28.0
6 changes: 5 additions & 1 deletion tools/src/main.go → tools/src/ovc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ import (
"os"
"path/filepath"

"ovirt/build"
"ovc/build"
)

// ToolFunc is the type of functions that implement tools.
//
type ToolFunc func(project *build.Project) error

// This index contains the mapping from names to tool functions.
//
var toolsIndex = map[string]ToolFunc{
"build": buildTool,
"clean": cleanTool,
Expand Down
2 changes: 1 addition & 1 deletion tools/src/push.go → tools/src/ovc/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package main
import (
"fmt"

"ovirt/build"
"ovc/build"
)

func pushTool(project *build.Project) error {
Expand Down
2 changes: 1 addition & 1 deletion tools/src/save.go → tools/src/ovc/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package main
import (
"fmt"

"ovirt/build"
"ovc/build"
)

func saveTool(project *build.Project) error {
Expand Down

0 comments on commit 20e6f1e

Please sign in to comment.