in targets/linux/deb/distro/pkg.go [90:135]
func searchForAltGolang(ctx context.Context, client gwclient.Client, spec *dalec.Spec, targetKey string, in llb.State, opts ...llb.ConstraintsOpt) (string, error) {
if !spec.HasGomods() {
return "", nil
}
var candidates []string
deps := spec.GetBuildDeps(targetKey)
if _, hasNormalGo := deps["golang"]; hasNormalGo {
return "", nil
}
for dep := range deps {
if strings.HasPrefix(dep, "golang-") {
// Get the base version component
_, ver, _ := strings.Cut(dep, "-")
// Trim off any potential extra stuff like `golang-1.20-go` (ie the `-go` bit)
// This is just for having definitive search paths to check it should
// not be an issue if this is not like the above example and its
// something else like `-doc` since we are still going to check the
// binary exists anyway (plus this would be highly unlikely in any case).
ver, _, _ = strings.Cut(ver, "-")
candidates = append(candidates, "usr/lib/go-"+ver+"/bin")
}
}
if len(candidates) == 0 {
return "", nil
}
stfs, err := bkfs.FromState(ctx, &in, client, opts...)
if err != nil {
return "", err
}
for _, p := range candidates {
_, err := fs.Stat(stfs, filepath.Join(p, "go"))
if err == nil {
// bkfs does not allow a leading `/` in the stat path per spec for [fs.FS]
// Add that in here
p := "/" + p
return p, nil
}
}
return "", nil
}