Skip to content

Commit

Permalink
cc_configure: stricter error checks in _execute
Browse files Browse the repository at this point in the history
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 #2675

RELNOTES: none
PiperOrigin-RevId: 152685220
  • Loading branch information
laszlocsomor authored and buchgr committed Apr 11, 2017
1 parent c781f45 commit 07fbeae
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tools/cpp/cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 07fbeae

Please sign in to comment.