Add maxdepth parameter to get_labels function#3460
Add maxdepth parameter to get_labels function#3460chrisnovakovic merged 3 commits intothought-machine:masterfrom
maxdepth parameter to get_labels function#3460Conversation
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.
src/parse/asp/builtins.go
Outdated
| 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") |
There was a problem hiding this comment.
The message here needs to account for maxDepth being greater than 0 (or should this just be maxDepth == 0?)
There was a problem hiding this comment.
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").
|
Having said all that, I think there's merit in severing the dependency between |
Add a
maxdepthparameter to theget_labelsbuilt-in function that controls the maximum depth ofget_labels' recursive dependency search. The default is -1, meaning "no limit". The main use case is to help limit the collection ofcc: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
transitiveparameter:transitive=Trueis equivalent tomaxdepth=-1, andtransitive=Falseis equivalent tomaxdepth=0. Thetransitiveparameter remains for backwards compatibility, although it could now be removed in a future major release.