Skip to content

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

Merged
aignas merged 3 commits intobazel-contrib:mainfrom
aignas:refactor/get-platforms-names
Jul 19, 2024
Merged

refactor(internal): move the os/arch detection to repo_utils#2075
aignas merged 3 commits intobazel-contrib:mainfrom
aignas:refactor/get-platforms-names

Conversation

@aignas
Copy link
Copy Markdown
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 bazel-contrib#2059 and makes the code more succinct.

Work towards bazel-contrib#260, bazel-contrib#1105, bazel-contrib#1868.
@aignas aignas requested review from groodt and rickeylev as code owners July 18, 2024 15:46

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
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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 bazel-contrib:main with commit 6e9a65f Jul 19, 2024
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