bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.21k stars 4.07k forks source link

Please allow FilesToRunProvider to be constructed by Starlark #7187

Closed jmillikin-stripe closed 2 weeks ago

jmillikin-stripe commented 5 years ago

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

Now that FilesToRunProvider can be passed directly to ctx.actions.run() as an executable, I want to replace some of my (executable, runfiles) structs with the native provider. It looks like values of this type can only be read by Starlark, not constructed.

I'd like to be able to do something like this:

# @rules_something//:my_toolchain returns a MyToolchainInfo
def _my_toolchain(ctx):
  return MyToolchainInfo(
    tool = FilesToRunProvider(
      executable = ctx.executable._tool,
      runfiles = ctx.runfiles(files = ctx.files._templates),
    ),
  )

# downstream_rule depends on @rules_something//:my_toolchain
def _downstream_rule(ctx):
  my_toolchain = ctx.attr._my_toolchain[MyToolchainInfo]
  ctx.actions.run(executable = my_toolchain.tool, ...)
irengrig commented 5 years ago

/cc @laszlocsomor

laszlocsomor commented 5 years ago

@irengrig : I'm confused, why should I know about this issue?

irengrig commented 5 years ago

Is that related to ctx.resolve_tools() ?

laszlocsomor commented 5 years ago

I see, thanks! Yes, it is related, but I don't think it's relevant: ctx.resolve_tools() (see design and PR) is about resolving the input files and input manifests of tools, while this PR is about creating a certain Provider.

irengrig commented 5 years ago

This provider is also about invoking the tool and pass the information about runfiles. I am not sure how exactly it is different from this case, but it solves the same problem.

laszlocsomor commented 5 years ago

Ah, you're right, in that light they are related.

github-actions[bot] commented 2 weeks ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

tjgq commented 2 weeks ago

Let's dedup against https://github.com/bazelbuild/bazel/issues/15486 given the recent discussion happening there.