Skip to content

Commit

Permalink
make.bat: add Makefile functionality for Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ceh committed Jan 25, 2015
1 parent 8b0fe52 commit 78b947d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 20 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

18 changes: 0 additions & 18 deletions build.bat

This file was deleted.

86 changes: 86 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -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%
42 changes: 42 additions & 0 deletions scripts/windows/build.bat
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/windows/verify_no_uuid.bat
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 78b947d

Please sign in to comment.