Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e53b0b7

Browse filesBrowse files
authored
feat: add debug logging of repo sub processes (bazel-contrib#1735)
Debugging what the repo rules are up to can be difficult because Bazel doesn't provide many facilities to inspect what they're up to. This adds an environment variable, `RULES_PYTHON_REPO_DEBUG`, that, when set, will make our repo rules print out detailed information about the subprocesses they are running. This also makes failed commands dump much more comprehensive information. This was driven by the recent report of failures on Windows during a repo rule.
1 parent 8fa6212 commit e53b0b7
Copy full SHA for e53b0b7

File tree

Expand file treeCollapse file tree

8 files changed

+323
-90
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+323
-90
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ A brief description of the categories of changes:
6161
rely on toolchain configuration and how the latest version takes precedence
6262
if e.g. `3.8` is selected. That also simplifies `.bazelrc` for any users
6363
that set the default `python_version` string flag in that way.
64+
65+
* (repo rules) The environment variable `RULES_PYTHON_REPO_DEBUG=1` can be
66+
set to make repository rules log detailed information about what they're
67+
up to.
68+
6469
## 0.29.0 - 2024-01-22
6570

6671
[0.29.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.29.0

‎python/BUILD.bazel

Copy file name to clipboardExpand all lines: python/BUILD.bazel
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ bzl_library(
203203
"//python/private:coverage_deps_bzl",
204204
"//python/private:full_version_bzl",
205205
"//python/private:internal_config_repo_bzl",
206+
"//python/private:repo_utils_bzl",
206207
"//python/private:toolchains_repo_bzl",
207-
"//python/private:which_bzl",
208208
],
209209
)
210210

‎python/pip_install/BUILD.bazel

Copy file name to clipboardExpand all lines: python/pip_install/BUILD.bazel
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ bzl_library(
3535
"//python/private:parse_whl_name_bzl",
3636
"//python/private:patch_whl_bzl",
3737
"//python/private:render_pkg_aliases_bzl",
38+
"//python/private:repo_utils_bzl",
3839
"//python/private:toolchains_repo_bzl",
39-
"//python/private:which_bzl",
4040
"//python/private:whl_target_platforms_bzl",
4141
"@bazel_skylib//lib:sets",
4242
],

‎python/pip_install/pip_repository.bzl

Copy file name to clipboardExpand all lines: python/pip_install/pip_repository.bzl
+26-34Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ load("//python/private:normalize_name.bzl", "normalize_name")
2727
load("//python/private:parse_whl_name.bzl", "parse_whl_name")
2828
load("//python/private:patch_whl.bzl", "patch_whl")
2929
load("//python/private:render_pkg_aliases.bzl", "render_pkg_aliases")
30+
load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
3031
load("//python/private:toolchains_repo.bzl", "get_host_os_arch")
31-
load("//python/private:which.bzl", "which_with_fail")
3232
load("//python/private:whl_target_platforms.bzl", "whl_target_platforms")
3333

3434
CPPFLAGS = "CPPFLAGS"
@@ -115,7 +115,11 @@ def _get_xcode_location_cflags(rctx):
115115
if not rctx.os.name.lower().startswith("mac os"):
116116
return []
117117

118-
xcode_sdk_location = rctx.execute([which_with_fail("xcode-select", rctx), "--print-path"])
118+
xcode_sdk_location = repo_utils.execute_unchecked(
119+
rctx,
120+
op = "GetXcodeLocation",
121+
arguments = [repo_utils.which_checked(rctx, "xcode-select"), "--print-path"],
122+
)
119123
if xcode_sdk_location.return_code != 0:
120124
return []
121125

@@ -144,14 +148,16 @@ def _get_toolchain_unix_cflags(rctx, python_interpreter):
144148
if not is_standalone_interpreter(rctx, python_interpreter):
145149
return []
146150

147-
er = rctx.execute([
148-
python_interpreter,
149-
"-c",
150-
"import sys; print(f'{sys.version_info[0]}.{sys.version_info[1]}', end='')",
151-
])
152-
if er.return_code != 0:
153-
fail("could not get python version from interpreter (status {}): {}".format(er.return_code, er.stderr))
154-
_python_version = er.stdout
151+
stdout = repo_utils.execute_checked_stdout(
152+
rctx,
153+
op = "GetPythonVersionForUnixCflags",
154+
arguments = [
155+
python_interpreter,
156+
"-c",
157+
"import sys; print(f'{sys.version_info[0]}.{sys.version_info[1]}', end='')",
158+
],
159+
)
160+
_python_version = stdout
155161
include_path = "{}/include/python{}".format(
156162
python_interpreter.dirname,
157163
_python_version,
@@ -406,6 +412,7 @@ def _pip_repository_impl(rctx):
406412

407413
common_env = [
408414
"RULES_PYTHON_PIP_ISOLATED",
415+
REPO_DEBUG_ENV_VAR,
409416
]
410417

411418
common_attrs = {
@@ -526,7 +533,7 @@ is one of `linux`, `osx`, `windows` and arch is one of `x86_64`, `x86_32`,
526533
527534
You can also target a specific Python version by using `cp3<minor_version>_<os>_<arch>`.
528535
If multiple python versions are specified as target platforms, then select statements
529-
of the `lib` and `whl` targets will include usage of version aware toolchain config
536+
of the `lib` and `whl` targets will include usage of version aware toolchain config
530537
settings like `@rules_python//python/config_settings:is_python_3.y`.
531538
532539
Special values: `host` (for generating deps for the host platform only) and
@@ -753,28 +760,14 @@ def _whl_library_impl(rctx):
753760
# Manually construct the PYTHONPATH since we cannot use the toolchain here
754761
environment = _create_repository_execution_environment(rctx, python_interpreter)
755762

756-
result = rctx.execute(
757-
args,
763+
repo_utils.execute_checked(
764+
rctx,
765+
op = "whl_library.ResolveRequirement({}, {})".format(rctx.attr.name, rctx.attr.requirement),
766+
arguments = args,
758767
environment = environment,
759768
quiet = rctx.attr.quiet,
760769
timeout = rctx.attr.timeout,
761770
)
762-
if result.return_code:
763-
fail((
764-
"whl_library '{name}' wheel_installer failed:\n" +
765-
" command: {cmd}\n" +
766-
" environment:\n{env}\n" +
767-
" return code: {return_code}\n" +
768-
"===== stdout start ====\n{stdout}\n===== stdout end===\n" +
769-
"===== stderr start ====\n{stderr}\n===== stderr end===\n"
770-
).format(
771-
name = rctx.attr.name,
772-
cmd = " ".join([str(a) for a in args]),
773-
env = "\n".join(["{}={}".format(k, v) for k, v in environment.items()]),
774-
return_code = result.return_code,
775-
stdout = result.stdout,
776-
stderr = result.stderr,
777-
))
778771

779772
whl_path = rctx.path(json.decode(rctx.read("whl_file.json"))["whl_file"])
780773
if not rctx.delete("whl_file.json"):
@@ -807,8 +800,10 @@ def _whl_library_impl(rctx):
807800
for p in whl_target_platforms(parsed_whl.platform_tag)
808801
]
809802

810-
result = rctx.execute(
811-
args + [
803+
repo_utils.execute_checked(
804+
rctx,
805+
op = "whl_library.ExtractWheel({}, {})".format(rctx.attr.name, whl_path),
806+
arguments = args + [
812807
"--whl-file",
813808
whl_path,
814809
] + ["--platform={}".format(p) for p in target_platforms],
@@ -817,9 +812,6 @@ def _whl_library_impl(rctx):
817812
timeout = rctx.attr.timeout,
818813
)
819814

820-
if result.return_code:
821-
fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))
822-
823815
metadata = json.decode(rctx.read("metadata.json"))
824816
rctx.delete("metadata.json")
825817

‎python/private/BUILD.bazel

Copy file name to clipboardExpand all lines: python/private/BUILD.bazel
+6-10Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ bzl_library(
208208
],
209209
)
210210

211+
bzl_library(
212+
name = "repo_utils_bzl",
213+
srcs = ["repo_utils.bzl"],
214+
)
215+
211216
bzl_library(
212217
name = "stamp_bzl",
213218
srcs = ["stamp.bzl"],
@@ -223,7 +228,7 @@ bzl_library(
223228
name = "toolchains_repo_bzl",
224229
srcs = ["toolchains_repo.bzl"],
225230
deps = [
226-
":which_bzl",
231+
":repo_utils_bzl",
227232
"//python:versions_bzl",
228233
],
229234
)
@@ -242,15 +247,6 @@ bzl_library(
242247
srcs = ["version_label.bzl"],
243248
)
244249

245-
bzl_library(
246-
name = "which_bzl",
247-
srcs = ["which.bzl"],
248-
visibility = [
249-
"//docs:__subpackages__",
250-
"//python:__subpackages__",
251-
],
252-
)
253-
254250
bzl_library(
255251
name = "whl_target_platforms_bzl",
256252
srcs = ["whl_target_platforms.bzl"],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.