mirror of https://github.com/status-im/consul.git
Merge pull request #638 from ceh/bat-build
make.bat: add Makefile functionality for Windows
This commit is contained in:
commit
72a6692602
24
README.md
24
README.md
|
@ -42,9 +42,9 @@ http://www.consul.io/docs
|
||||||
|
|
||||||
## Developing Consul
|
## 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,
|
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
|
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:
|
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
|
If you make any changes to the code, run `make format` in order to automatically
|
||||||
format the code according to Go standards.
|
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.
|
||||||
|
|
||||||
|
|
18
build.bat
18
build.bat
|
@ -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%
|
|
|
@ -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%
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue