Workaround an RBE bug where stderr is merged with stdout.
Any code path using exec_result.stderr won't work with RBE due to a bug where the service returns stderr as stdout. PiperOrigin-RevId: 295107492 Change-Id: I5738d46f7bb4cc049636a6f6625abc782d2d1e29
This commit is contained in:
parent
2084931948
commit
fe03adf6e6
18
third_party/gpus/cuda_configure.bzl
vendored
18
third_party/gpus/cuda_configure.bzl
vendored
@ -39,6 +39,7 @@ load(
|
|||||||
)
|
)
|
||||||
load(
|
load(
|
||||||
"//third_party/remote_config:common.bzl",
|
"//third_party/remote_config:common.bzl",
|
||||||
|
"err_out",
|
||||||
"get_bash_bin",
|
"get_bash_bin",
|
||||||
"get_cpu_value",
|
"get_cpu_value",
|
||||||
"get_python_bin",
|
"get_python_bin",
|
||||||
@ -273,20 +274,21 @@ def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp, tf_sysroot):
|
|||||||
sysroot += ["--sysroot", tf_sysroot]
|
sysroot += ["--sysroot", tf_sysroot]
|
||||||
result = raw_exec(repository_ctx, [cc, "-E", "-x" + lang, "-", "-v"] +
|
result = raw_exec(repository_ctx, [cc, "-E", "-x" + lang, "-", "-v"] +
|
||||||
sysroot)
|
sysroot)
|
||||||
index1 = result.stderr.find(_INC_DIR_MARKER_BEGIN)
|
stderr = err_out(result)
|
||||||
|
index1 = stderr.find(_INC_DIR_MARKER_BEGIN)
|
||||||
if index1 == -1:
|
if index1 == -1:
|
||||||
return []
|
return []
|
||||||
index1 = result.stderr.find("\n", index1)
|
index1 = stderr.find("\n", index1)
|
||||||
if index1 == -1:
|
if index1 == -1:
|
||||||
return []
|
return []
|
||||||
index2 = result.stderr.rfind("\n ")
|
index2 = stderr.rfind("\n ")
|
||||||
if index2 == -1 or index2 < index1:
|
if index2 == -1 or index2 < index1:
|
||||||
return []
|
return []
|
||||||
index2 = result.stderr.find("\n", index2 + 1)
|
index2 = stderr.find("\n", index2 + 1)
|
||||||
if index2 == -1:
|
if index2 == -1:
|
||||||
inc_dirs = result.stderr[index1 + 1:]
|
inc_dirs = stderr[index1 + 1:]
|
||||||
else:
|
else:
|
||||||
inc_dirs = result.stderr[index1 + 1:index2].strip()
|
inc_dirs = stderr[index1 + 1:index2].strip()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
_normalize_include_path(repository_ctx, _cxx_inc_convert(p))
|
_normalize_include_path(repository_ctx, _cxx_inc_convert(p))
|
||||||
@ -346,7 +348,7 @@ def _cuda_include_path(repository_ctx, cuda_config):
|
|||||||
cmd = "%s -v /dev/null -o /dev/null ; [ $? -eq 1 ]" % str(nvcc_path)
|
cmd = "%s -v /dev/null -o /dev/null ; [ $? -eq 1 ]" % str(nvcc_path)
|
||||||
result = raw_exec(repository_ctx, [get_bash_bin(repository_ctx), "-c", cmd])
|
result = raw_exec(repository_ctx, [get_bash_bin(repository_ctx), "-c", cmd])
|
||||||
target_dir = ""
|
target_dir = ""
|
||||||
for one_line in result.stderr.splitlines():
|
for one_line in err_out(result).splitlines():
|
||||||
if one_line.startswith("#$ _TARGET_DIR_="):
|
if one_line.startswith("#$ _TARGET_DIR_="):
|
||||||
target_dir = (
|
target_dir = (
|
||||||
cuda_config.cuda_toolkit_path + "/" + one_line.replace(
|
cuda_config.cuda_toolkit_path + "/" + one_line.replace(
|
||||||
@ -600,7 +602,7 @@ def find_cuda_config(repository_ctx, script_path, cuda_libraries):
|
|||||||
script_path,
|
script_path,
|
||||||
] + cuda_libraries)
|
] + cuda_libraries)
|
||||||
if exec_result.return_code:
|
if exec_result.return_code:
|
||||||
auto_configure_fail("Failed to run find_cuda_config.py: %s" % exec_result.stderr)
|
auto_configure_fail("Failed to run find_cuda_config.py: %s" % err_out(exec_result))
|
||||||
|
|
||||||
# Parse the dict from stdout.
|
# Parse the dict from stdout.
|
||||||
return dict([tuple(x.split(": ")) for x in exec_result.stdout.splitlines()])
|
return dict([tuple(x.split(": ")) for x in exec_result.stdout.splitlines()])
|
||||||
|
14
third_party/gpus/rocm_configure.bzl
vendored
14
third_party/gpus/rocm_configure.bzl
vendored
@ -21,6 +21,7 @@ load(
|
|||||||
)
|
)
|
||||||
load(
|
load(
|
||||||
"//third_party/remote_config:common.bzl",
|
"//third_party/remote_config:common.bzl",
|
||||||
|
"err_out",
|
||||||
"execute",
|
"execute",
|
||||||
"files_exist",
|
"files_exist",
|
||||||
"get_bash_bin",
|
"get_bash_bin",
|
||||||
@ -116,20 +117,21 @@ def _get_cxx_inc_directories_impl(repository_ctx, cc, lang_is_cpp):
|
|||||||
"-",
|
"-",
|
||||||
"-v",
|
"-v",
|
||||||
])
|
])
|
||||||
index1 = result.stderr.find(_INC_DIR_MARKER_BEGIN)
|
stderr = err_out(result)
|
||||||
|
index1 = stderr.find(_INC_DIR_MARKER_BEGIN)
|
||||||
if index1 == -1:
|
if index1 == -1:
|
||||||
return []
|
return []
|
||||||
index1 = result.stderr.find("\n", index1)
|
index1 = stderr.find("\n", index1)
|
||||||
if index1 == -1:
|
if index1 == -1:
|
||||||
return []
|
return []
|
||||||
index2 = result.stderr.rfind("\n ")
|
index2 = stderr.rfind("\n ")
|
||||||
if index2 == -1 or index2 < index1:
|
if index2 == -1 or index2 < index1:
|
||||||
return []
|
return []
|
||||||
index2 = result.stderr.find("\n", index2 + 1)
|
index2 = stderr.find("\n", index2 + 1)
|
||||||
if index2 == -1:
|
if index2 == -1:
|
||||||
inc_dirs = result.stderr[index1 + 1:]
|
inc_dirs = stderr[index1 + 1:]
|
||||||
else:
|
else:
|
||||||
inc_dirs = result.stderr[index1 + 1:index2].strip()
|
inc_dirs = stderr[index1 + 1:index2].strip()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
str(repository_ctx.path(_cxx_inc_convert(p)))
|
str(repository_ctx.path(_cxx_inc_convert(p)))
|
||||||
|
16
third_party/remote_config/common.bzl
vendored
16
third_party/remote_config/common.bzl
vendored
@ -260,3 +260,19 @@ def realpath(repository_ctx, path, bash_bin = None):
|
|||||||
bash_bin = get_bash_bin(repository_ctx)
|
bash_bin = get_bash_bin(repository_ctx)
|
||||||
|
|
||||||
return execute(repository_ctx, [bash_bin, "-c", "realpath %s" % path]).stdout.strip()
|
return execute(repository_ctx, [bash_bin, "-c", "realpath %s" % path]).stdout.strip()
|
||||||
|
|
||||||
|
def err_out(result):
|
||||||
|
"""Returns stderr if set, else stdout.
|
||||||
|
|
||||||
|
This function is a workaround for a bug in RBE where stderr is returned as stdout. Instead
|
||||||
|
of using result.stderr use err_out(result) instead.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
result: the exec_result.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The stderr if set, else stdout
|
||||||
|
"""
|
||||||
|
if len(result.stderr) == 0:
|
||||||
|
return result.stdout
|
||||||
|
return result.stderr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user