]> Cypherpunks.ru repositories - gostls13.git/commitdiff
build: force all Windows batch files to CRLF
authorGiovanni Bajo <rasky@develer.com>
Sun, 22 Mar 2020 08:28:21 +0000 (09:28 +0100)
committerGiovanni Bajo <rasky@develer.com>
Sun, 22 Mar 2020 08:42:38 +0000 (08:42 +0000)
Batch files should use CRLF endings. LF endings mostly
work but in some situations they cause random errors like
goto commands failing for mysterious reasons. See
golang.org/issue/37791 for more information.

Next CL triggered one of such bug (a label was not being
recognized), so prepare for it by converting to CRLF.

This CL also touches all existing batch files to force git
to update the line endings (unfortunately, changing
.gitattributes only has effect next time the file is checked
out or modified).

Fixes #37791
Updates #9281

Change-Id: I6f9a114351cb7ac9881914400aa210c930eb8cc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/96495
Run-TryBot: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
.gitattributes
src/all.bat
src/clean.bat
src/make.bat
src/race.bat
src/run.bat
test/winbatch.go [new file with mode: 0644]

index 07953cae39ba75dbf550a5ce013974ca1e829206..bcea0290f4c8d9197fc7d7c055a8055126278078 100644 (file)
@@ -8,3 +8,9 @@
 # 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 0647a715ba2463718b385800d1de0f53f005b29e..8bbd6b1b5dae5c0b1b893d0364557c327893965d 100644 (file)
@@ -1,6 +1,7 @@
 :: 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
index 3cc6a689bc2e46537106fac196aa28c93eb7c68b..0954dcd67f191f373840769a04562ae7916613a7 100644 (file)
@@ -1,6 +1,7 @@
 :: 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
index d18cd87d48465d93a340b9a401a80ba1f1fdd054..5dbde85564e9ff3166e11e5b404db9a2bcdf25fc 100644 (file)
@@ -132,3 +132,4 @@ set GOBUILDFAIL=1
 if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
 
 :end
+
index e1c3fbf5d9c6407b19316c861e38bff59893ae6b..d26f3180a3c352611c77a4ed8a9454a6437f1548 100644 (file)
@@ -49,4 +49,3 @@ echo All tests passed.
 
 :end
 if x%GOBUILDEXIT%==x1 exit %GOBUILDFAIL%
-
index 123edcc35dd7d636bfb14d2ce38f99a0483f3b0c..25ee58001ef4b0f23c82984b6ead8c98b9633311 100644 (file)
@@ -1,6 +1,7 @@
 :: 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
 
 :: Keep environment variables within this script
diff --git a/test/winbatch.go b/test/winbatch.go
new file mode 100644 (file)
index 0000000..30e0e3c
--- /dev/null
@@ -0,0 +1,30 @@
+// run
+
+// Copyright 2020 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.
+
+// Check that batch files are maintained as CRLF files (consistent behaviour
+// on all operating systems). See https://github.com/golang/go/issues/37791
+
+package main
+
+import (
+       "bytes"
+       "fmt"
+       "io/ioutil"
+       "os"
+       "path/filepath"
+       "runtime"
+)
+
+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)
+               }
+       }
+}