From 78b947ddbc57b3567ad3053b753ad5ab507706e0 Mon Sep 17 00:00:00 2001 From: Emil Hessman Date: Sat, 24 Jan 2015 23:58:04 +0100 Subject: [PATCH] make.bat: add Makefile functionality for Windows Converted the Makefile functionality into several bat files to better support building on Windows. All targets have been introduced in the make.bat file, except for "cov" and "format". Running make.bat with no arguments runs the all target per default, just like Makefile. If an argument is supplied, it must be one of all, cover, deps, integ, test, vet, or updatedeps. For example > make.bat test runs the test target. --- README.md | 24 ++++++++- build.bat | 18 ------- make.bat | 86 ++++++++++++++++++++++++++++++ scripts/windows/build.bat | 42 +++++++++++++++ scripts/windows/verify_no_uuid.bat | 14 +++++ 5 files changed, 164 insertions(+), 20 deletions(-) delete mode 100644 build.bat create mode 100644 make.bat create mode 100644 scripts/windows/build.bat create mode 100644 scripts/windows/verify_no_uuid.bat diff --git a/README.md b/README.md index 3b7cdf0b21..51283a1fbc 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,9 @@ http://www.consul.io/docs ## Developing Consul -If you wish to work on Consul itself, you'll first need [Go](http://golang.org) +If you wish to work on Consul itself, you'll first need [Go](https://golang.org) installed (version 1.4+ is _required_). Make sure you have Go properly installed, -including setting up your [GOPATH](http://golang.org/doc/code.html#GOPATH). +including setting up your [GOPATH](https://golang.org/doc/code.html#GOPATH). Next, clone this repository into `$GOPATH/src/github.com/hashicorp/consul` and then just type `make`. In a few moments, you'll have a working `consul` executable: @@ -63,3 +63,23 @@ You can run tests by typing `make test`. If you make any changes to the code, run `make format` in order to automatically format the code according to Go standards. + +### Building Consul on Windows + +Make sure Go 1.4+ is installed on your system and that the Go command is in your +%PATH%. + +For building Consul on Windows, you also need to have MinGW installed. +[TDM-GCC](http://tdm-gcc.tdragon.net/) is a simple bundle installer which has all +the required tools for building Consul with MinGW. + +Install TDM-GCC and make sure it has been added to your %PATH%. + +If all goes well, you should be able to build Consul by running `make.bat` from a +command prompt. + +See also [golang/winstrap](https://github.com/golang/winstrap) and +[golang/wiki/WindowsBuild](https://github.com/golang/go/wiki/WindowsBuild) +for more information of how to set up a general Go build environment on Windows +with MinGW. + diff --git a/build.bat b/build.bat deleted file mode 100644 index f522775333..0000000000 --- a/build.bat +++ /dev/null @@ -1,18 +0,0 @@ -@echo off - -REM Download Mingw 64 on Windows from http://win-builds.org/download.html - -set GOARCH=%2 -IF "%2" == "" (set GOARCH=amd64) -set MODULENAME=%1 -set ORG_PATH=github.com\hashicorp -set REPO_PATH=%ORG_PATH%\%MODULENAME% - -set GOPATH=%cd%\gopath - -rmdir /s /q %GOPATH%\src\%REPO_PATH% 2>nul -mkdir %GOPATH%\src\%ORG_PATH% 2>nul -go get .\... -mklink /J "%GOPATH%\src\%REPO_PATH%" "%cd%" 2>nul - -%GOROOT%\bin\go build -o bin\%GOARCH%\%MODULENAME%.exe %REPO_PATH% \ No newline at end of file diff --git a/make.bat b/make.bat new file mode 100644 index 0000000000..659560e735 --- /dev/null +++ b/make.bat @@ -0,0 +1,86 @@ +@echo off + +setlocal + +set _EXITCODE=0 + +set _DEPSFILE=%TEMP%\consul-deps.txt +go list -f "{{range .TestImports}}{{.}} {{end}}" .\... >%_DEPSFILE% + +set _PKGSFILE=%TEMP%\consul-pkgs.txt +go list .\... >%_PKGSFILE% + +set _VETARGS=-asmdecl -atomic -bool -buildtags -copylocks -methods^ + -nilfunc -printf -rangeloops -shift -structtags -unsafeptr +if defined VETARGS set _VETARGS=%VETARGS% + +:deps +echo --^> Installing build dependencies +for /f "delims=" %%d in (%_DEPSFILE%) do go get -d -v .\... %%d + +if [%1]==[] goto all +if x%1==xdeps goto end +goto args + +:args +for %%a in (all,cover,integ,test,vet,updatedeps) do (if x%1==x%%a goto %%a) +echo. +echo Unknown make target: %1 +echo Expected one of "all", "cover", "deps", "integ", "test", "vet", or "updatedeps". +set _EXITCODE=1 +goto end + +:all +md bin 2>NUL +call .\scripts\windows\build.bat %CD% +if not errorlevel 1 goto end +echo. +echo BUILD FAILED +set _EXITCODE=%ERRORLEVEL% +goto end + +:cover +set _COVER=--cover +go tool cover 2>NUL +if %ERRORLEVEL% EQU 3 go get golang.org/x/tools/cmd/cover +goto test + +:integ +set INTEG_TESTS=yes +goto test + +:test +call .\scripts\windows\verify_no_uuid.bat %CD% +if %ERRORLEVEL% EQU 0 goto _test +echo. +echo UUID verification failed. +set _EXITCODE=%ERRORLEVEL% +goto end +:_test +for /f "delims=" %%p in (%_PKGSFILE%) do ( + go test %_COVER% %%p + if errorlevel 1 set _TESTFAIL=1 +) +if x%_TESTFAIL%==x1 set _EXITCODE=1 && goto end +goto vet + +:vet +go tool vet 2>NUL +if %ERRORLEVEL% EQU 3 go get golang.org/x/tools/cmd/vet +echo --^> Running go tool vet %_VETARGS% +go tool vet %_VETARGS% . +echo. +if %ERRORLEVEL% EQU 0 echo ALL TESTS PASSED && goto end +echo Vet found suspicious constructs. Please check the reported constructs +echo and fix them if necessary before submitting the code for reviewal. +set _EXITCODE=%ERRORLEVEL% +goto end + +:updatedeps +echo --^> Updating build dependencies +for /f "delims=" %%d in (%_DEPSFILE%) do go get -d -f -u .\... %%d +goto end + +:end +del /F %_DEPSFILE% %_PKGSFILE% 2>NUL +exit /B %_EXITCODE% diff --git a/scripts/windows/build.bat b/scripts/windows/build.bat new file mode 100644 index 0000000000..312cd67746 --- /dev/null +++ b/scripts/windows/build.bat @@ -0,0 +1,42 @@ +@echo off + +setlocal + +if not exist %1 exit /B 1 +cd %1 + +:: Get the git commit +set _GIT_COMMIT_FILE=%TEMP%\consul-git_commit.txt +set _GIT_DIRTY_FILE=%TEMP%\consul-git_dirty.txt +set _GIT_DESCRIBE_FILE=%TEMP%\consul-git_describe.txt + +set _NUL_CMP_FILE=%TEMP%\consul-nul_cmp.txt +type NUL >%_NUL_CMP_FILE% + +git rev-parse HEAD >%_GIT_COMMIT_FILE% +set /p _GIT_COMMIT=<%_GIT_COMMIT_FILE% +del /F "%_GIT_COMMIT_FILE%" 2>NUL + +set _GIT_DIRTY= +git status --porcelain >%_GIT_DIRTY_FILE% +fc %_GIT_DIRTY_FILE% %_NUL_CMP_FILE% >NUL +if errorlevel 1 set _GIT_DIRTY=+CHANGES +del /F "%_GIT_DIRTY_FILE%" 2>NUL +del /F "%_NUL_CMP_FILE%" 2>NUL + +git describe --tags >%_GIT_DESCRIBE_FILE% +set /p _GIT_DESCRIBE=<%_GIT_DESCRIBE_FILE% +del /F "%_GIT_DESCRIBE_FILE%" 2>NUL + +:: Install dependencies +echo --^> Installing dependencies to speed up builds... +go get .\... + +:: Build! +echo --^> Building... +go build^ + -ldflags "-X main.GitCommit %_GIT_COMMIT%%_GIT_DIRTY% -X main.GitDescribe %_GIT_DESCRIBE%"^ + -v^ + -o bin\consul.exe . +if errorlevel 1 exit /B 1 +copy /B /Y bin\consul.exe %GOPATH%\bin\consul.exe >NUL diff --git a/scripts/windows/verify_no_uuid.bat b/scripts/windows/verify_no_uuid.bat new file mode 100644 index 0000000000..bcbc5fa28c --- /dev/null +++ b/scripts/windows/verify_no_uuid.bat @@ -0,0 +1,14 @@ +@echo off + +setlocal + +if not exist %1\consul\state_store.go exit /B 1 +if not exist %1\consul\fsm.go exit /B 1 + +findstr /R generateUUID %1\consul\state_store.go 1>nul +if not %ERRORLEVEL% EQU 1 exit /B 1 + +findstr generateUUID %1\consul\fsm.go 1>nul +if not %ERRORLEVEL% EQU 1 exit /B 1 + +exit /B 0