From 34a783684aad56c5f654c8b85f7e5d557df34c2c Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Thu, 22 Dec 2016 09:58:30 -0600
Subject: [PATCH] Use glide for dependencies

Use the new tools/test-setup.sh for bootstrapping our
dev/test environment

Change-Id: Ic5c9d89d4a6d89f8a4b138fc9c814452fc6ff104
---
 Makefile                         | 58 ++++++++++++++++++++++----------
 glide.lock                       |  6 ++++
 glide.yaml                       |  3 ++
 tools/install-distro-packages.sh | 16 +++++++++
 tools/test-setup.sh              | 52 ++++++++++++++++++++++++++++
 5 files changed, 117 insertions(+), 18 deletions(-)
 create mode 100644 glide.lock
 create mode 100644 glide.yaml
 create mode 100755 tools/test-setup.sh

diff --git a/Makefile b/Makefile
index 2191219..ec922fd 100644
--- a/Makefile
+++ b/Makefile
@@ -13,30 +13,23 @@ GOPATH_DEFAULT := $(PWD)/.go
 export GOPATH ?= $(GOPATH_DEFAULT)
 DEST := $(GOPATH)/src/$(GIT_HOST)/openstack/$(BASE_DIR).git
 
-env:
-	@echo "PWD: $(PWD)"
-	@echo "BASE_DIR: $(BASE_DIR)"
-	@echo "GOPATH: $(GOPATH)"
-	@echo "DEST: $(DEST)"
+# CTI targets
 
-work: $(GOPATH) $(DEST)
+depend: work
+	cd $(DEST) && glide install
 
-$(GOPATH):
-	mkdir -p $(GOPATH)
+test: depend
+	cd $(DEST) && go test -tags=unit ./...
 
-$(DEST): $(GOPATH)
-	mkdir -p $(shell dirname $(DEST))
-	ln -s $(PWD) $(DEST)
-
-get: work
-	cd $(DEST); go get -tags=unit -t ./...
-
-test: get
-	cd $(DEST); go test -tags=unit ./...
+functional:
+	@echo "$@ not yet implemented"
 
 fmt: work
 	cd $(DEST) && go fmt ./...
 
+lint:
+	@echo "$@ not yet implemented"
+
 cover:
 	@echo "$@ not yet implemented"
 
@@ -49,6 +42,28 @@ relnotes:
 translation:
 	@echo "$@ not yet implemented"
 
+# Do the work here
+
+# Set up the development environment
+env:
+	@echo "PWD: $(PWD)"
+	@echo "BASE_DIR: $(BASE_DIR)"
+	@echo "GOPATH: $(GOPATH)"
+	@echo "DEST: $(DEST)"
+
+# Get our dev/test dependencies in place
+bootstrap:
+	tools/test-setup.sh
+
+work: $(GOPATH) $(DEST)
+
+$(GOPATH):
+	mkdir -p $(GOPATH)
+
+$(DEST): $(GOPATH)
+	mkdir -p $(shell dirname $(DEST))
+	ln -s $(PWD) $(DEST)
+
 .bindep:
 	virtualenv .bindep
 	.bindep/bin/pip install bindep
@@ -61,8 +76,15 @@ install-distro-packages:
 
 clean:
 	rm -rf .bindep
+
+realclean: clean
+	rm -rf vendor
 	if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
 		rm -rf $(GOPATH); \
 	fi
 
-.PHONY: bindep clean
+shell: work
+	cd $(DEST) && $(SHELL) -i
+
+.PHONY: bindep clean cover depend docs fmt functional lint realclean \
+	relnotes test translation
diff --git a/glide.lock b/glide.lock
new file mode 100644
index 0000000..3f3301c
--- /dev/null
+++ b/glide.lock
@@ -0,0 +1,6 @@
+hash: 29383d95fa712061eaaec8c9f3af33f4a29700e0d385f4f9f454f1ce27b05fec
+updated: 2016-12-21T14:53:45.41134367-06:00
+imports:
+- name: github.com/fullsailor/pkcs7
+  version: cedaa6c8ea14493515fcf950eabba5eb1530c349
+devImports: []
diff --git a/glide.yaml b/glide.yaml
new file mode 100644
index 0000000..9d6e50a
--- /dev/null
+++ b/glide.yaml
@@ -0,0 +1,3 @@
+package: git.openstack.org/openstack/golang-client.git
+import:
+- package: github.com/fullsailor/pkcs7
diff --git a/tools/install-distro-packages.sh b/tools/install-distro-packages.sh
index c5801a3..ee6e032 100755
--- a/tools/install-distro-packages.sh
+++ b/tools/install-distro-packages.sh
@@ -7,6 +7,22 @@ function is_fedora {
     [ -f /usr/bin/yum ] && cat /etc/*release | grep -q -e "Fedora"
 }
 
+PACKAGES=""
+if ! which virtualenv; then
+    PACKAGES="$PACKAGES virtualenv"
+fi
+if ! which make; then
+    PACKAGES="$PACKAGES make"
+fi
+if [[ -n $PACKAGES ]]; then
+    sudo apt-get -q --assume-yes install virtualenv
+fi
+
+# Check for bindep
+if ! which bindep; then
+    make bindep
+fi
+
 PACKAGES=$(make bindep || true)
 
 # inspired from project-config install-distro-packages.sh
diff --git a/tools/test-setup.sh b/tools/test-setup.sh
new file mode 100755
index 0000000..6a8fa1e
--- /dev/null
+++ b/tools/test-setup.sh
@@ -0,0 +1,52 @@
+#!/bin/bash -xe
+# test-setup.sh - Install required stuffs
+# Used in both CI jobs and locally
+#
+# Install the following tools:
+# * glide
+
+# Get OS
+case $(uname -s) in
+    Darwin)
+        OS=darwin
+        ;;
+    Linux)
+        if LSB_RELEASE=$(which lsb_release); then
+            OS=$($LSB_RELEASE -s -c)
+        else
+            # No lsb-release, trya hack or two
+            if which dpkg 1>/dev/null; then
+                OS=debian
+            elif which yum 1>/dev/null || which dnf 1>/dev/null; then
+                OS=redhat
+            else
+                echo "Linux distro not yet supported"
+                exit 1
+            fi
+        fi
+        ;;
+    *)
+        echo "Unsupported OS"
+        exit 1
+        ;;
+esac
+
+case $OS in
+    darwin)
+        if which brew 1>/dev/null; then
+            brew install glide
+        else
+            echo "Homebrew not found, install Glide from source?"
+        fi
+        ;;
+    xenial)
+        APT_GET="DEBIAN_FRONTEND=noninteractive \
+            apt-get -q --option "Dpkg::Options::=--force-confold" \
+            --assume-yes"
+        if ! which add-apt-repository 1>/dev/null; then
+            sudo $APT_GET install software-properties-common
+        fi
+        sudo add-apt-repository --yes ppa:masterminds/glide && sudo apt-get update
+        sudo $APT_GET install glide
+        ;;
+esac