From 835cffb6ac3305a7d531ef6c7a3440eb7c1d851c Mon Sep 17 00:00:00 2001 From: Cyan Date: Sun, 3 Sep 2023 20:21:19 +0800 Subject: [PATCH] go: install binaries to /usr/lib/go/bin/ - Before this, go and gofmt was installed to /usr/bin, which confuses Go as it can not figure out $GOROOT automatically by os.Executable, see [1] for details. By installing binaries to $GOROOT/bin (GOROOT points to /usr/lib/go), go can now figure out its GOROOT. - Provide symlinks in /usr/bin/go{,fmt}-google to ensure it is there. - Update alternatives file to point corresponding executables to the one installed in $GOROOT. [1]: https://github.com/golang/go/issues/61921#issuecomment-1673399370 --- lang-golang/go/autobuild/alternatives | 4 ++-- lang-golang/go/autobuild/build | 17 +++++++---------- lang-golang/go/autobuild/build.stage2 | 17 +++++++---------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lang-golang/go/autobuild/alternatives b/lang-golang/go/autobuild/alternatives index 9b1a2669c10..6812feec41b 100644 --- a/lang-golang/go/autobuild/alternatives +++ b/lang-golang/go/autobuild/alternatives @@ -1,2 +1,2 @@ -alternative /usr/bin/go /usr/bin/go-google 80 -alternative /usr/bin/gofmt /usr/bin/gofmt-google 80 +alternative /usr/bin/go /usr/lib/go/bin/go 80 +alternative /usr/bin/gofmt /usr/lib/go/bin/gofmt 80 diff --git a/lang-golang/go/autobuild/build b/lang-golang/go/autobuild/build index 9199952e206..ae2a1455c75 100644 --- a/lang-golang/go/autobuild/build +++ b/lang-golang/go/autobuild/build @@ -59,9 +59,9 @@ cp -rv "$SRCDIR"/{doc,misc} \ ln -sv ../../share/go/doc \ "$PKGDIR/usr/lib/go/doc" cp -av "$SRCDIR"/bin \ - "$PKGDIR/usr" + "$PKGDIR/usr/lib/go/" cp -av "$SRCDIR"/pkg \ - "$PKGDIR/usr/lib/go" + "$PKGDIR/usr/lib/go/" cp -av "$GOROOT/src" \ "$PKGDIR/usr/lib/go/" cp -av "$GOROOT/src/cmd" \ @@ -83,10 +83,6 @@ abinfo "Setting executable bit for sql.go ..." find "$PKGDIR" \ -type f -name sql.go -exec chmod -v -x {} \; -abinfo "Creating a symlink for /usr/lib/go/bin to /usr/bin ..." -ln -svf ../../bin \ - "$PKGDIR/usr/lib/go/bin" - abinfo "Installing build scripts ..." install -Dvm755 "$SRCDIR"/src/make.bash \ "$PKGDIR/usr/lib/go/src/make.bash" @@ -103,7 +99,7 @@ install -Dvm644 "$SRCDIR"/VERSION \ "$PKGDIR/usr/lib/go/VERSION" abinfo "Touching all installed files ..." -find "$PKGDIR"/usr/{lib/go/pkg,bin} \ +find "$PKGDIR"/usr/lib/go/{pkg,bin} \ -type f -exec touch '{}' + abinfo "Installing basic Go tools ..." @@ -111,9 +107,10 @@ install -dvm755 "$PKGDIR"/usr/lib/go/pkg/tool/"${GOOS}"_"$GOARCH" install -pvm755 "$SRCDIR"/pkg/tool/"${GOOS}"_"$GOARCH"/* \ "$PKGDIR"/usr/lib/go/pkg/tool/"${GOOS}"_"$GOARCH" -abinfo "Renaming go and gofmt for alternatives ..." -mv -v "$PKGDIR"/usr/bin/go{,-google} -mv -v "$PKGDIR"/usr/bin/gofmt{,-google} +abinfo "Linking go and gofmt installed in GOROOT to /usr/bin ..." +mkdir "$PKGDIR"/usr/bin +ln -sfv ../lib/go/bin/go "$PKGDIR"/usr/bin/go-google +ln -sfv ../lib/go/bin/gofmt "$PKGDIR"/usr/bin/gofmt-google abinfo "Preparing to build extra Go tools ..." mkdir -pv "$SRCDIR"/go-tools/src/golang.org/x/ diff --git a/lang-golang/go/autobuild/build.stage2 b/lang-golang/go/autobuild/build.stage2 index b99c4d9c9fa..82de1343844 100644 --- a/lang-golang/go/autobuild/build.stage2 +++ b/lang-golang/go/autobuild/build.stage2 @@ -66,9 +66,9 @@ cp -rv "$SRCDIR"/{doc,misc} \ ln -sv ../../share/go/doc \ "$PKGDIR/usr/lib/go/doc" cp -av "$SRCDIR"/bin \ - "$PKGDIR/usr" + "$PKGDIR/usr/lib/go/" cp -av "$SRCDIR"/pkg \ - "$PKGDIR/usr/lib/go" + "$PKGDIR/usr/lib/go/" cp -av "$GOROOT/src" \ "$PKGDIR/usr/lib/go/" cp -av "$GOROOT/src/cmd" \ @@ -90,10 +90,6 @@ abinfo "Setting executable bit for sql.go ..." find "$PKGDIR" \ -type f -name sql.go -exec chmod -v -x {} \; -abinfo "Creating a symlink for /usr/lib/go/bin to /usr/bin ..." -ln -svf ../../bin \ - "$PKGDIR/usr/lib/go/bin" - abinfo "Installing build scripts ..." install -Dvm755 "$SRCDIR"/src/make.bash \ "$PKGDIR/usr/lib/go/src/make.bash" @@ -110,7 +106,7 @@ install -Dvm644 "$SRCDIR"/VERSION \ "$PKGDIR/usr/lib/go/VERSION" abinfo "Touching all installed files ..." -find "$PKGDIR"/usr/{lib/go/pkg,bin} \ +find "$PKGDIR"/usr/lib/go/{pkg,bin} \ -type f -exec touch '{}' + abinfo "Installing basic Go tools ..." @@ -118,9 +114,10 @@ install -dvm755 "$PKGDIR"/usr/lib/go/pkg/tool/"${GOOS}"_"$GOARCH" install -pvm755 "$SRCDIR"/pkg/tool/"${GOOS}"_"$GOARCH"/* \ "$PKGDIR"/usr/lib/go/pkg/tool/"${GOOS}"_"$GOARCH" -abinfo "Renaming go and gofmt for alternatives ..." -mv -v "$PKGDIR"/usr/bin/go{,-google} -mv -v "$PKGDIR"/usr/bin/gofmt{,-google} +abinfo "Linking go and gofmt installed in GOROOT to /usr/bin ..." +mkdir "$PKGDIR"/usr/bin +ln -sfv ../lib/go/bin/go "$PKGDIR"/usr/bin/go-google +ln -sfv ../lib/go/bin/gofmt "$PKGDIR"/usr/bin/gofmt-google abinfo "Preparing to build extra Go tools ..." mkdir -pv "$SRCDIR"/go-tools/src/golang.org/x/