on the portability of make.bash

138 views
Skip to first unread message

Eric Grosse

unread,
Apr 11, 2024, 6:56:04 PM4/11/24
to golang-nuts

In 2012 Russ wisely and definitively addressed portability of make.bash:

We are aware of the history of incompatibilities between shells.

For a while we did try to write portable shell scripts, but that

was distracting us from the real work of writing Go

[https://github.com/golang/go/issues/3235#issuecomment-66064352]

For those who care, Korn shell suffices for compiling from source. A Go bootstrap from somewhere you trust and a default OpenBSD install is enough without any other dependencies. This is of interest for those of us scrutinizing software supply chain security these days. Here's the trick:

ed make.bash

/build -o

s/.*/(&)

wq

ksh make.bash


If you're curious, what's happening is that

foo() {

"$@"

}

export R=r

R=s foo date

echo $R

prints "r" in bash but "s" in ksh.  Adding the parens in make.bash runs the dist build in a subshell and does the right thing for setting GOROOT under both shells.


It would be nice to upstream that two-character change so we can match tree hashes, but only if it is clearly understood that the team is not making any promise of future support for anything other than bash. Even with my change, ksh still prints a warning about "-a" being an unknown arg to the "type" builtin, though fortunately that doesn't affect my use case. I have done no testing of other Go tools when bash is missing.


Reply all
Reply to author
Forward
0 new messages