bazelbuild / bazel

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

missing conceptual piece: metapackage / collection of multiple packages #14691

Closed grimreaper closed 2 years ago

grimreaper commented 2 years ago

Description of the problem / feature request:

Bazel lacks definition of a "metapackage"

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

This is a bit of a meta ticket since it describes multiple problems and points out how they all stem from the same missing conceptual piece. A resolution to this ticket would be then both a solution for the conceptual piece and new tickets for each of the features.

A typical monorepo will have multiple services, libraries, scripts, or whatnot. For lack of a better term I will call these metapackage. A metapackage can thought of as a collection targets grouped under one directory. Users may wish to enforce rules at the component level.

Such rules include "services may not depend on one another", "libraries may not depend on services", "library A may not depend on library B", "all targets in service A must have fatal warnings enabled", "only a fixed set of targets can depend on deprecated library". In addition users may want to be able to query this conceptual piece, define properties or labels, and related pieces.

There is currently no way to define this inside of bazel. Any such implementation requires repeated and recursive calls to bazel query and utilities outside.

For example imagine this code structure (with a BUILD file under each directory):

yoda/src/main/scala/com/example/yoda
yoda/src/test/scala/com/example/yoda
harrypotter/src/main/scala/com/example/harrypotter
harrypotter/src/test/scala/com/example/harrypotter
wand/src/main/scala/com/example/wand
wand/src/tests/scala/com/example/wand
deprecated/src/main/scala/example/deprecated

There is no way to define "yoda may not depend on harrypotter" or "set fatal_warnings=True on all targets under "yoda".

gregestren commented 2 years ago

Can visibility and package() help?

brentleyjones commented 2 years ago

Also package_group(), which I've used to implement the type of "service can't depended on other services" type of visibility before.

grimreaper commented 2 years ago

package() can not help since it only applies to the given BUILD file.

package_group() is similar to what I was discussing here especially considering that it supports ... in its definition. That said, it doesn't provide all the functionality I was discussing above. Even package does not.

I'll close this ticket and open more specific feature requests though. I was unaware of package_group prior.