]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: treat all files as binary, but check in .bat with CRLF
authorDmitri Shuralyov <dmitshur@golang.org>
Thu, 4 Jun 2020 04:35:09 +0000 (00:35 -0400)
committerDmitri Shuralyov <dmitshur@golang.org>
Mon, 8 Jun 2020 15:31:43 +0000 (15:31 +0000)
This is a followup to CL 96495.

It should be simpler and more robust to achieve .bat files having
CRLF line endings by treating it as a binary file, like all other
files, and checking it in with the desired CRLF line endings.

A test is used to check the entire Go tree, short of directories
starting with "." and named "testdata", for any .bat files that
have anything other than strict CRLF line endings. This will help
catch any accidental modifications to existing .bat files or check
ins of new .bat files.

Importantly, this is compatible with how Gerrit serves .tar.gz files,
making it so that CRLF line endings are preserved.

The Go project is supported on many different environments, some of
which may have limited git implementations available, or none at all.
Relying on fewer git features and special rules makes it easier to
have confidence in the exact content of all files. Additionally, Go
development started in Subversion, moved to Perforce, then Mercurial,
and now uses Git.¹ Reducing its reliance on git-specific features will
help if there will be another transition in the project's future.

There are only 5 .bat files in the entire Go source tree, so a new one
being added is a rare event, and we prefer to do things in Go instead.
We still have the option of improving the experience for developers by
adding a pre-commit converter for .bat files to the git-codereview tool.

¹ https://groups.google.com/d/msg/golang-dev/sckirqOWepg/YmyT7dWJiocJ

Fixes #39391.
For #37791.

Change-Id: I6e202216322872f0307ac96f1b8d3f57cb901e6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/236437
Reviewed-by: Bryan C. Mills <bcmills@google.com>
.gitattributes
src/all.bat
src/clean.bat
src/make.bat
src/race.bat
src/run.bat
test/winbatch.go

index bcea0290f4c8d9197fc7d7c055a8055126278078..cabbb1732c418125f9c773ce7a28ba34f2708554 100644 (file)
@@ -1,16 +1,16 @@
 # Treat all files in the Go repo as binary, with no git magic updating
-# line endings. Windows users contributing to Go will need to use a
-# modern version of git and editors capable of LF line endings.
+# line endings. This produces predictable results in different environments.
+#
+# Windows users contributing to Go will need to use a modern version
+# of git and editors capable of LF line endings.
+#
+# Windows .bat files are known to have multiple bugs when run with LF
+# endings, and so they are checked in with CRLF endings, with a test
+# in test/winbatch.go to catch problems. (See golang.org/issue/37791.)
 #
 # We'll prevent accidental CRLF line endings from entering the repo
-# via the git-review gofmt checks.
+# via the git-codereview gofmt checks and tests.
 #
-# See golang.org/issue/9281
+# See golang.org/issue/9281.
 
 * -text
