[subpackages] Update examples and GN rules with improved patterns
Now that PackageResolver supports subpackages, the subpackage examples
are updated to align with expected patterns.
This CL also changes the PackageResolver implementation slightly, to
allow non-base packages to depend on subpackages in base. The reverse is
still disallowed. (A package in base cannot depend on a subpackage that
is not also in base.) Consider two "superpackages" (one in base and one
not in base) that depend on the same subpackage. In order for the
superpackage in base to resolve the subpackage, the subpackage _MUST_
also be in base. Since the subpackage is defined by it's blobs, the base
representation is guaranteed to match the representation expected by the
superpackage not in base, so the PackageResolver is capable of returning
the package from base without unnecessarily duplicating the blob outside
of base. This behavior is internal to the PackageResolver.
This CL also improves the `subpackages = []` GN declaration to align
more closely with how packages include additional components, via a
`deps = []` list of targets, and since most subpackages will _not_ need
to be renamed, the alignment shortens the cognitive distance for
migrating component dependencies to subpackage dependencies.
A new `renameable_subpackages = [{}, ...] replaces the prior
`subpackages` variable, allowing selected subpackages to be renamed,
when required.
`fuchsia_package_with_single_component()` and
`fuchsia_package_with_default_component()` both support `subpackages`
(and `renameable_subpackages`), since these targets are more likely to
be applicable for packages that include subpackages that were migrated
from in-package component deps.
And since a `fuchsia_test_package()` can easily be converted to migrate
component dependencies to subpackages, a `fuchsia_test_package()` can
much more commonly contain a single test component. So a
`fuchsia_test_package_with_default_component()` is added (mirroring the
existing `fuchsia_package_with_default_component()`, and is used in the
existing examples.
Lastly, the changes required updates to CTF (an early adopter of
subpackages), so I made the required changes after consulting with the
original author.
Bug: 100060
Change-Id: I8ada8732f7186d51b346c2d31da757b1e16f748c
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/744574
Reviewed-by: Kendal Harland <kjharland@google.com>
Reviewed-by: Erick Tryzelaar <etryzelaar@google.com>
Reviewed-by: Shai Barack <shayba@google.com>
Commit-Queue: Rich Kadel <richkadel@google.com>
Fuchsia is an open source, general purpose operating system supporting modern 64-bit Intel and ARM processors.
We expect everyone interacting with our project to respect our code of conduct.
Read more about Fuchsia's principles.
See Getting Started.
See fuchsia.dev.