Skip to content

Conversation

@chrisnovakovic
Copy link
Contributor

@chrisnovakovic chrisnovakovic commented Nov 27, 2025

Add a maxdepth parameter to the get_labels built-in function that controls the maximum depth of get_labels' recursive dependency search. The default is -1, meaning "no limit". The main use case is to help limit the collection of cc:inc: labels to direct dependencies in the cc-rules plugin, since headers used by transitive (library) dependencies shouldn't be required at compilation time.

This is an alternative to (and is in fact a superset of the functionality offered by) the transitive parameter: transitive=True is equivalent to maxdepth=-1, and transitive=False is equivalent to maxdepth=0. The transitive parameter remains for backwards compatibility, although it could now be removed in a future major release.

This is used in conjunction with the `transitive` parameter; when
`transitive` is true, `maxdepth` can be used to control the maximum
depth of the recursion. The default is -1, meaning "no limit". The main
use case is to help limit the collection of `cc:inc:` labels to direct
dependencies in the cc-rules plugin, since headers used by (library)
dependencies shouldn't be required at compilation time.

`transitive=True, maxdepth=0` is equivalent to `transitive=False`, so
actually there's no need for `transitive` to exist as a parameter at all
any more, although it remains for backwards compatibility. It could be
removed in a future major release.
if all && !transitive {
log.Fatalf("get_labels can't be called with all set to true when transitive is set to False")
if all && maxDepth != -1 {
log.Fatalf("get_labels can't be called with all set to True when transitive is set to False")
Copy link
Contributor

Choose a reason for hiding this comment

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

The message here needs to account for maxDepth being greater than 0 (or should this just be maxDepth == 0?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a kludge to work around the fact that transitive still exists as a parameter in the built-in function. In getLabelsInternal's function signature, transitive has been replaced with maxDepth; all && maxDepth != -1 is therefore equivalent to the former all && !transitive (because maxDepth < -1 is forbidden by getLabels, and maxDepth > -1 means "not really transitive: stop recursing this many levels deep").

@chrisnovakovic
Copy link
Contributor Author

Having said all that, I think there's merit in severing the dependency between transitive and maxdepth (because requiring transitive=True as a prerequisite for using maxdepth feels like an abuse of the definition of "transitive"). It'd be better for them to be mutually exclusive parameters and for transitive=<True|False> to be aliases for maxdepth=<-1|0> respectively.

@chrisnovakovic chrisnovakovic marked this pull request as draft November 27, 2025 15:49
@chrisnovakovic chrisnovakovic marked this pull request as ready for review November 27, 2025 16:27
@chrisnovakovic chrisnovakovic merged commit 5004307 into thought-machine:master Nov 27, 2025
13 checks passed
@chrisnovakovic chrisnovakovic deleted the get_labels-maxdepth branch November 27, 2025 16:50
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