aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar laszlocsomor <laszlocsomor@google.com>2017-04-10 14:32:07 +0000
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-04-11 10:49:42 +0200
commit07fbeaea1d7759e3c03def5ccc031a70f4218ae6 (patch)
tree3aade8cfa1332870cfa759b433e0a859071b985f
parentc781f45de27afe3a90dcadb5075dc90df8105d80 (diff)
cc_configure: stricter error checks in _execute
Add stricter error checks in hopes of catching occasional CI flakiness where the stdout of a command seems to get lost. It's now an error if the command returns a non-zero exit code (or a zero one if it's expected to fail) or if its stdout is empty. Previously we only checked if stderr was empty to consider the action successful. See https://github.com/bazelbuild/bazel/issues/2675 RELNOTES: none PiperOrigin-RevId: 152685220
-rw-r--r--tools/cpp/cc_configure.bzl23
1 files changed, 17 insertions, 6 deletions
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index 73653e9d10..fd7edd0b54 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -87,16 +87,27 @@ def _which_cmd(repository_ctx, cmd, default = None):
return str(result)
-def _execute(repository_ctx, command, environment = None):
+def _execute(repository_ctx, command, environment = None,
+ expect_failure = False):
"""Execute a command, return stdout if succeed and throw an error if it fails."""
if environment:
result = repository_ctx.execute(command, environment = environment)
else:
result = repository_ctx.execute(command)
- if result.stderr:
- auto_configure_fail(result.stderr)
- else:
- return result.stdout.strip()
+ if expect_failure != (result.return_code != 0):
+ if expect_failure:
+ auto_configure_fail(
+ "expected failure, command %s, stderr: (%s)" % (
+ command, result.stderr))
+ else:
+ auto_configure_fail(
+ "non-zero exit code: %d, command %s, stderr: (%s)" % (
+ result.return_code, command, result.stderr))
+ stripped_stdout = result.stdout.strip()
+ if not stripped_stdout:
+ auto_configure_fail(
+ "empty output from command %s, stderr: (%s)" % (command, result.stderr))
+ return stripped_stdout
def _get_tool_paths(repository_ctx, darwin, cc):
@@ -578,7 +589,7 @@ def _is_support_whole_archive(repository_ctx, vc_path):
if "NO_WHOLE_ARCHIVE_OPTION" in env and env["NO_WHOLE_ARCHIVE_OPTION"] == "1":
return False
linker = _find_msvc_tool(repository_ctx, vc_path, "link.exe")
- result = _execute(repository_ctx, [linker])
+ result = _execute(repository_ctx, [linker], expect_failure = True)
return result.find("/WHOLEARCHIVE") != -1