Skip to content

refactor: use logger in repo_utils.execute_* functions #2082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2024

Conversation

rickeylev
Copy link
Collaborator

This is to unify how it handles printing log messages.

This also updates repo rules using repo_utils to create loggers and set the _rule_name attribute for the logger to use.

  • Also removes defunct repo_utils.debug_print
  • Also makes some functions private that aren't used elsewhere

This is to unify how it handles printing log messages.

This also updates repo rules using repo_utils to create loggers and
set the `_rule_name` attribute for the logger to use.

* Also removes defunct repo_utils.debug_print
* Also makes some functions private that aren't used elsewhere
@rickeylev rickeylev requested review from aignas and groodt as code owners July 21, 2024 02:41
@rickeylev
Copy link
Collaborator Author

Piping logger through helper functions is kind of annoying. It makes me want to wrap rctx entirely (so that we can do rctx.execute_checked(), without having to pass any of the logger args around). Or we do something like only allow loggers to be configured through attributes; that way, any helper that needs a logger can simply create one and be confident it's getting the right settings.

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I like the suggestion to wrap the context and have extra methods, like log.warn or execute_unchecked. I would say that we can add a note in our issue list and consider it as a followup to this PR as this PR already improves things.

We could also unify the API by having watch method for bazel 6, so our code would become more modern.

@@ -92,6 +82,7 @@ def _logger(ctx, name = None):
debug = lambda message_cb: _log(2, "DEBUG", message_cb),
info = lambda message_cb: _log(1, "INFO", message_cb),
warn = lambda message_cb: _log(0, "WARNING", message_cb),
fail = lambda message_cb: _log(-1, "FAIL", message_cb, fail),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only annoying thing about the fail method is that one has to do a return in the code afterwards to satisfy buildifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh? I didn't see that buildifier error pop up.

rctx.file("BUILD.bazel", """\
# Generated by python/private/toolchains_repo.bzl

exports_files(["python"], visibility = ["//visibility:public"])
""")

(os_name, arch) = get_host_os_arch(rctx)
host_platform = get_host_platform(os_name, arch)
(os_name, arch) = _get_host_os_arch(rctx, logger)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly this code was written before rctx and mctx had the architecture. I think we could look into removing the dependency on uname here.

And just use the repo utils equivalents.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, that would explain a bit. I always wondered why we were calling uname when rctx seemed to have the equivalent.

@aignas
Copy link
Collaborator

aignas commented Jul 22, 2024 via email

@rickeylev rickeylev enabled auto-merge July 22, 2024 04:32
@rickeylev rickeylev added this pull request to the merge queue Jul 22, 2024
Merged via the queue into bazel-contrib:main with commit 90baa6b Jul 22, 2024
4 checks passed
@rickeylev rickeylev deleted the refactor.execute.uses.logger branch July 22, 2024 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants