67.12. gopls-0.23.0
The Go language server
| Version | 0.23.0, release 1 |
| Shelf | devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities |
| Phase | 40_lang (Languages), 20 of 186 in build order |
| Licence | BSD-3-Clause |
| Homepage | https://pkg.go.dev/golang.org/x/tools/gopls |
| Build time | 1.3 SBU |
| Installed size | 32.9 MiB in 4 files |
| Recipe | ports/core/devtools/gopls/kpkgbuild |
About
gopls is the Go language server, which editors run for completion, navigation, diagnostics and refactoring of Go code. It is built with cgo off from its vendor bundle; see go. It works against the installed go toolchain.
Why it is in KDOS
The comment above it in script/phases/40_lang/packages.d/devtools.txt:
The module is not at the tarball root: x/tools tags a gopls release and ships gopls as a subdirectory with its own go.mod, which is what the
vendordir =helper exists for.
Sources
gopls-0.23.0.tar.gz(8.1 MiB)
sha2561ba41875b918db73c6a409ad8f552b85f72dfeea43ffb541b798322ff6b4152b
upstream: https://github.com/golang/tools/archive/refs/tags/gopls/v0.23.0.tar.gz
archive copy: sources-1/devtools--gopls-0.23.0.tar.gzgopls-vendor-0.23.0.tar.xz(2.2 MiB)
sha256a31b71f90a2d519a30501eeaaa4873da87d7c8210dcd1981ce0fee9d9e48a9b1
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-1/devtools--gopls-vendor-0.23.0.tar.xz
Dependencies
Depends on: go.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/40_lang/phase.env && kpkg install gopls'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/devtools/gopls.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/devtools/gopls
echo '1ba41875b918db73c6a409ad8f552b85f72dfeea43ffb541b798322ff6b4152b gopls-0.23.0.tar.gz' | sha256sum -c -
echo 'a31b71f90a2d519a30501eeaaa4873da87d7c8210dcd1981ce0fee9d9e48a9b1 gopls-vendor-0.23.0.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/gopls
SRC=$SRC_ROOT/gopls-0.23.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf gopls-0.23.0.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers vendordir and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz -C $vendordir
cd $vendordir
export CGO_ENABLED=0
go build -mod=vendor -ldflags "-s -w" -o gopls
install -Dm755 gopls $PKG/usr/bin/gopls
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/gopls, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf gopls-0.23.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/gopls, and runs the triggers its paths call for.
Contents
Installed programs: gopls.
Installed directories: /usr/share/licenses/gopls.
Notes
The source is the gopls/v<version> tag of golang.org/x/tools, and gopls is not the module at the top of that tree: it is the gopls subdirectory, with a go.mod of its own. The recipe’s vendordir = gopls makes ports/fetch run go mod vendor there (see Keys other tools read), and build.sh unpacks the bundle into the same directory and builds from it. A bundle made at the top of the tree would vendor the parent x/tools module instead.