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

Ability to query for runtime dependencies #21830

Open
swarren12 opened this issue Mar 27, 2024 · 4 comments
Open

Ability to query for runtime dependencies #21830

swarren12 opened this issue Mar 27, 2024 · 4 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Core Skyframe, bazel query, BEP, options parsing, bazelrc team-Rules-Java Issues for Java rules type: feature request

Comments

@swarren12
Copy link

Description of the feature request:

I believe it would be useful to query for the "runtime" dependencies of a given target. By "runtime" here, I don't necessarily just mean the content of the runtime_deps attribute that exists on some targets, but the set of both deps and runtime_deps excluding anything marked as neverlink=True.

If this feature already exists, I can't see anything obvious in the documentation about it.

As an example:

java_library(name = "a", ...)
java_library(name = "b", deps=[":a"], ..., neverlink=True)
java_library(name = "c", ...)
java_library(name = "d", ...)
java_library(name = "e", deps = [":b", ":c"], runtime_deps=[":d"], ...)

Given the following targets, I'd expect to be able to query for something similar to the following:

$ bazel query 'deps(//:e)' --noimplicit_deps
//:a
//:b
//:c
//:d
//:e

$ bazel query 'runtime_deps("//:e")' --noimplicit_deps
//:c
//:d
//:e

I've represented it here as a query function, but I'm not sure if a command line argument would be more appropriate?

Which category does this issue belong to?

Core

What underlying problem are you trying to solve with this feature?

To be able to query for the dependencies of a target that will be required at runtime.

Which operating system are you running Bazel on?

Ubuntu 23.10

What is the output of bazel info release?

release 6.4.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

I couldn't find anything obvious

Any other information, logs, or outputs that you want to share?

No response

@github-actions github-actions bot added the team-Core Skyframe, bazel query, BEP, options parsing, bazelrc label Mar 27, 2024
@iancha1992 iancha1992 added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. and removed team-Core Skyframe, bazel query, BEP, options parsing, bazelrc labels Mar 27, 2024
@meteorcloudy meteorcloudy added team-Rules-Java Issues for Java rules team-Core Skyframe, bazel query, BEP, options parsing, bazelrc and removed team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Apr 16, 2024
@hvadehra
Copy link
Member

bazel query operates on the target graph. The notion of a runtime (or compile-time) dependency is a language-specific (in this case java), and can only be determined during analysis. Since we're looking to make bazel increasingly more language-agnostic, I'd say this FR is infeasible.

I think the way to achieve this would be to write an aspect and collect the targets appropriately.

@hvadehra hvadehra added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged labels Apr 29, 2024
@swarren12
Copy link
Author

swarren12 commented Apr 29, 2024

The notion of a runtime (or compile-time) dependency is a language-specific (in this case java), and can only be determined during analysis.

Maybe I misunderstood, but I thought that neverlink was common to all rules? I'm specifically interested in excluding neverlink=True, which I feel should be possible from query (or, at least, cquery)?

However, I didn't realise that this might be possible via an aspect. I'll have a look into this option and see if it works!

@hvadehra
Copy link
Member

I thought that neverlink was common to all rules

Consider genrule or sh_test which don't have such an attribute. Or a (hypothetical) ruleset that may have the attribute, but also supports a --force_ignore_neverlink flag which overrides the default behavior.

@swarren12
Copy link
Author

Okay, I think I see why this is problematic.

I'll see if I can get something going with an aspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Core Skyframe, bazel query, BEP, options parsing, bazelrc team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants
@hvadehra @meteorcloudy @swarren12 @iancha1992 @satyanandak and others