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

feat: platform_transition_filegroup #55

Merged
merged 2 commits into from
Mar 31, 2022
Merged

feat: platform_transition_filegroup #55

merged 2 commits into from
Mar 31, 2022

Conversation

@@ -96,7 +90,37 @@ bzl_library(

bzl_library(
name = "diff_test",
srcs = ["diff_test.bzl"],
srcs = ["diff_test.bzl"], # keep
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's this comment for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

without it, running Gazelle in this repo removes the file.

Gazelle seems to have some (new?) heuristics for avoiding "test code" being included, so files ending with "_test.bzl" are a problem. I had to totally revert the changes Gazelle makes to the lib/private/BUILD.bazel file where it removes a bunch...

Copy link
Collaborator

@kormide kormide left a comment

Choose a reason for hiding this comment

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

LGTM structurally, but not familiar with transitions so maybe @gregmagolan should also review.

@gregmagolan
Copy link
Collaborator

I'll try this at rh for my use case today

@gregmagolan
Copy link
Collaborator

Hmm. rules_docker transition outputs multiple platforms: https://github.com/bazelbuild/rules_docker/blob/master/container/image.bzl#L787

_image_transition = transition(
    implementation = _image_transition_impl,
    inputs = [],
    outputs = [
        "//command_line_option:platforms",
        "@io_bazel_rules_docker//platforms:image_transition_cpu",
        "@io_bazel_rules_docker//platforms:image_transition_os",
    ],
)

@gregmagolan
Copy link
Collaborator

Should this support multiple platforms with target_platforms?

@alexeagle
Copy link
Collaborator Author

I guess it could support a list of target_platforms - wouldn't that mean you transition to a constraint that requires all of those platforms? I'm not seeing how that would be useful, since platforms are disjoint/mutually exclusive?

@gregmagolan
Copy link
Collaborator

I guess it could support a list of target_platforms - wouldn't that mean you transition to a constraint that requires all of those platforms? I'm not seeing how that would be useful, since platforms are disjoint/mutually exclusive?

I'm sure either. Wonder why the rules_docker transition returns multiple

@gregmagolan
Copy link
Collaborator

Sorted it out for the rules_docker transition use case. This won't be useful there as the transition of just the target_platform is insufficient so I'll need to land a similar rule in rules_docker that uses the transitions there which transitions the target_platform and a few other settings:

"Rules for working with transitions."

load("@io_bazel_rules_docker//container:image_transition.bzl", _image_transition = "image_transition")

def _docker_transition_filegroup_impl(ctx):
    files = []
    runfiles = ctx.runfiles()
    for src in ctx.attr.srcs:
        files.append(src[DefaultInfo].files)

    runfiles = runfiles.merge_all([src[DefaultInfo].default_runfiles for src in ctx.attr.srcs])
    return [DefaultInfo(
        files = depset(transitive = files),
        runfiles = runfiles,
    )]

docker_transition_filegroup = rule(
    _docker_transition_filegroup_impl,
    attrs = {
        # Required to Opt-in to the transitions feature.
        "_allowlist_function_transition": attr.label(
            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
        ),
        "architecture": attr.string(
            doc = "The desired rules_docker CPU architecture to transition to.",
            default = "amd64",
        ),
        "operating_system": attr.string(
            doc = "The desired rules_docker OS to transition to.",
            default = "linux",
        ),
        "srcs": attr.label_list(
            allow_empty = False,
            cfg = _image_transition,
            doc = "The input to be transitioned to the rules_docker platform.",
        ),
    },
    doc = "Transitions the srcs to the rules_docker platform.",
)

@gregmagolan gregmagolan merged commit 096133e into main Mar 31, 2022
@cgrindel cgrindel deleted the transition branch October 7, 2022 22:56
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.

3 participants