Merge pull request #4494 from tb3088/EOL-handling
Eol handling for the Repo and build process
This commit is contained in:
commit
dfe4f56c75
6
.gitattributes
vendored
6
.gitattributes
vendored
@ -1,2 +1,4 @@
|
|||||||
|
* text=auto
|
||||||
common/test-fixtures/root/* eol=lf
|
*.go text eol=lf
|
||||||
|
*.sh text eol=lf
|
||||||
|
common/test-fixtures/root/* eol=lf
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -23,4 +23,5 @@ packer-test*.log
|
|||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
/packer.exe
|
/packer.exe
|
||||||
|
.project
|
||||||
|
9
Makefile
9
Makefile
@ -4,7 +4,7 @@ VET?=$(shell ls -d */ | grep -v vendor | grep -v website)
|
|||||||
GITSHA:=$(shell git rev-parse HEAD)
|
GITSHA:=$(shell git rev-parse HEAD)
|
||||||
# Get the current local branch name from git (if we can, this may be blank)
|
# 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)
|
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)
|
GOOS=$(shell go env GOOS)
|
||||||
GOARCH=$(shell go env GOARCH)
|
GOARCH=$(shell go env GOARCH)
|
||||||
GOPATH=$(shell go env GOPATH)
|
GOPATH=$(shell go env GOPATH)
|
||||||
@ -58,10 +58,13 @@ dev: deps ## Build and install a development build
|
|||||||
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
|
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
|
||||||
|
|
||||||
fmt: ## Format Go code
|
fmt: ## Format Go code
|
||||||
@gofmt -w -s $(GOFMT_FILES)
|
@$(GOFMT_FILES) | xargs gofmt -w -s
|
||||||
|
|
||||||
fmt-check: ## Check go code formatting
|
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:
|
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 {} \;
|
@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 {} \;
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#
|
|
||||||
# This script builds the application from source for multiple platforms.
|
# 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
|
set -e
|
||||||
|
|
||||||
# Get the parent directory of where this script is.
|
# Get the parent directory of where this script is.
|
||||||
@ -11,54 +15,88 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
|||||||
# Change into that directory
|
# Change into that directory
|
||||||
cd $DIR
|
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
|
# Delete the old dir
|
||||||
echo "==> Removing old directory..."
|
echo "==> Removing old directory..."
|
||||||
rm -f bin/*
|
rm -f bin/*
|
||||||
rm -rf pkg/*
|
rm -rf pkg/*
|
||||||
mkdir -p bin/
|
mkdir -p bin/
|
||||||
|
|
||||||
|
# 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!
|
# Build!
|
||||||
echo "==> Building..."
|
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
|
set +e
|
||||||
gox \
|
${GOX:?command not found} \
|
||||||
-os="${XC_OS}" \
|
-os="${XC_OS:-$ALL_XC_OS}" \
|
||||||
-arch="${XC_ARCH}" \
|
-arch="${XC_ARCH:-$ALL_XC_ARCH}" \
|
||||||
-osarch="!darwin/arm !darwin/arm64" \
|
-osarch="!darwin/arm !darwin/arm64" \
|
||||||
-ldflags "${GOLDFLAGS}" \
|
-ldflags "${GOLDFLAGS}" \
|
||||||
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
||||||
.
|
.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Move all the compiled things to the $GOPATH/bin
|
# trim GOPATH to first element
|
||||||
GOPATH=${GOPATH:-$(go env GOPATH)}
|
IFS="$PATHSEP"
|
||||||
case $(uname) in
|
|
||||||
CYGWIN*)
|
|
||||||
GOPATH="$(cygpath $GOPATH)"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
OLDIFS=$IFS
|
|
||||||
IFS=:
|
|
||||||
case $(uname) in
|
|
||||||
MINGW*)
|
|
||||||
IFS=";"
|
|
||||||
;;
|
|
||||||
MSYS*)
|
|
||||||
IFS=";"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
MAIN_GOPATH=($GOPATH)
|
MAIN_GOPATH=($GOPATH)
|
||||||
|
MAIN_GOPATH="$(convert_path --unix "$MAIN_GOPATH")"
|
||||||
IFS=$OLDIFS
|
IFS=$OLDIFS
|
||||||
|
|
||||||
# Copy our OS/Arch to the bin/ directory
|
# Copy our OS/Arch to the bin/ directory
|
||||||
echo "==> Copying binaries for this platform..."
|
echo "==> Copying binaries for this platform..."
|
||||||
DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)"
|
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 ${F} bin/
|
cp -v ${F} bin/
|
||||||
cp ${F} ${MAIN_GOPATH}/bin/
|
cp -v ${F} ${MAIN_GOPATH}/bin/
|
||||||
done
|
done
|
||||||
|
|
||||||
# Done!
|
# Done!
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Check gofmt
|
for f in $@; do
|
||||||
echo "==> Checking that code complies with gofmt requirements..."
|
[ -n "`dos2unix 2>/dev/null < $f | gofmt -s -d`" ] && echo $f
|
||||||
gofmt_files=$(gofmt -s -l ${@})
|
done
|
||||||
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."
|
|
||||||
|
|
||||||
|
# always return success or else 'make' will abort
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user