-
-# The only exception is Windows files that must absolutely be CRLF or
-# might not work. Batch files are known to have multiple bugs when run
-# with LF endings. See golang.org/issue/37791 for more information.
-
-*.bat text eol=crlf
index 8bbd6b1b5dae5c0b1b893d0364557c327893965d..ae835d992f318d4440f2d8ffad0769e154e7ecf3 100644 (file)
@@ -1,27 +1,27 @@
-:: Copyright 2012 The Go Authors. All rights reserved.
-:: Use of this source code is governed by a BSD-style
-:: license that can be found in the LICENSE file.
-
-@echo off
-
-setlocal
-
-if exist make.bat goto ok
-echo all.bat must be run from go\src
-:: cannot exit: would kill parent command interpreter
-goto end
-:ok
-
-set OLDPATH=%PATH%
-call make.bat --no-banner --no-local
-if %GOBUILDFAIL%==1 goto end
-call run.bat --no-rebuild --no-local
-if %GOBUILDFAIL%==1 goto end
-:: we must restore %PATH% before running "dist banner" so that the latter
-:: can get the original %PATH% and give suggestion to add %GOROOT%/bin
-:: to %PATH% if necessary.
-set PATH=%OLDPATH%
-"%GOTOOLDIR%/dist" banner
-
-:end
-if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
+:: Copyright 2012 The Go Authors. All rights reserved.\r
+:: Use of this source code is governed by a BSD-style\r
+:: license that can be found in the LICENSE file.\r
+\r
+@echo off\r
+\r
+setlocal\r
+\r
+if exist make.bat goto ok\r
+echo all.bat must be run from go\src\r
+:: cannot exit: would kill parent command interpreter\r
+goto end\r
+:ok\r
+\r
+set OLDPATH=%PATH%\r
+call make.bat --no-banner --no-local\r
+if %GOBUILDFAIL%==1 goto end\r
+call run.bat --no-rebuild --no-local\r
+if %GOBUILDFAIL%==1 goto end\r
+:: we must restore %PATH% before running "dist banner" so that the latter\r
+:: can get the original %PATH% and give suggestion to add %GOROOT%/bin\r
+:: to %PATH% if necessary.\r
+set PATH=%OLDPATH%\r
+"%GOTOOLDIR%/dist" banner\r
+\r
+:end\r
+if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%\r
index 0954dcd67f191f373840769a04562ae7916613a7..c957353d0f10f5edfa1a4e833cb134e801f22820 100644 (file)
@@ -1,32 +1,32 @@
-:: Copyright 2012 The Go Authors. All rights reserved.
-:: Use of this source code is governed by a BSD-style
-:: license that can be found in the LICENSE file.
-
-@echo off
-
-setlocal
-
-set GOBUILDFAIL=0
-
-go tool dist env -w -p >env.bat
-if errorlevel 1 goto fail
-call env.bat
-del env.bat
-echo.
-
-if exist %GOTOOLDIR%\dist.exe goto distok
-echo cannot find %GOTOOLDIR%\dist; nothing to clean
-goto fail
-:distok
-
-"%GOBIN%\go" clean -i std
-"%GOBIN%\go" tool dist clean
-"%GOBIN%\go" clean -i cmd
-
-goto end
-
-:fail
-set GOBUILDFAIL=1
-
-:end
-if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
+:: Copyright 2012 The Go Authors. All rights reserved.\r
+:: Use of this source code is governed by a BSD-style\r
+:: license that can be found in the LICENSE file.\r
+\r
+@echo off\r
+\r
+setlocal\r
+\r
+set GOBUILDFAIL=0\r
+\r
+go tool dist env -w -p >env.bat\r
+if errorlevel 1 goto fail\r
+call env.bat\r
+del env.bat\r
+echo.\r
+\r
+if exist %GOTOOLDIR%\dist.exe goto distok\r
+echo cannot find %GOTOOLDIR%\dist; nothing to clean\r
+goto fail\r
+:distok\r
+\r
+"%GOBIN%\go" clean -i std\r
+"%GOBIN%\go" tool dist clean\r
+"%GOBIN%\go" clean -i cmd\r
+\r
+goto end\r
+\r
+:fail\r
+set GOBUILDFAIL=1\r
+\r
+:end\r
+if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%\r
index f7955ec88a9488c3bb893be9592ab1b8a337faae..277a34d5d7a0e2912e4d4144ad353df1881d00c4 100644 (file)
-:: Copyright 2012 The Go Authors. All rights reserved.
-:: Use of this source code is governed by a BSD-style
-:: license that can be found in the LICENSE file.
-
-:: Environment variables that control make.bat:
-::
-:: GOROOT_FINAL: The expected final Go root, baked into binaries.
-:: The default is the location of the Go tree during the build.
-::
-:: GOHOSTARCH: The architecture for host tools (compilers and
-:: binaries).  Binaries of this type must be executable on the current
-:: system, so the only common reason to set this is to set
-:: GOHOSTARCH=386 on an amd64 machine.
-::
-:: GOARCH: The target architecture for installed packages and tools.
-::
-:: GOOS: The target operating system for installed packages and tools.
-::
-:: GO_GCFLAGS: Additional go tool compile arguments to use when
-:: building the packages and commands.
-::
-:: GO_LDFLAGS: Additional go tool link arguments to use when
-:: building the commands.
-::
-:: CGO_ENABLED: Controls cgo usage during the build. Set it to 1
-:: to include all cgo related files, .c and .go file with "cgo"
-:: build directive, in the build. Set it to 0 to ignore them.
-::
-:: CC: Command line to run to compile C code for GOHOSTARCH.
-:: Default is "gcc".
-::
-:: CC_FOR_TARGET: Command line to run compile C code for GOARCH.
-:: This is used by cgo. Default is CC.
-::
-:: FC: Command line to run to compile Fortran code.
-:: This is used by cgo. Default is "gfortran".
-
-@echo off
-
-:: Keep environment variables within this script
-:: unless invoked with --no-local.
-if x%1==x--no-local goto nolocal
-if x%2==x--no-local goto nolocal
-if x%3==x--no-local goto nolocal
-if x%4==x--no-local goto nolocal
-setlocal
-:nolocal
-
-set GOENV=off
-set GOBUILDFAIL=0
-set GOFLAGS=
-set GO111MODULE=
-
-if exist make.bat goto ok
-echo Must run make.bat from Go src directory.
-goto fail
-:ok
-
-:: Clean old generated file that will cause problems in the build.
-del /F ".\pkg\runtime\runtime_defs.go" 2>NUL
-
-:: Set GOROOT for build.
-cd ..
-set GOROOT_TEMP=%CD%
-set GOROOT=
-cd src
-set vflag=
-if x%1==x-v set vflag=-v
-if x%2==x-v set vflag=-v
-if x%3==x-v set vflag=-v
-if x%4==x-v set vflag=-v
-
-if not exist ..\bin\tool mkdir ..\bin\tool
-
-:: Calculating GOROOT_BOOTSTRAP
-if not "x%GOROOT_BOOTSTRAP%"=="x" goto bootstrapset
-for /f "tokens=*" %%g in ('where go 2^>nul') do (
-       if "x%GOROOT_BOOTSTRAP%"=="x" (
-               for /f "tokens=*" %%i in ('%%g env GOROOT 2^>nul') do (
-                       if /I not %%i==%GOROOT_TEMP% (
-                               set GOROOT_BOOTSTRAP=%%i
-                       )
-               )
-       )
-)
-if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4
-
-:bootstrapset
-if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail
-set GOROOT=%GOROOT_TEMP%
-set GOROOT_TEMP=
-
-echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%
-if x%vflag==x-v echo cmd/dist
-setlocal
-set GOROOT=%GOROOT_BOOTSTRAP%
-set GOOS=
-set GOARCH=
-set GOBIN=
-set GO111MODULE=off
-"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist
-endlocal
-if errorlevel 1 goto fail
-.\cmd\dist\dist.exe env -w -p >env.bat
-if errorlevel 1 goto fail
-call env.bat
-del env.bat
-if x%vflag==x-v echo.
-
-if x%1==x--dist-tool goto copydist
-if x%2==x--dist-tool goto copydist
-if x%3==x--dist-tool goto copydist
-if x%4==x--dist-tool goto copydist
-
-set buildall=-a
-if x%1==x--no-clean set buildall=
-if x%2==x--no-clean set buildall=
-if x%3==x--no-clean set buildall=
-if x%4==x--no-clean set buildall=
-if x%1==x--no-banner set buildall=%buildall% --no-banner
-if x%2==x--no-banner set buildall=%buildall% --no-banner
-if x%3==x--no-banner set buildall=%buildall% --no-banner
-if x%4==x--no-banner set buildall=%buildall% --no-banner
-
-:: Run dist bootstrap to complete make.bash.
-:: Bootstrap installs a proper cmd/dist, built with the new toolchain.
-:: Throw ours, built with Go 1.4, away after bootstrap.
-.\cmd\dist\dist.exe bootstrap %vflag% %buildall%
-if errorlevel 1 goto fail
-del .\cmd\dist\dist.exe
-goto end
-
-:: DO NOT ADD ANY NEW CODE HERE.
-:: The bootstrap+del above are the final step of make.bat.
-:: If something must be added, add it to cmd/dist's cmdbootstrap,
-:: to avoid needing three copies in three different shell languages
-:: (make.bash, make.bat, make.rc).
-
-:copydist
-mkdir "%GOTOOLDIR%" 2>NUL
-copy cmd\dist\dist.exe "%GOTOOLDIR%\"
-goto end
-
-:bootstrapfail
-echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe
-echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go 1.4.
-
-:fail
-set GOBUILDFAIL=1
-if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
-
-:end
-
+:: Copyright 2012 The Go Authors. All rights reserved.\r
+:: Use of this source code is governed by a BSD-style\r
+:: license that can be found in the LICENSE file.\r
+\r
+:: Environment variables that control make.bat:\r
+::\r
+:: GOROOT_FINAL: The expected final Go root, baked into binaries.\r
+:: The default is the location of the Go tree during the build.\r
+::\r
+:: GOHOSTARCH: The architecture for host tools (compilers and\r
+:: binaries).  Binaries of this type must be executable on the current\r
+:: system, so the only common reason to set this is to set\r
+:: GOHOSTARCH=386 on an amd64 machine.\r
+::\r
+:: GOARCH: The target architecture for installed packages and tools.\r
+::\r
+:: GOOS: The target operating system for installed packages and tools.\r
+::\r
+:: GO_GCFLAGS: Additional go tool compile arguments to use when\r
+:: building the packages and commands.\r
+::\r
+:: GO_LDFLAGS: Additional go tool link arguments to use when\r
+:: building the commands.\r
+::\r
+:: CGO_ENABLED: Controls cgo usage during the build. Set it to 1\r
+:: to include all cgo related files, .c and .go file with "cgo"\r
+:: build directive, in the build. Set it to 0 to ignore them.\r
+::\r
+:: CC: Command line to run to compile C code for GOHOSTARCH.\r
+:: Default is "gcc".\r
+::\r
+:: CC_FOR_TARGET: Command line to run compile C code for GOARCH.\r
+:: This is used by cgo. Default is CC.\r
+::\r
+:: FC: Command line to run to compile Fortran code.\r
+:: This is used by cgo. Default is "gfortran".\r
+\r
+@echo off\r
+\r
+:: Keep environment variables within this script\r
+:: unless invoked with --no-local.\r
+if x%1==x--no-local goto nolocal\r
+if x%2==x--no-local goto nolocal\r
+if x%3==x--no-local goto nolocal\r
+if x%4==x--no-local goto nolocal\r
+setlocal\r
+:nolocal\r
+\r
+set GOENV=off\r
+set GOBUILDFAIL=0\r
+set GOFLAGS=\r
+set GO111MODULE=\r
+\r
+if exist make.bat goto ok\r
+echo Must run make.bat from Go src directory.\r
+goto fail\r
+:ok\r
+\r
+:: Clean old generated file that will cause problems in the build.\r
+del /F ".\pkg\runtime\runtime_defs.go" 2>NUL\r
+\r
+:: Set GOROOT for build.\r
+cd ..\r
+set GOROOT_TEMP=%CD%\r
+set GOROOT=\r
+cd src\r
+set vflag=\r
+if x%1==x-v set vflag=-v\r
+if x%2==x-v set vflag=-v\r
+if x%3==x-v set vflag=-v\r
+if x%4==x-v set vflag=-v\r
+\r
+if not exist ..\bin\tool mkdir ..\bin\tool\r
+\r
+:: Calculating GOROOT_BOOTSTRAP\r
+if not "x%GOROOT_BOOTSTRAP%"=="x" goto bootstrapset\r
+for /f "tokens=*" %%g in ('where go 2^>nul') do (\r
+       if "x%GOROOT_BOOTSTRAP%"=="x" (\r
+               for /f "tokens=*" %%i in ('%%g env GOROOT 2^>nul') do (\r
+                       if /I not %%i==%GOROOT_TEMP% (\r
+                               set GOROOT_BOOTSTRAP=%%i\r
+                       )\r
+               )\r
+       )\r
+)\r
+if "x%GOROOT_BOOTSTRAP%"=="x" set GOROOT_BOOTSTRAP=%HOMEDRIVE%%HOMEPATH%\Go1.4\r
+\r
+:bootstrapset\r
+if not exist "%GOROOT_BOOTSTRAP%\bin\go.exe" goto bootstrapfail\r
+set GOROOT=%GOROOT_TEMP%\r
+set GOROOT_TEMP=\r
+\r
+echo Building Go cmd/dist using %GOROOT_BOOTSTRAP%\r
+if x%vflag==x-v echo cmd/dist\r
+setlocal\r
+set GOROOT=%GOROOT_BOOTSTRAP%\r
+set GOOS=\r
+set GOARCH=\r
+set GOBIN=\r
+set GO111MODULE=off\r
+"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist\r
+endlocal\r
+if errorlevel 1 goto fail\r
+.\cmd\dist\dist.exe env -w -p >env.bat\r
+if errorlevel 1 goto fail\r
+call env.bat\r
+del env.bat\r
+if x%vflag==x-v echo.\r
+\r
+if x%1==x--dist-tool goto copydist\r
+if x%2==x--dist-tool goto copydist\r
+if x%3==x--dist-tool goto copydist\r
+if x%4==x--dist-tool goto copydist\r
+\r
+set buildall=-a\r
+if x%1==x--no-clean set buildall=\r
+if x%2==x--no-clean set buildall=\r
+if x%3==x--no-clean set buildall=\r
+if x%4==x--no-clean set buildall=\r
+if x%1==x--no-banner set buildall=%buildall% --no-banner\r
+if x%2==x--no-banner set buildall=%buildall% --no-banner\r
+if x%3==x--no-banner set buildall=%buildall% --no-banner\r
+if x%4==x--no-banner set buildall=%buildall% --no-banner\r
+\r
+:: Run dist bootstrap to complete make.bash.\r
+:: Bootstrap installs a proper cmd/dist, built with the new toolchain.\r
+:: Throw ours, built with Go 1.4, away after bootstrap.\r
+.\cmd\dist\dist.exe bootstrap %vflag% %buildall%\r
+if errorlevel 1 goto fail\r
+del .\cmd\dist\dist.exe\r
+goto end\r
+\r
+:: DO NOT ADD ANY NEW CODE HERE.\r
+:: The bootstrap+del above are the final step of make.bat.\r
+:: If something must be added, add it to cmd/dist's cmdbootstrap,\r
+:: to avoid needing three copies in three different shell languages\r
+:: (make.bash, make.bat, make.rc).\r
+\r
+:copydist\r
+mkdir "%GOTOOLDIR%" 2>NUL\r
+copy cmd\dist\dist.exe "%GOTOOLDIR%\"\r
+goto end\r
+\r
+:bootstrapfail\r
+echo ERROR: Cannot find %GOROOT_BOOTSTRAP%\bin\go.exe\r
+echo Set GOROOT_BOOTSTRAP to a working Go tree ^>= Go 1.4.\r
+\r
+:fail\r
+set GOBUILDFAIL=1\r
+if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%\r
+\r
+:end\r
index d26f3180a3c352611c77a4ed8a9454a6437f1548..8f0355612cb3f3d5b065ae41a3ea9a6a39fb60ca 100644 (file)
@@ -1,51 +1,51 @@
-:: Copyright 2013 The Go Authors. All rights reserved.
-:: Use of this source code is governed by a BSD-style
-:: license that can be found in the LICENSE file.
-
-:: race.bash tests the standard library under the race detector.
-:: https://golang.org/doc/articles/race_detector.html
-
-@echo off
-
-setlocal
-
-if exist make.bat goto ok
-echo race.bat must be run from go\src
-:: cannot exit: would kill parent command interpreter
-goto end
-:ok
-
-set GOROOT=%CD%\..
-call make.bat --dist-tool >NUL
-if errorlevel 1 goto fail
-.\cmd\dist\dist.exe env -w -p >env.bat
-if errorlevel 1 goto fail
-call env.bat
-del env.bat
-
-if %GOHOSTARCH% == amd64 goto continue
-echo Race detector is only supported on windows/amd64.
-goto fail
-
-:continue
-call make.bat --no-banner --no-local
-if %GOBUILDFAIL%==1 goto end
-echo # go install -race std
-go install -race std
-if errorlevel 1 goto fail
-
-go tool dist test -race
-
-if errorlevel 1 goto fail
-goto succ
-
-:fail
-set GOBUILDFAIL=1
-echo Fail.
-goto end
-
-:succ
-echo All tests passed.
-
-:end
-if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
+:: Copyright 2013 The Go Authors. All rights reserved.\r
+:: Use of this source code is governed by a BSD-style\r
+:: license that can be found in the LICENSE file.\r
+\r
+:: race.bash tests the standard library under the race detector.\r
+:: https://golang.org/doc/articles/race_detector.html\r
+\r
+@echo off\r
+\r
+setlocal\r
+\r
+if exist make.bat goto ok\r
+echo race.bat must be run from go\src\r
+:: cannot exit: would kill parent command interpreter\r
+goto end\r
+:ok\r
+\r
+set GOROOT=%CD%\..\r
+call make.bat --dist-tool >NUL\r
+if errorlevel 1 goto fail\r
+.\cmd\dist\dist.exe env -w -p >env.bat\r
+if errorlevel 1 goto fail\r
+call env.bat\r
+del env.bat\r
+\r
+if %GOHOSTARCH% == amd64 goto continue\r
+echo Race detector is only supported on windows/amd64.\r
+goto fail\r
+\r
+:continue\r
+call make.bat --no-banner --no-local\r
+if %GOBUILDFAIL%==1 goto end\r
+echo # go install -race std\r
+go install -race std\r
+if errorlevel 1 goto fail\r
+\r
+go tool dist test -race\r
+\r
+if errorlevel 1 goto fail\r
+goto succ\r
+\r
+:fail\r
+set GOBUILDFAIL=1\r
+echo Fail.\r
+goto end\r
+\r
+:succ\r
+echo All tests passed.\r
+\r
+:end\r
+if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%\r
index 69c181854b026a5e942428a7c63d1e12f884140c..90602b68cb4cbb81be958778fafd1107873f93f1 100644 (file)
@@ -1,59 +1,59 @@
-:: Copyright 2012 The Go Authors. All rights reserved.
-:: Use of this source code is governed by a BSD-style
-:: license that can be found in the LICENSE file.
-
-@echo off
-
-if exist ..\bin\go.exe goto ok
-echo Must run run.bat from Go src directory after installing cmd/go.
-goto fail
-:ok
-
-:: Keep environment variables within this script
-:: unless invoked with --no-local.
-if x%1==x--no-local goto nolocal
-if x%2==x--no-local goto nolocal
-setlocal
-:nolocal
-
-set GOBUILDFAIL=0
-
-:: we disallow local import for non-local packages, if %GOROOT% happens
-:: to be under %GOPATH%, then some tests below will fail
-set GOPATH=
-:: Issue 14340: ignore GOBIN during all.bat.
-set GOBIN=
-set GOFLAGS=
-set GO111MODULE=
-
-rem TODO avoid rebuild if possible
-
-if x%1==x--no-rebuild goto norebuild
-echo ##### Building packages and commands.
-..\bin\go install -a -v std cmd
-if errorlevel 1 goto fail
-echo.
-:norebuild
-
-:: we must unset GOROOT_FINAL before tests, because runtime/debug requires
-:: correct access to source code, so if we have GOROOT_FINAL in effect,
-:: at least runtime/debug test will fail.
-set GOROOT_FINAL=
-
-:: get CGO_ENABLED
-..\bin\go env > env.bat
-if errorlevel 1 goto fail
-call env.bat
-del env.bat
-echo.
-
-..\bin\go tool dist test
-if errorlevel 1 goto fail
-echo.
-
-goto end
-
-:fail
-set GOBUILDFAIL=1
-
-:end
+:: Copyright 2012 The Go Authors. All rights reserved.\r
+:: Use of this source code is governed by a BSD-style\r
+:: license that can be found in the LICENSE file.\r
+\r
+@echo off\r
+\r
+if exist ..\bin\go.exe goto ok\r
+echo Must run run.bat from Go src directory after installing cmd/go.\r
+goto fail\r
+:ok\r
+\r
+:: Keep environment variables within this script\r
+:: unless invoked with --no-local.\r
+if x%1==x--no-local goto nolocal\r
+if x%2==x--no-local goto nolocal\r
+setlocal\r
+:nolocal\r
+\r
+set GOBUILDFAIL=0\r
+\r
+:: we disallow local import for non-local packages, if %GOROOT% happens\r
+:: to be under %GOPATH%, then some tests below will fail\r
+set GOPATH=\r
+:: Issue 14340: ignore GOBIN during all.bat.\r
+set GOBIN=\r
+set GOFLAGS=\r
+set GO111MODULE=\r
+\r
+rem TODO avoid rebuild if possible\r
+\r
+if x%1==x--no-rebuild goto norebuild\r
+echo ##### Building packages and commands.\r
+..\bin\go install -a -v std cmd\r
+if errorlevel 1 goto fail\r
+echo.\r
+:norebuild\r
+\r
+:: we must unset GOROOT_FINAL before tests, because runtime/debug requires\r
+:: correct access to source code, so if we have GOROOT_FINAL in effect,\r
+:: at least runtime/debug test will fail.\r
+set GOROOT_FINAL=\r
+\r
+:: get CGO_ENABLED\r
+..\bin\go env > env.bat\r
+if errorlevel 1 goto fail\r
+call env.bat\r
+del env.bat\r
+echo.\r
+\r
+..\bin\go tool dist test\r
+if errorlevel 1 goto fail\r
+echo.\r
+\r
+goto end\r
+\r
+:fail\r
+set GOBUILDFAIL=1\r
+\r
+:end\r
index 30e0e3c982e389c56fcfbba114110b2e179c1c1d..c3b48d385cecc8bd1dd4ddfa5e1a8b1377750283 100644 (file)
@@ -4,8 +4,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Check that batch files are maintained as CRLF files (consistent behaviour
-// on all operating systems). See https://github.com/golang/go/issues/37791
+// Check that batch files are maintained as CRLF files (consistent
+// behavior on all operating systems). See golang.org/issue/37791.
 
 package main
 
@@ -13,18 +13,56 @@ import (
        "bytes"
        "fmt"
        "io/ioutil"
+       "log"
        "os"
        "path/filepath"
        "runtime"
+       "strings"
 )
 
 func main() {
-       batches, _ := filepath.Glob(runtime.GOROOT() + "/src/*.bat")
-       for _, bat := range batches {
-               body, _ := ioutil.ReadFile(bat)
-               if !bytes.Contains(body, []byte("\r\n")) {
-                       fmt.Printf("Windows batch file %s does not contain CRLF line termination.\nTry running git checkout src/*.bat to fix this.\n", bat)
-                       os.Exit(1)
+       // Ensure that the GOROOT/src/all.bat file exists and has strict CRLF line endings.
+       enforceBatchStrictCRLF(filepath.Join(runtime.GOROOT(), "src", "all.bat"))
+
+       // Walk the entire Go repository source tree (without GOROOT/pkg),
+       // skipping directories that start with "." and named "testdata",
+       // and ensure all .bat files found have exact CRLF line endings.
+       err := filepath.Walk(runtime.GOROOT(), func(path string, fi os.FileInfo, err error) error {
+               if err != nil {
+                       return err
+               }
+               if fi.IsDir() && (strings.HasPrefix(fi.Name(), ".") || fi.Name() == "testdata") {
+                       return filepath.SkipDir
+               }
+               if path == filepath.Join(runtime.GOROOT(), "pkg") {
+                       // GOROOT/pkg is known to contain generated artifacts, not source code.
+                       // Skip it to avoid false positives. (Also see golang.org/issue/37929.)
+                       return filepath.SkipDir
+               }
+               if filepath.Ext(fi.Name()) == ".bat" {
+                       enforceBatchStrictCRLF(path)
+               }
+               return nil
+       })
+       if err != nil {
+               log.Fatalln(err)
+       }
+}
+
+func enforceBatchStrictCRLF(path string) {
+       b, err := ioutil.ReadFile(path)
+       if err != nil {
+               log.Fatalln(err)
+       }
+       cr, lf := bytes.Count(b, []byte{13}), bytes.Count(b, []byte{10})
+       crlf := bytes.Count(b, []byte{13, 10})
+       if cr != crlf || lf != crlf {
+               if rel, err := filepath.Rel(runtime.GOROOT(), path); err == nil {
+                       // Make the test failure more readable by showing a path relative to GOROOT.
+                       path = rel
                }
+               fmt.Printf("Windows batch file %s does not use strict CRLF line termination.\n", path)
+               fmt.Printf("Please convert it to CRLF before checking it in due to golang.org/issue/37791.\n")
+               os.Exit(1)
        }
 }