Skip to content

Commit 79600ec

Browse files
dmitshurgopherbot
authored andcommitted
internal/buildgo: handle different layout of go.dev/dl/ tarballs
The genbootstrap-generated bootstrap tarballs placed all files at the root of the tarball, while the go.dev/dl/ tarballs place them in 'go'. So when using a tarball from go.dev/dl/ as the bootstrap toolchain, the previously working GOROOT_BOOTSTRAP=$WORKDIR/go1.4 now ends up needing a slight change to GOROOT_BOOTSTRAP=$WORKDIR/go1.4/go. This was missed in CL 520901. Fix it now, so that it's possible to switch to using the go.dev/dl/ tarballs as originally intended there. Balance out this new complexity slightly by removing a condition for leaving out the -force flag. The Go 1.20 release branch has aged out. Change-Id: I6e598e66020e46cc11d40b21663ddb6bd6792fb2 Reviewed-on: https://go-review.googlesource.com/c/build/+/606835 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent bba03e4 commit 79600ec

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

cmd/coordinator/buildstatus.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,19 +599,15 @@ func (st *buildStatus) SpanRecord(sp *schedule.Span, err error) *types.SpanRecor
599599

600600
// goBuilder returns a GoBuilder for this buildStatus.
601601
func (st *buildStatus) goBuilder() buildgo.GoBuilder {
602-
forceMake := true
603-
if st.RevBranch == "release-branch.go1.20" {
604-
// The concept of "broken ports" and -force flag didn't
605-
// exist prior to Go 1.21. See go.dev/issue/56679.
606-
// TODO: Remove this condition when Go 1.20 is no longer supported.
607-
forceMake = false
608-
}
602+
goDevDLBootstrap := strings.HasPrefix(
603+
st.conf.GoBootstrapURL(pool.NewGCEConfiguration().BuildEnv()), "https://go.dev/dl/")
609604
return buildgo.GoBuilder{
610-
Logger: st,
611-
BuilderRev: st.BuilderRev,
612-
Conf: st.conf,
613-
Goroot: "go",
614-
Force: forceMake,
605+
Logger: st,
606+
BuilderRev: st.BuilderRev,
607+
Conf: st.conf,
608+
Goroot: "go",
609+
GoDevDLBootstrap: goDevDLBootstrap,
610+
Force: true,
615611
}
616612
}
617613

internal/buildgo/buildgo.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,53 @@ type GoBuilder struct {
9898
// GorootBootstrap is an optional absolute Unix-style path to the
9999
// bootstrap toolchain, overriding the default.
100100
GorootBootstrap string
101+
// GoDevDLBootstrap is whether the bootstrap comes from go.dev/dl/,
102+
// meaning its content is inside a directory named "go" as opposed
103+
// to the root of the archive. GorootBootstrap must be empty if so.
104+
GoDevDLBootstrap bool
101105
// Force controls whether to use the -force flag when building Go.
102106
// See go.dev/issue/56679.
103107
Force bool
104108
}
105109

106-
// RunMake builds the tool chain.
107-
// goroot is relative to the workdir with forward slashes.
110+
// RunMake builds the toolchain.
108111
// w is the Writer to send build output to.
109112
// remoteErr and err are as described at the top of this file.
110113
func (gb GoBuilder) RunMake(ctx context.Context, bc buildlet.Client, w io.Writer) (remoteErr, err error) {
111114
// Build the source code.
112115
makeSpan := gb.CreateSpan("make", gb.Conf.MakeScript())
113116
env := append(gb.Conf.Env(), "GOBIN=")
114117
if gb.GorootBootstrap != "" {
118+
if gb.GoDevDLBootstrap {
119+
return nil, fmt.Errorf("cannot set a non-empty GorootBootstrap together with GoDevDLBootstrap")
120+
}
115121
env = append(env, "GOROOT_BOOTSTRAP="+gb.GorootBootstrap)
116122
}
117123
makeArgs := gb.Conf.MakeScriptArgs()
118124
if gb.Force {
119125
makeArgs = append(makeArgs, "-force")
120126
}
127+
var makePath []string
128+
if gb.GoDevDLBootstrap {
129+
// When using go.dev/dl/ tarballs for bootstrap, their GOROOT ends up being
130+
// $WORKDIR/go1.4/go, which differs from the genbootstrap tarballs where it's
131+
// $WORKDIR/go1.4 (without the 'go' subdirectory) instead. So, it's necessary
132+
// to arrange for it to be found.
133+
//
134+
// GOROOT_BOOTSTRAP defaults to $WORKDIR/go1.4 via cmd/buildlet, and since
135+
// $WORKDIR expansion is supported in $PATH but not in other environment variables,
136+
// setting it to a correct value here would need an extra bc.WorkDir remote call.
137+
// So it is simpler to clear out GOROOT_BOOTSTRAP and let the bootstrap
138+
// toolchain be found by adding its go/bin directory to the front of $PATH.
139+
env = append(env, "GOROOT_BOOTSTRAP=")
140+
makePath = []string{"$WORKDIR/go1.4/go/bin", "$PATH"}
141+
}
121142
remoteErr, err = bc.Exec(ctx, path.Join(gb.Goroot, gb.Conf.MakeScript()), buildlet.ExecOpts{
122143
Output: w,
123144
ExtraEnv: env,
124145
Debug: true,
125146
Args: makeArgs,
147+
Path: makePath,
126148
})
127149
if err != nil {
128150
makeSpan.Done(err)

0 commit comments

Comments
 (0)