Skip to content

Commit

Permalink
go: install binaries to /usr/lib/go/bin/
Browse files Browse the repository at this point in the history
- 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]: golang/go#61921 (comment)
  • Loading branch information
Cyanoxygen authored and MingcongBai committed Sep 21, 2023
1 parent 89a6cae commit 835cffb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lang-golang/go/autobuild/alternatives
Original file line number Diff line number Diff line change
@@ -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
17 changes: 7 additions & 10 deletions lang-golang/go/autobuild/build
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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"
Expand All @@ -103,17 +99,18 @@ 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 ..."
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/
Expand Down
17 changes: 7 additions & 10 deletions lang-golang/go/autobuild/build.stage2
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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"
Expand All @@ -110,17 +106,18 @@ 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 ..."
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/
Expand Down

0 comments on commit 835cffb

Please sign in to comment.