Skip to content

Commit

Permalink
go_local_sdk: more strict SDK platform detection (#2765)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
prattmic authored and Jay Conrod committed Dec 23, 2020
1 parent e883622 commit 800ed40
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions go/private/sdk.bzl
Expand Up @@ -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.
Expand Down

0 comments on commit 800ed40

Please sign in to comment.