Skip to content

Allow ctx.expand_location to specify output_group #6001

Closed

Description

@Globegitter

Description of the problem / feature request:

When using ctx.expand_location() it would be great to be able to specify which output_group I want returned from the target.

Feature requests: what underlying problem are you trying to solve with this feature?

Sometime I want a specific (sub)set of the files returned from the target. Further right now just the implicit output of a target is taken, so it is not even possible to get some of the possible output from targets that may be requested by the rule.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

have a rule that returns:

return [
   DefaultInfo(
       files = some_files
   ),
   OutputGroupInfo(
        other_files = other_files,
    ),
]

Then another rule which has a target from this rule as dep, as well as an entry_point/main that specified a path to that dep (i.e. entry_point = "$(location :my_dep)") and then does:

ctx.expand_location(ctx.attr.entry_point)

This will get the implicit output specified by DefaultInfo even though I want to get the location of other_files

What operating system are you running Bazel on?

Ubuntu 16.04

What's the output of bazel info release?

release 0.17.0rc1

Activity

  1. added
    untriaged
    on Aug 27, 2018
  2. laurentlb commented on Aug 28, 2018

    @laurentlb
    Contributor

    Why do you use ctx.expand_location()?
    Does the format string come from a BUILD file?

  3. Globegitter commented on Aug 29, 2018

    @Globegitter
    Author

    Yes, to be more concrete I ran into that when working on this PR: bazel-contrib/rules_nodejs#217

    The already existing rollup_bundle rule expects entry_point to be passed in as a string.

  4. laurentlb commented on Aug 29, 2018

    @laurentlb
    Contributor

    For your example, can you use: entry_point = ":test"?
    Then mark entry_point as a label, which will allow the rule to access any of its output groups.

  5. Globegitter commented on Aug 29, 2018

    @Globegitter
    Author

    Yeah I was thinking that as well as an alternative option, maybe that would indeed be the best way forward.

  6. laurentlb commented on Aug 29, 2018

    @laurentlb
    Contributor

    I think that's cleaner. I'm going to close the request.
    The main use-case of expand_location was for reimplementing genrules (the users specifies the command in a BUILD file and wants to refer to other targets). In most other cases, I would suggest to avoid this function.

  7. removed
    untriaged
    on Sep 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions