Skip to content

Commit 514964b

Browse files
committed
gopls/internal/hooks: improve license file test
Now that we're only including licenses for the things gopls actually depends on, we don't need to access the network on the trybots, and we can get rid of the go.sum check that adds a step to the release process. Change-Id: I3d38334ea3a9c904dfa125157c7b0468a0699b54 Reviewed-on: https://go-review.googlesource.com/c/tools/+/286436 Trust: Heschi Kreinick <heschi@google.com> Run-TryBot: Heschi Kreinick <heschi@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
1 parent 68bf78a commit 514964b

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

gopls/internal/hooks/gen-licenses.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66

77
set -o pipefail
88

9+
output=$1
910
tempfile=$(mktemp)
1011
cd $(dirname $0)
1112

12-
modhash=$(sha256sum ../../go.sum | awk '{print $1}')
13-
# Make sure we have the code for all the modules we depend on.
14-
go mod download
15-
1613
cat > $tempfile <<END
1714
// Copyright 2020 The Go Authors. All rights reserved.
1815
// Use of this source code is governed by a BSD-style
@@ -37,9 +34,5 @@ for mod in $mods; do
3734
echo >> $tempfile
3835
done
3936

40-
cat >> $tempfile << END
41-
\`
42-
43-
const licensesGeneratedFrom = "$modhash"
44-
END
45-
mv $tempfile licenses.go
37+
echo "\`" >> $tempfile
38+
mv $tempfile $output

gopls/internal/hooks/licenses.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,3 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
167167
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
168168
169169
`
170-
171-
const licensesGeneratedFrom = "029a0f934a7bad22a7d47185055bc554b1ea23ce427351caa87d9a088fcfba4e"

gopls/internal/hooks/licenses_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,36 @@
55
package hooks
66

77
import (
8-
"crypto/sha256"
9-
"encoding/hex"
8+
"bytes"
109
"io/ioutil"
10+
"os/exec"
11+
"runtime"
1112
"testing"
1213
)
1314

1415
func TestLicenses(t *testing.T) {
15-
sumBytes, err := ioutil.ReadFile("../../go.sum")
16+
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
17+
t.Skip("generating licenses only works on Unixes")
18+
}
19+
tmp, err := ioutil.TempFile("", "")
20+
if err != nil {
21+
t.Fatal(err)
22+
}
23+
tmp.Close()
24+
25+
if out, err := exec.Command("./gen-licenses.sh", tmp.Name()).CombinedOutput(); err != nil {
26+
t.Fatalf("generating licenses failed: %q, %v", out, err)
27+
}
28+
29+
got, err := ioutil.ReadFile(tmp.Name())
30+
if err != nil {
31+
t.Fatal(err)
32+
}
33+
want, err := ioutil.ReadFile("licenses.go")
1634
if err != nil {
1735
t.Fatal(err)
1836
}
19-
sumSum := sha256.Sum256(sumBytes)
20-
if licensesGeneratedFrom != hex.EncodeToString(sumSum[:]) {
37+
if !bytes.Equal(got, want) {
2138
t.Error("combined license text needs updating. Run: `go generate ./internal/hooks` from the gopls module.")
2239
}
2340
}

0 commit comments

Comments
 (0)