From 800ed40572bb38aa911e197216a140d1bec2861e Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 21 Dec 2020 18:18:34 -0500 Subject: [PATCH] go_local_sdk: more strict SDK platform detection (#2765) We determine the "SDK platform" by looking at the goos_goarch subdirectory of pkg/tool. If the goroot has actually built the toolchain for multiple platforms, then we just pick the first one and potentially fail cryptically later. Ideally, we would simply register toolchains for all of the host platforms we find, but that is likely a much larger change. Until then, provide a much clearer error message that we don't like finding multiple platforms. Fixes #2764 --- go/private/sdk.bzl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl index c148c9e2ff..24987ba126 100644 --- a/go/private/sdk.bzl +++ b/go/private/sdk.bzl @@ -252,13 +252,21 @@ def _detect_host_sdk(ctx): return root def _detect_sdk_platform(ctx, goroot): - res = ctx.execute(["ls", goroot + "/pkg/tool"]) + path = goroot + "/pkg/tool" + res = ctx.execute(["ls", path]) if res.return_code != 0: - fail("Could not detect SDK platform") + fail("Could not detect SDK platform: unable to list %s: %s" % (path, res.stderr)) + + platforms = [] for f in res.stdout.strip().split("\n"): if f.find("_") >= 0: - return f - fail("Could not detect SDK platform") + platforms.append(f) + + if len(platforms) == 0: + fail("Could not detect SDK platform: found no platforms in %s" % path) + if len(platforms) > 1: + fail("Could not detect SDK platform: found multiple platforms %s in %s" % (platforms, path)) + return platforms[0] def _parse_versions_json(data): """Parses version metadata returned by golang.org.