Skip to content

Commit b01fc6f

Browse files
committed
add _get_env_var to simplify getting env variable
1 parent 3fb980c commit b01fc6f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

go/private/sdk.bzl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ def _sdk_build_file(ctx, platform):
237237
},
238238
)
239239

240+
def _get_env_var(ctx, name, default=""):
241+
if name in ctx.os.environ:
242+
return ctx.os.environ[name]
243+
else:
244+
return default
245+
240246
def _detect_host_platform(ctx):
241247
if ctx.os.name == "linux":
242248
goos, goarch = "linux", "amd64"
@@ -276,11 +282,9 @@ def _detect_host_platform(ctx):
276282
# Default to amd64 when uname doesn't return a known value.
277283

278284
elif ctx.os.name.startswith("windows"):
279-
if "PROCESSOR_ARCHITECTURE" in ctx.os.environ and \
280-
ctx.os.environ["PROCESSOR_ARCHITECTURE"] == "ARM64":
285+
if _get_env_var(ctx, "PROCESSOR_ARCHITECTURE") == "ARM64":
281286
goarch = "arm64"
282-
elif "PROCESSOR_ARCHITEW6432" in ctx.os.environ and \
283-
ctx.os.environ["PROCESSOR_ARCHITEW6432"] == "ARM64":
287+
elif _get_env_var(ctx, "PROCESSOR_ARCHITEW6432") == "ARM64":
284288
goarch = "arm64"
285289
else:
286290
goarch = "amd64"

0 commit comments

Comments
 (0)