diff --git a/.gitignore b/.gitignore index ffd13cb..cac95cb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ /exported-artifacts/ /tools/bin/ /tools/pkg/ -/tools/src/gopkg.in/ +vendor/ diff --git a/Makefile b/Makefile index a6e01df..79d2b4e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tools/src/build.go b/tools/src/ovc/build.go similarity index 98% rename from tools/src/build.go rename to tools/src/ovc/build.go index 9022a99..f30c029 100644 --- a/tools/src/build.go +++ b/tools/src/ovc/build.go @@ -21,7 +21,7 @@ package main import ( "fmt" - "ovirt/build" + "ovc/build" ) func buildTool(project *build.Project) error { diff --git a/tools/src/ovirt/build/commands.go b/tools/src/ovc/build/commands.go similarity index 100% rename from tools/src/ovirt/build/commands.go rename to tools/src/ovc/build/commands.go diff --git a/tools/src/ovirt/build/dockerfiles.go b/tools/src/ovc/build/dockerfiles.go similarity index 100% rename from tools/src/ovirt/build/dockerfiles.go rename to tools/src/ovc/build/dockerfiles.go diff --git a/tools/src/ovirt/build/images.go b/tools/src/ovc/build/images.go similarity index 100% rename from tools/src/ovirt/build/images.go rename to tools/src/ovc/build/images.go diff --git a/tools/src/ovirt/build/project.go b/tools/src/ovc/build/project.go similarity index 99% rename from tools/src/ovirt/build/project.go rename to tools/src/ovc/build/project.go index 6995c78..27f1f3a 100644 --- a/tools/src/ovirt/build/project.go +++ b/tools/src/ovc/build/project.go @@ -27,7 +27,7 @@ import ( "path/filepath" "regexp" - "gopkg.in/ini.v1" + "github.com/go-ini/ini" ) // Project contains the project configuration. diff --git a/tools/src/ovirt/build/re.go b/tools/src/ovc/build/re.go similarity index 100% rename from tools/src/ovirt/build/re.go rename to tools/src/ovc/build/re.go diff --git a/tools/src/ovirt/build/templates.go b/tools/src/ovc/build/templates.go similarity index 100% rename from tools/src/ovirt/build/templates.go rename to tools/src/ovc/build/templates.go diff --git a/tools/src/clean.go b/tools/src/ovc/clean.go similarity index 98% rename from tools/src/clean.go rename to tools/src/ovc/clean.go index d9323ad..3741812 100644 --- a/tools/src/clean.go +++ b/tools/src/ovc/clean.go @@ -22,7 +22,7 @@ package main import ( "fmt" - "ovirt/build" + "ovc/build" ) func cleanTool(project *build.Project) error { diff --git a/tools/src/deploy.go b/tools/src/ovc/deploy.go similarity index 99% rename from tools/src/deploy.go rename to tools/src/ovc/deploy.go index 6b333ac..78f0e1d 100644 --- a/tools/src/deploy.go +++ b/tools/src/ovc/deploy.go @@ -26,7 +26,7 @@ import ( "strconv" "strings" - "ovirt/build" + "ovc/build" ) // The name of the project. diff --git a/tools/src/ovc/glide.lock b/tools/src/ovc/glide.lock new file mode 100644 index 0000000..28d6777 --- /dev/null +++ b/tools/src/ovc/glide.lock @@ -0,0 +1,6 @@ +hash: 4de13599e262976dc3aaf850a3e41cc81c09f1a4bc2796295cdbc3011d4cf1e9 +updated: 2017-06-06T14:04:26.429728957+02:00 +imports: +- name: github.com/go-ini/ini + version: d3de07a94d22b4a0972deb4b96d790c2c0ce8333 +testImports: [] diff --git a/tools/src/ovc/glide.yaml b/tools/src/ovc/glide.yaml new file mode 100644 index 0000000..d10d27f --- /dev/null +++ b/tools/src/ovc/glide.yaml @@ -0,0 +1,4 @@ +package: ovc +import: +- package: github.com/go-ini/ini + version: v1.28.0 diff --git a/tools/src/main.go b/tools/src/ovc/main.go similarity index 92% rename from tools/src/main.go rename to tools/src/ovc/main.go index 58bd0aa..24df683 100644 --- a/tools/src/main.go +++ b/tools/src/ovc/main.go @@ -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, diff --git a/tools/src/push.go b/tools/src/ovc/push.go similarity index 98% rename from tools/src/push.go rename to tools/src/ovc/push.go index 565c7e0..9313c60 100644 --- a/tools/src/push.go +++ b/tools/src/ovc/push.go @@ -21,7 +21,7 @@ package main import ( "fmt" - "ovirt/build" + "ovc/build" ) func pushTool(project *build.Project) error { diff --git a/tools/src/save.go b/tools/src/ovc/save.go similarity index 98% rename from tools/src/save.go rename to tools/src/ovc/save.go index 3eec1ef..9dc36b4 100644 --- a/tools/src/save.go +++ b/tools/src/ovc/save.go @@ -21,7 +21,7 @@ package main import ( "fmt" - "ovirt/build" + "ovc/build" ) func saveTool(project *build.Project) error {