Skip to content
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

refactor(internal): move the os/arch detection to repo_utils #2075

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

aignas
Copy link
Collaborator

@aignas aignas commented Jul 18, 2024

This also changes the local_runtime_repo to explicitly check for
supported platforms instead of relying on a None value returned by the
helper method. This makes the behaviour exactly the same to the
behaviour before this PR and we can potentially drop the need for the
validation in the future if our local_runtime detection is more robust.

This also makes the platform detectino in pypi_repo_utils not depend
on uname and only use the repository_ctx. Apparently the
module_ctx.watch throws an error if one attempts to watch files on the
system (this is left for repository_rule it seems and one can only do
module_ctx.watch on files within the current workspace. This was
surprising, but could have been worked around by just unifying code.

This splits out things from #2059 and makes the code more succinct.

Work towards #260, #1105, #1868.

This also changes the local_runtime_repo to explicitly check for
supported platforms instead of relying on a `None` value returned by the
helper method. This makes the behaviour exactly the same to the
behaviour before this PR and we can potentially drop the need for the
validation in the future if our local_runtime detection is more robust.

This also makes the platform detectino in `pypi_repo_utils` not depend
on `uname` and only use the `repository_ctx`. Apparently the
`module_ctx.watch` throws an error if one attempts to watch files on the
system (this is left for `repository_rule` it seems and one can only do
`module_ctx.watch` on files within the current workspace. This was
surprising, but could have been worked around by just unifying code.

This splits out things from bazelbuild#2059 and makes the code more succinct.

Work towards bazelbuild#260, bazelbuild#1105, bazelbuild#1868.
@@ -46,7 +46,7 @@ def _local_runtime_repo_impl(rctx):
on_failure = rctx.attr.on_failure

platforms_os_name = repo_utils.get_platforms_os_name(rctx)
if not platforms_os_name:
if platforms_os_name not in ["linux", "osx", "windows"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just remove this block; as mentioned in the originating PR, I just had it return None because I knew there were cases it didn't handle, but didn't know what they were. Now that it handles all the cases, we can just assume whatever value is returned is correct.

return "windows"
return os

def _get_platforms_arch_name(rctx):
Copy link
Contributor

Choose a reason for hiding this comment

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

How about _get_platforms_cpu_name instead? Since it's mapping the value to the @platforms//cpu:<name>, where the term is "cpu", not "arch".

@aignas aignas enabled auto-merge July 19, 2024 01:03
@aignas aignas added this pull request to the merge queue Jul 19, 2024
Merged via the queue into bazelbuild:main with commit 6e9a65f Jul 19, 2024
4 checks passed
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