1#!/bin/bash -eu
2
3# Copyright 2020 The Go Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6
7set -o pipefail
8
9output=$1
10tempfile=$(mktemp)
11cd $(dirname $0)
12
13cat > $tempfile <<END
14// Copyright 2020 The Go Authors. All rights reserved.
15// Use of this source code is governed by a BSD-style
16// license that can be found in the LICENSE file.
17
18//go:generate ./gen-licenses.sh licenses.go
19package hooks
20
21const licensesText = \`
22END
23
24# List all the modules gopls depends on, except other golang.org modules, which
25# are known to have the same license.
26mods=$(go list -deps -f '{{with .Module}}{{.Path}}{{end}}' golang.org/x/tools/gopls | sort -u | grep -v golang.org)
27for mod in $mods; do
28  # Find the license file, either LICENSE or COPYING, and add it to the result.
29  dir=$(go list -m -f {{.Dir}} $mod)
30  license=$(ls -1 $dir | egrep -i '^(LICENSE|COPYING)$')
31  echo "-- $mod $license --" >> $tempfile
32  echo >> $tempfile
33  sed 's/^-- / &/' $dir/$license >> $tempfile
34  echo >> $tempfile
35done
36
37echo "\`" >> $tempfile
38mv $tempfile $output