From 28ee83e1ea59d7ff673e53d53098ddbd8eda7c64 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Thu, 18 May 2017 17:20:07 +0800 Subject: [PATCH] Add initial makefile and tools This is for aligning with Golang CTI proposed proposed in https://review.openstack.org/410355. Change-Id: I04c25e8bde1bcb6c17b12284b67eb3e9953d94fe Signed-off-by: Pengfei Ni --- Makefile | 130 +++++++++++++++++++++++++++++++ bindep.txt | 5 ++ glide.yaml | 2 + main.go | 7 ++ tools/install-distro-packages.sh | 40 ++++++++++ tools/test-setup.sh | 54 +++++++++++++ 6 files changed, 238 insertions(+) create mode 100644 Makefile create mode 100644 bindep.txt create mode 100644 glide.yaml create mode 100644 main.go create mode 100755 tools/install-distro-packages.sh create mode 100755 tools/test-setup.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..82fd43a --- /dev/null +++ b/Makefile @@ -0,0 +1,130 @@ +# stackube Makefile +# Follows the interface defined in the Golang CTI proposed +# in https://review.openstack.org/410355 + +#REPO_VERSION?=$(shell git describe --tags) + +GIT_HOST = git.openstack.org +SHELL := /bin/bash + +PWD := $(shell pwd) +BASE_DIR := $(shell basename $(PWD)) +# Keep an existing GOPATH, make a private one if it is undefined +GOPATH_DEFAULT := $(PWD)/.go +export GOPATH ?= $(GOPATH_DEFAULT) +PKG := $(shell awk '/^package: / { print $$2 }' glide.yaml) +DEST := $(GOPATH)/src/$(PKG) + +GOFLAGS := +TAGS := +LDFLAGS := + +# Default target +.PHONY: all +all: build + +# CTI targets + +.PHONY: depend +depend: work + cd $(DEST) && glide install + +.PHONY: depend-update +depend-update: work + cd $(DEST) && glide update + +.PHONY: build +build: depend + cd $(DEST) && go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)'' ./... + +.PHONY: install +install: depend + cd $(DEST) && go install $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)'' ./... + +.PHONY: test +test: test-unit + +.PHONY: test-unit +test-unit: depend +test-unit: TAGS += unit +test-unit: test-flags + +.PHONY: test-flags +test-flags: + cd $(DEST) && go test $(GOFLAGS) -tags '$(TAGS)' ./... + +# The above pipeline is required because gofmt always returns 0 and we need +# to detect if any files are listed as having format problems. +.PHONY: fmt +fmt: work + files=$$(cd $(DEST) && gofmt -l . | tee >(cat - >&2)); [ -z "$$files" ] + +.PHONY: fmtfix +fmtfix: work + cd $(DEST) && go fmt ./... + +lint: + @echo "$@ not yet implemented" + +cover: + @echo "$@ not yet implemented" + +docs: + @echo "$@ not yet implemented" + +godoc: + @echo "$@ not yet implemented" + +releasenotes: + @echo "Reno not yet implemented for this repo" + +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)" + @echo "PKG: $(PKG)" + +# 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 + +bindep: .bindep + @.bindep/bin/bindep -b -f bindep.txt || true + +install-distro-packages: + tools/install-distro-packages.sh + +clean: + rm -rf .bindep + +realclean: clean + rm -rf vendor + if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \ + rm -rf $(GOPATH); \ + fi + +shell: work + cd $(DEST) && $(SHELL) -i + +.PHONY: bindep clean cover depend docs fmt functional lint realclean \ + relnotes test translation diff --git a/bindep.txt b/bindep.txt new file mode 100644 index 0000000..5e3550e --- /dev/null +++ b/bindep.txt @@ -0,0 +1,5 @@ +pkg-config +build-essential +golang-go +golint +make diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 0000000..f3ca981 --- /dev/null +++ b/glide.yaml @@ -0,0 +1,2 @@ +package: git.openstack.org/openstack/stackube +import: [] diff --git a/main.go b/main.go new file mode 100644 index 0000000..252fafe --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello from stackube") +} diff --git a/tools/install-distro-packages.sh b/tools/install-distro-packages.sh new file mode 100755 index 0000000..ee6e032 --- /dev/null +++ b/tools/install-distro-packages.sh @@ -0,0 +1,40 @@ +#!/bin/bash -xe + +# Local version to install bindep packages +# Suitable for use for development + +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 +if apt-get -v >/dev/null 2>&1 ; then + sudo apt-get -qq update + sudo PATH=/usr/sbin:/sbin:$PATH DEBIAN_FRONTEND=noninteractive \ + apt-get -q --option "Dpkg::Options::=--force-confold" \ + --assume-yes install $PACKAGES +elif emerge --version >/dev/null 2>&1 ; then + sudo emerge -uDNq --jobs=4 @world + sudo PATH=/usr/sbin:/sbin:$PATH emerge -q --jobs=4 $PACKAGES +else + is_fedora && YUM=dnf || YUM=yum + sudo PATH=/usr/sbin:/sbin:$PATH $YUM install -y $PACKAGES +fi diff --git a/tools/test-setup.sh b/tools/test-setup.sh new file mode 100755 index 0000000..4ae7853 --- /dev/null +++ b/tools/test-setup.sh @@ -0,0 +1,54 @@ +#!/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 + if ! which glide 1>/dev/null; then + brew install glide + fi + 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