From 049e1bbf73bcfdc22a2e2b79714aaa93dbdb756f Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Wed, 1 Feb 2017 22:57:36 -0500 Subject: [PATCH 1/6] too many files for shell during Make, convert .go and .sh to EOL=lf --- .gitattributes | 6 ++++-- Makefile | 9 ++++++--- scripts/gofmtcheck.sh | 14 ++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.gitattributes b/.gitattributes index 7230f36f4..fba3b1303 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ - -common/test-fixtures/root/* eol=lf \ No newline at end of file +* text=auto +*.go text eol=lf +*.sh text eol=lf +common/test-fixtures/root/* eol=lf diff --git a/Makefile b/Makefile index 54852ce26..cb48d7e2c 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ VET?=$(shell ls -d */ | grep -v vendor | grep -v website) GITSHA:=$(shell git rev-parse HEAD) # Get the current local branch name from git (if we can, this may be blank) GITBRANCH:=$(shell git symbolic-ref --short HEAD 2>/dev/null) -GOFMT_FILES?=$$(find . -not -path "./vendor/*" -name "*.go") +GOFMT_FILES?=find . -path ./vendor -prune -o -name "*.go" GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) GOPATH=$(shell go env GOPATH) @@ -57,10 +57,13 @@ dev: deps ## Build and install a development build @cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH) fmt: ## Format Go code - @gofmt -w -s $(GOFMT_FILES) + @$(GOFMT_FILES) | xargs gofmt -w -s fmt-check: ## Check go code formatting - $(CURDIR)/scripts/gofmtcheck.sh $(GOFMT_FILES) + @echo "==> Checking that code complies with gofmt requirements..." + @echo "You can use the command: \`make fmt\` to reformat code." + @$(GOFMT_FILES) | xargs $(CURDIR)/scripts/gofmtcheck.sh + @echo "Check complete." fmt-docs: @find ./website/source/docs -name "*.md" -exec pandoc --wrap auto --columns 79 --atx-headers -s -f "markdown_github+yaml_metadata_block" -t "markdown_github+yaml_metadata_block" {} -o {} \; diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh index 5b99bcdc4..cc6deb81e 100755 --- a/scripts/gofmtcheck.sh +++ b/scripts/gofmtcheck.sh @@ -1,14 +1,8 @@ #!/usr/bin/env bash -# Check gofmt -echo "==> Checking that code complies with gofmt requirements..." -gofmt_files=$(gofmt -s -l ${@}) -if [[ -n ${gofmt_files} ]]; then - echo 'gofmt needs running on the following files:' - echo "${gofmt_files}" - echo "You can use the command: \`make fmt\` to reformat code." - exit 1 -fi -echo "Check passed." +for f in $@; do + [ -n "`dos2unix 2>/dev/null < $f | gofmt -s -d`" ] && echo $f +done +# always return success or else 'make' will abort exit 0 From 1d0cf3d9094126b0a278674fe8b758e1df967869 Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Thu, 2 Feb 2017 02:05:09 -0500 Subject: [PATCH 2/6] handle missing GOPATH and cygwin considerations --- scripts/build.sh | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 84bd7f67d..4c02cedb3 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -21,44 +21,33 @@ rm -f bin/* rm -rf pkg/* mkdir -p bin/ +OLDIFS=$IFS +IFS=: +case $(uname) in + MINGW*|MSYS*) + IFS=";" + ;; +esac + # Build! echo "==> Building..." set +e -gox \ +${GOX:-$GOPATH/bin/gox} \ -os="${XC_OS}" \ -arch="${XC_ARCH}" \ -osarch="!darwin/arm !darwin/arm64" \ -ldflags "${GOLDFLAGS}" \ -output "pkg/{{.OS}}_{{.Arch}}/packer" \ . -set -e -# Move all the compiled things to the $GOPATH/bin -GOPATH=${GOPATH:-$(go env GOPATH)} -case $(uname) in - CYGWIN*) - GOPATH="$(cygpath $GOPATH)" - ;; -esac -OLDIFS=$IFS -IFS=: -case $(uname) in - MINGW*) - IFS=";" - ;; - MSYS*) - IFS=";" - ;; -esac -MAIN_GOPATH=($GOPATH) IFS=$OLDIFS +set -e # Copy our OS/Arch to the bin/ directory echo "==> Copying binaries for this platform..." -DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" -for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do - cp ${F} bin/ - cp ${F} ${MAIN_GOPATH}/bin/ +for F in $(find pkg/$(go env GOOS)_$(go env GOARCH) -mindepth 1 -maxdepth 1 -type f); do + cp -v ${F} bin/ + cp -v ${F} ${GOPATH}/bin/ done # Done! From 9a2d5885cedd9eec42d9e95abdd334da0c1de18e Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Fri, 29 Dec 2017 17:46:14 -0500 Subject: [PATCH 3/6] ignore Eclipse project files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6ab3cdfb9..0f310de91 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ packer-test*.log .idea/ *.iml Thumbs.db -/packer.exe \ No newline at end of file +/packer.exe +.project From 6a85f5aed7776ea562a67a589971a56385a81e09 Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Thu, 2 Feb 2017 02:05:09 -0500 Subject: [PATCH 4/6] handle missing GOPATH and cygwin considerations --- scripts/build.sh | 79 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 4c02cedb3..5533cf939 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash -# + # This script builds the application from source for multiple platforms. +# Determine the arch/os combos we're building for +ALL_XC_ARCH="386 amd64 arm arm64 ppc64le" +ALL_XC_OS="linux darwin windows freebsd openbsd solaris" + set -e # Get the parent directory of where this script is. @@ -21,33 +25,82 @@ rm -f bin/* rm -rf pkg/* mkdir -p bin/ -OLDIFS=$IFS -IFS=: -case $(uname) in - MINGW*|MSYS*) - IFS=";" +# helpers for Cygwin-hosted builds +: ${OSTYPE:=`uname`} + +case $OSTYPE in + MINGW*|MSYS*|cygwin|CYGWIN*) + # cygwin only translates ';' to ':' on select environment variables + PATHSEP=';' ;; + *) PATHSEP=':' esac +function convert_path() { + local flag + [ "${1:0:1}" = '-' ] && { flag="$1"; shift; } + + [ -n "$1" ] || return 0 + case ${OSTYPE:-`uname`} in + cygwin|CYGWIN*) + cygpath $flag -- "$1" + ;; + *) echo "$1" + esac +} + +# XXX works in MINGW? +which go &>/dev/null || PATH+=":`convert_path "${GOROOT:?}"`/bin" + +OLDIFS="$IFS" + +# make sure GOPATH is consistent - Windows binaries can't handle Cygwin-style paths +IFS="$PATHSEP" +for d in ${GOPATH:-$(go env GOPATH)}; do + _GOPATH+="${_GOPATH:+$PATHSEP}$(convert_path --windows "$d")" +done +GOPATH="$_GOPATH" + +# locate 'gox' and traverse GOPATH if needed +which "${GOX:=gox}" &>/dev/null || { + for d in $GOPATH; do + GOX="$(convert_path --unix "$d")/bin/gox" + [ -x "$GOX" ] && break || unset GOX + done +} +IFS="$OLDIFS" + # Build! echo "==> Building..." + +# If in dev mode, only build for ourself +if [ -n "${PACKER_DEV+x}" ]; then + XC_OS=$(go env GOOS) + XC_ARCH=$(go env GOARCH) +fi + set +e -${GOX:-$GOPATH/bin/gox} \ - -os="${XC_OS}" \ - -arch="${XC_ARCH}" \ +${GOX:?command not found} \ + -os="${XC_OS:-$ALL_XC_OS}" \ + -arch="${XC_ARCH:-$ALL_XC_ARCH}" \ -osarch="!darwin/arm !darwin/arm64" \ -ldflags "${GOLDFLAGS}" \ -output "pkg/{{.OS}}_{{.Arch}}/packer" \ . - -IFS=$OLDIFS set -e +# trim GOPATH to first element +IFS="$PATHSEP" +MAIN_GOPATH=($GOPATH) +MAIN_GOPATH="$(convert_path --unix "$MAIN_GOPATH")" +IFS=$OLDIFS + # Copy our OS/Arch to the bin/ directory echo "==> Copying binaries for this platform..." -for F in $(find pkg/$(go env GOOS)_$(go env GOARCH) -mindepth 1 -maxdepth 1 -type f); do +DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" +for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do cp -v ${F} bin/ - cp -v ${F} ${GOPATH}/bin/ + cp -v ${F} ${MAIN_GOPATH}/bin/ done # Done! From d5bf9277cebb6d334e0db93a601301d9f4ee38ea Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Sat, 7 Apr 2018 05:33:46 -0400 Subject: [PATCH 5/6] remove rebase duplicate --- scripts/build.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 5533cf939..19ed1ad09 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -15,10 +15,6 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" # Change into that directory cd $DIR -# Determine the arch/os combos we're building for -XC_ARCH=${XC_ARCH:-"386 amd64 arm arm64 ppc64le"} -XC_OS=${XC_OS:-linux darwin windows freebsd openbsd solaris} - # Delete the old dir echo "==> Removing old directory..." rm -f bin/* From 554b2b4a5dc88296032179ff795a0bd5872bf63b Mon Sep 17 00:00:00 2001 From: Matthew Patton Date: Mon, 9 Apr 2018 19:47:41 -0400 Subject: [PATCH 6/6] ignore errors during Find --- scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index 19ed1ad09..4f55b9893 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -94,7 +94,7 @@ IFS=$OLDIFS # Copy our OS/Arch to the bin/ directory echo "==> Copying binaries for this platform..." DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)" -for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do +for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f 2>/dev/null); do cp -v ${F} bin/ cp -v ${F} ${MAIN_GOPATH}/bin/ done