From cde8f697a96db9c24d428a9c2e4743e38cd69681 Mon Sep 17 00:00:00 2001
From: George Hartzell <hartzell@alerce.com>
Date: Thu, 24 Nov 2016 12:25:51 -0800
Subject: [PATCH] Bugfix/update go packages (#2369)

* Update go-bootstrap package

The last C based Go src tree was the 1.4 series.  For a while they
were cutting new releases so that people could bootstrap from a C only
system.  Now they're recommending that you either use the release-1.4
branch or that you use a date-stamped tarball that they'll produce on
an as-needed basis.

There are several issues that keep 1.4.2 from building on a CentOS 7
system.

I've switched to the date based tarball.

The cgo bits were also mis-behaving, but they're not needed for the
bootstrapping task so I've set an environment variable that disables
them.

Details [on the install-from-source
page](https://golang.org/doc/install/source#go14) and these issues:

- https://github.com/golang/go/issues/17545
- https://github.com/golang/go/issues/16352.

* Update go package

Switched from pulling from the git repository to using the source
tarballs and added digest values.

Added support for 1.7.3, continued supporting 1.6.2, including patches
for a couple of problems (details in
[17545](https://github.com/golang/go/issues/17545) and
[17986](https://github.com/golang/go/issues/17986).

Dropped support for 1.5.4 and 1.4.2 because they no longer pass their
tests and the patches above to not apply.
---
 .../builtin/packages/go-bootstrap/package.py   | 12 ++++++++----
 .../packages/go/misc-cgo-testcshared.patch     | 11 +++++++++++
 var/spack/repos/builtin/packages/go/package.py | 16 ++++++++++++----
 .../repos/builtin/packages/go/time_test.patch  | 18 ++++++++++++++++++
 4 files changed, 49 insertions(+), 8 deletions(-)
 create mode 100644 var/spack/repos/builtin/packages/go/misc-cgo-testcshared.patch
 create mode 100644 var/spack/repos/builtin/packages/go/time_test.patch

diff --git a/var/spack/repos/builtin/packages/go-bootstrap/package.py b/var/spack/repos/builtin/packages/go-bootstrap/package.py
index d48c7c9756..77a074e809 100644
--- a/var/spack/repos/builtin/packages/go-bootstrap/package.py
+++ b/var/spack/repos/builtin/packages/go-bootstrap/package.py
@@ -41,14 +41,17 @@ class GoBootstrap(Package):
 
     extendable = True
 
-    # NOTE: Go@1.4.2 is the only supported bootstrapping compiler because all
+    # NOTE: Go@1.4.x is the only supported bootstrapping compiler because all
     # later versions require a Go compiler to build.
-    # See: https://golang.org/doc/install/source
-    version('1.4.2', git='https://go.googlesource.com/go', tag='go1.4.2')
+    # See: https://golang.org/doc/install/source#go14 and
+    # https://github.com/golang/go/issues/17545 and
+    # https://github.com/golang/go/issues/16352
+    version('1.4-bootstrap-20161024', '76e42c8152e8560ded880a6d1d1f53cb',
+            url='https://storage.googleapis.com/golang/go1.4-bootstrap-20161024.tar.gz')
 
     variant('test', default=True, description='Build and run tests as part of the build.')
 
-    provides('golang@:1.4.2')
+    provides('golang@:1.4-bootstrap-20161024')
 
     depends_on('git', type='alldeps')
 
@@ -69,6 +72,7 @@ def patch(self):
         pass
 
     def install(self, spec, prefix):
+        env['CGO_ENABLED'] = '0'
         bash = which('bash')
         with working_dir('src'):
             bash('{0}.bash'.format('all' if '+test' in spec else 'make'))
diff --git a/var/spack/repos/builtin/packages/go/misc-cgo-testcshared.patch b/var/spack/repos/builtin/packages/go/misc-cgo-testcshared.patch
new file mode 100644
index 0000000000..17751df816
--- /dev/null
+++ b/var/spack/repos/builtin/packages/go/misc-cgo-testcshared.patch
@@ -0,0 +1,11 @@
+--- misc/cgo/testcshared/test.bash.orig	2016-11-19 00:00:11.917000000 +0000
++++ misc/cgo/testcshared/test.bash	2016-11-19 00:00:22.081000000 +0000
+@@ -107,7 +107,7 @@
+ 
+ # test0: exported symbols in shared lib are accessible.
+ # TODO(iant): using _shared here shouldn't really be necessary.
+-$(go env CC) ${GOGCCFLAGS} -I ${installdir} -o testp main0.c libgo.$libext
++$(go env CC) ${GOGCCFLAGS} -I ${installdir} -o testp main0.c ./libgo.$libext
+ binpush testp
+ 
+ output=$(run LD_LIBRARY_PATH=. ./testp)
diff --git a/var/spack/repos/builtin/packages/go/package.py b/var/spack/repos/builtin/packages/go/package.py
index 5fa3017ab5..7f4d509466 100644
--- a/var/spack/repos/builtin/packages/go/package.py
+++ b/var/spack/repos/builtin/packages/go/package.py
@@ -32,13 +32,12 @@
 class Go(Package):
     """The golang compiler and build environment"""
     homepage = "https://golang.org"
-    url = "https://go.googlesource.com/go"
+    url='https://storage.googleapis.com/golang/go1.7.3.src.tar.gz'
 
     extendable = True
 
-    version('1.6.2', git='https://go.googlesource.com/go', tag='go1.6.2')
-    version('1.5.4', git='https://go.googlesource.com/go', tag='go1.5.4')
-    version('1.4.2', git='https://go.googlesource.com/go', tag='go1.4.2')
+    version('1.7.3', '83d1b7bd4281479ab7d153e5152c9fc9')
+    version('1.6.2', 'd1b50fa98d9a71eeee829051411e6207')
 
     variant('test', default=True, description='Build and run tests as part of the build.')
 
@@ -49,6 +48,12 @@ class Go(Package):
     # should be a dep on external go compiler
     depends_on('go-bootstrap', type='build')
 
+    # https://github.com/golang/go/issues/17545
+    patch('time_test.patch', when='@1.6.2:1.7.3')
+
+    # https://github.com/golang/go/issues/17986
+    patch('misc-cgo-testcshared.patch', level=0, when='@1.6.2:1.7.3')
+
     # NOTE: Older versions of Go attempt to download external files that have
     # since been moved while running the test suite.  This patch modifies the
     # test files so that these tests don't cause false failures.
@@ -65,6 +70,9 @@ def patch(self):
     def patch(self):
         pass
 
+    def url_for_version(self, version):
+        return "https://storage.googleapis.com/golang/go{0}.src.tar.gz".format(version)
+
     def install(self, spec, prefix):
         bash = which('bash')
         with working_dir('src'):
diff --git a/var/spack/repos/builtin/packages/go/time_test.patch b/var/spack/repos/builtin/packages/go/time_test.patch
new file mode 100644
index 0000000000..c3e0697c91
--- /dev/null
+++ b/var/spack/repos/builtin/packages/go/time_test.patch
@@ -0,0 +1,18 @@
+diff --git a/src/time/time_test.go b/src/time/time_test.go
+index 68236fd..2e47d08 100644
+--- a/src/time/time_test.go
++++ b/src/time/time_test.go
+@@ -943,8 +943,11 @@ func TestLoadFixed(t *testing.T) {
+ 	// but Go and most other systems use "east is positive".
+ 	// So GMT+1 corresponds to -3600 in the Go zone, not +3600.
+ 	name, offset := Now().In(loc).Zone()
+-	if name != "GMT+1" || offset != -1*60*60 {
+-		t.Errorf("Now().In(loc).Zone() = %q, %d, want %q, %d", name, offset, "GMT+1", -1*60*60)
++	// The zone abbreviation is "-01" since tzdata-2016g, and "GMT+1"
++	// on earlier versions; we accept both. (Issue #17276).
++	if !(name == "GMT+1" || name == "-01") || offset != -1*60*60 {
++		t.Errorf("Now().In(loc).Zone() = %q, %d, want %q or %q, %d",
++			name, offset, "GMT+1", "-01", -1*60*60)
+ 	}
+ }
+ 
-- 
GitLab