Commit graph

74 commits

Author SHA1 Message Date
colincross
cfa2e91dc4
Actually pause mutators when adding dependencies (#335)
In the coordination between #316 and #318 the calls to mctx.pause()
were forgotten, causing dependencies returned by the Add*Dependency
calls to be in an undefined state.  Add the missing calls to
mctx.pause().

Change-Id: I648ad269449777363801785059b13b866424d4b5
2020-12-14 11:23:23 -08:00
Martin Stjernholm
0f1637b19b
Improve formatting of some error messages. (#327)
In particular the formatting of dependencies with variants which lacked
braces that caused them to float together with the dependency names.

Also add some context to the ReplaceDependenciesIf panic message.

Test: m
Change-Id: Ibd03690317ca53f3ecbdd95033404d89d849b4dd
2020-11-16 12:15:36 -08:00
Colin Cross
2da8492b9d Add Providers to Blueprint
Providers are a new concept for Blueprint, based on providers in Bazel:
https://docs.bazel.build/versions/master/skylark/rules.html#providers

Providers aim to simplify the interaction between modules by replacing
type asserting to arbitrary interfaces with requesting optional data
objects from modules.  This will also move Blueprint closer to supporting
incremental analysis by serializing the providers and only rerunning
the analysis phase on modules whose inputs have changed.

Change-Id: I39f5f78b372412a7dbf151ceccb3f917f6c874bf
2020-09-22 18:20:18 -07:00
colincross
66fa73dd6e
Merge pull request #316 from skvadrik/add-dep-ret-mod
Return dependency modules from dependency-adding methods.
2020-09-22 10:59:46 -07:00
Ulya Trafimovich
9577bbc922 Return dependency modules from dependency-adding methods.
The motivaion for this change is to allow writing code that uses the
newly added dependency module in the same mutator pass, for example to
add more dependencies. Like this:

  for _, m := range ctx.AddVariationDependencies(nil, tag, deps...) {
      if someModuleProperty(m); ok {
          ctx.AddVariationDependencies(nil, tag, otherDep)
      }
  }

Note that there is no guarantee that the returned module has already
been processed by the current mutator.

The patch does not add runtime overhead on findng dependency modules,
as this has already been done previously.

Test: go test
2020-09-17 11:43:15 +01:00
Colin Cross
c4773d90a2 Support pausing parallelVisit
Pass a channel to visitor functions called by parallelVisit that
allows them to pause the current visitor until a given visitor
has finished.  This allows parallelVisit to work on a dependency
graph while it is being mutated.

Test: Test_parallelVisit
Change-Id: Id8b1542c22ac9914439310e31d992ae0d7318d69
2020-09-16 12:58:39 -07:00
Colin Cross
5df74a8e38 Maintain ordering between variants and aliases
AddFarVariationDependencies takes the first matching variant.  To
maintain sensible behavior on a module with aliases, the ordering
of aliases and module variants needs to be maintained so that
AddFarVariationDependencies can find an earlier matching alias
instead of a more specific variant.

Test: go test .
Change-Id: I78f4e96edd98159f3a62d94e240e5d652667bec4
2020-09-09 18:29:15 -07:00
Colin Cross
39644c0903 Add tests for findVariant
Add tests for findVariant behavior that provides the matching
behaviors of AddVariationDependencies, AddFarVariationDependencies,
etc.

Test: Test_findVariant
Change-Id: I3494d57179c8b3d62f7d32e5a1b43c9b9672c2df
2020-09-09 18:27:32 -07:00
Colin Cross
18926521dc Make VisitAllModuleVariants, PrimaryModule and FinalModule available to mutators
Move the VisitAllModuleVariants, PrimaryModule and FinalModule methods to
baseModuleContext so they can be used by mutators.

Test: m checkbuild
Change-Id: I1827ce2fc75f017460a7f6a53b1dab6a81109435
2020-09-09 13:25:54 -07:00
Colin Cross
279489c017 Add CreateAliasVariation
CreateAliasVariation creates a new variation for the current mutator
that is an alias to a variation that was created with CreateVarations
by the same mutator.  It is similar to AliasVariation, except that
AliasVariation creates an alias from the pre-mutated variant to one
of the new variations, while CreateAliasVariation creates an alias
from a new post-mutated variation to one of the new variations.

Bug: 164216768
Test: TestCreateAliasVariation
Change-Id: I8847b8d6fc1d3248abc910b2fe2399881f9bdaee
2020-08-14 11:15:58 -07:00
Colin Cross
edc41769fe Combine variant fields into variant struct
Combine variant, variations and dependencyVariations into a single
struct.

Test: blueprint tests
Change-Id: I76811bb2bdf76f1b4cffc6a7b9bc7362ecb5f7b9
2020-08-14 11:15:58 -07:00
Daniel Cardenas
5de3dc04e0 Android inclusive language fixit. Make comment more succinct, clear and remove use of term "sanity".
Bug: 162536543
Change-Id: I4b40b1637e142d2f2fd513f62357213a9832bbaa
2020-07-30 16:48:42 -07:00
Paul Duffin
8969cb6170 Add ReplaceDependeciesIf to allow for conditional replacement
Adds support for making the replacement of one dependency with another
conditional on the from and to module as well as the tag used.
2020-06-30 12:15:26 +01:00
Martin Stjernholm
2f212479e2 Add ctx.OtherModule(Reverse)DependencyVariantExists.
This allows guarding calls to AddVariationDependencies and
AddReverseDependency to register dependencies on optional modules.
2020-05-26 20:52:43 +01:00
Paul Duffin
2a2c58ef46 Support checking syntax of generated Blueprint files
Adds a CheckBlueprintSyntax(...) method to check the syntax of a
Blueprint file.

Changes processModuleDef and newModule from being method on *Context to
being standalone functions. That ensures that CheckBlueprintSyntax(...)
does not need to take a context and so there is no chance that it can
change its state.
2020-05-13 09:06:17 +01:00
Colin Cross
c03a50c49c Add EarlyModuleContext.BlueprintsFile
EarlyModuleContext already has ModuleDir, add BlueprintsFile too.

Test: m checkbuild
Change-Id: Ia9e0c724562e1461dfcd5e01f56ff8abbea2ac06
2020-01-14 13:00:01 -08:00
Colin Cross
9672d86a87 Add scoped module factories
Add RegisterScopedModuleType to LoadHookContext that registers
a module type factory that will be visible for the remainder of
the file.  Also add ModuleFactories that returns the globally
register module factories.

Test: all blueprint tests
Change-Id: If646a73befe3b8e45c4b0984531c6a39ddc8d066
2020-01-02 20:32:51 -08:00
Colin Cross
da70fd0b84 Move LoadHooks from Soong to Blueprint
Move LoadHooks from Blueprint and run them during ParseBlueprintsFiles.
This will allow them to add scoped module types that are visible to the
rest of the Blueprints file.  Requires passing the config object to
ParseBlueprintsFiles.

Test: all blueprint tests
Change-Id: Ia2a2c9a0223d5458bfd48bd22ebed0fdbd0156c6
2020-01-02 20:32:51 -08:00
Colin Cross
f7beb89df5 Add support for module variant aliases
Adding a dependency on a module with variants can be problematic
if the code adding the dependency is not aware of every mutator
that has created variants.  Add an AliasVariations to
BottomUpMutatorContext, which allows a mutator to alias the
original variant of a module to one of the new variants of the
module, which will allow future dependencies to be added using
the original list of variations.  The aliases are transient,
and only exist until the next mutator that calls CreateVariations
when visiting the module without also calling AliasVariations.

Test: TestAlises
Change-Id: Ieaa04b5a6bdcb5a1ff5114b1e03460de795d4479
2019-11-14 12:58:52 -08:00
Colin Cross
9403b5a790 Delay allocating variationMaps until populating them
Modules are created with a nil variantionMap, which avoids allocating
an empty map if the module will never be split.
Context.addVariationDependencies constructs a variationMap to
compare against the variationMap of each variant, but constructed
an empty variationMap if no variations were specified.  A nil
map is not the same as an empty map, so consistently use a nil
map and create it when populating the first entry.

Change-Id: I48b604659f9cdb23326b504a093cdfe5a3eb4f68
2019-11-14 12:58:52 -08:00
Colin Cross
6af7284d08 Make CreateModule return the newly created module
Allow mutators to modify properties of the newly created module
by returning it.

Change-Id: Ia1acc70b6196195d1bad58c88ab3def70b99e42c
2019-09-25 14:53:25 -07:00
Jiyong Park
1e2e56dc62 Add SetDefaultDependencyVariation
SetDefaultDependencyVariation sets the variation name that will be used
when a dangling dependency is found while a module is being split. A
dangling dependency can occur if a module is split to a variant that one
of its dependencies is not split into. When the default variation is not
set, such dangling dependency is a hard error. But with the new
function, the default variation can be set and subsequent calls to
CreateVariations and its variations on the same context uses the default
variation when necessary.

(If even the default variation does not exist for the dependent module,
it is an hard error)

Note that this is different from calling SetDependencyVariation("foo")
followed by CreateVariations("foo", "bar"). In that case, regardless of
whether a dependency of the current module has the variant 'bar' or not,
only the 'foo' variant is chosen.

With SetDefaultDependencyVariation("foo") followed by
CreateVariations("foo", "bar"), 'foo' variant is used only when the
'bar' variant of the current module depends on a module that does not
have 'bar' variant.

Bug: 138103882
Test: m
Change-Id: I4520ca87487994de024fdbacda3bef6636225f0d
2019-08-09 12:49:11 -07:00
Colin Cross
d8367ff746 Add MutatorName to mutator contexts
Allow querying the mutator name for debugging.

Bug: 136473661
Change-Id: I6a9f1f8cc4fd456d32cc2f2ef85a497c193d7e09
2019-07-02 10:08:55 -07:00
Colin Cross
322cc01803 Report creating modules in errors on created modules
Bug: 133172285
Change-Id: I0782c722f5877508691868f96dbf7dc0bed3f9f4
2019-05-20 15:09:48 -07:00
Colin Cross
7bcc256dac Move module and singleton godoc from the implementation to the interface
The interface is visible in godoc, not the implementation, so
move the documentation onto the interface methods.

Test: view godoc
Change-Id: I3460003eed6bf57d8ae4dabe70ab306f049a0060
2019-05-20 15:08:39 -07:00
Colin Cross
99bdb2ab4f Consolidate mutator contexts
Move most of the mutator context methods into BaseModuleContext
so they are available to both top down and bottom up mutators.
Only CreateModule is unique to TopDownMutatorContext, and the
dependency and variation adding methods are unique to the
BottomUpMutatorContext.

The dependency visiting methods are now available on
BottomUpMutatorContext, which requires delaying making newly
added dependencies visible to maintain the invariant that
the mutator has been called on the dependency before the
dependency can be visited by its parents.

Test: m checkbuild
Change-Id: Ie14afc02ac76d0b5a66b0e52de2aa9e17fd1bec0
2019-05-20 14:58:14 -07:00
Colin Cross
d28b304d30 Add more OtherModule* methods
Add OtherModuleDir, OtherModuleSubDir, and OtherModuleType to
ModuleContext and TopDownMutatorContext, and add ModuleType to
BaseModuleContext.

Change-Id: If5c873a2620ef10333c0bdba5ab89d4256e5fdf2
2019-03-01 13:44:15 -08:00
Alex Light
142de248fa GetDirectDepWithTag needs to check all tags before panicing
GetDirectDeWithTag would panic if the first possible directDep did not
have the correct tag. It should check to see if any version of that
dependency has the right tag.

Test: atest CtsJdwpTunnelHostTestCases
Bug: 124507633
Bug: 125933724
Change-Id: I00d269130e9f136a93fd30c58b8fd929372d5b37
2019-02-27 15:34:26 -08:00
Colin Cross
526e02f0c6 Prevent duplicate visit calls in WalkDeps
WalkDeps was following every possible path through the dependency
tree, which can be enormous.  Modify it to only call visit for
any particular (child, parent) pair once for each direct dependency
by not recursing into child if visitDown returns true but child
has already been visited.

Test: TestWalkDeps, TestWalkDepsDuplicates
Change-Id: Ieef28399bd10e744417cdeb661dfa04fbeb4ec60
2018-06-21 13:41:42 -07:00
Colin Cross
9607a9f248 Allow multiple dependencies on the same module
Allow adding multiple dependencies on the same module.  Adds a flag
to Context.walkDeps to determine whether dependencies should be
visited multiple times, and clarifies the behavior of
VisitDepsDepthFirst (continues to visit each module once, even if
there are multiple dependencies on it) and VisitDirectDeps (may
visit a module multiple times).

Test: TestWalkDepsDuplicates, TestVisit
Change-Id: I58afbe90490aca102d242d63e185386e1fe55d73
2018-06-20 14:10:18 -07:00
Dan Willemsen
b6c90239d6 Append / to directories in Glob results
This makes it easy for users of Glob to detect whether the match is a
file or directory. Doing the check at this level means that the filelist
file used as a dependency will be updated if a directory is replaced
with a file of the same name, or vice versa.

Change-Id: I79ebba39327218bcdcf50b393498306119de9d6c
2018-02-23 17:21:37 -08:00
Jeff Gaston
0e90759bfe Make ninja file deterministic even with dup module names
Bug: 65683273
Test: ./build/soong/scripts/diff_build_graphs.sh \
      --products=aosp_arm '' ''

Change-Id: I5e45b2309ba4993ba2180b5f9a4785f31e28d503
2017-12-04 17:16:21 -08:00
Jeff Gaston
3c8c3346d2 Pass ModulePath to NameInterface
To allow it to validate that the filename equals Android.bp

Bug: 65683273
Test: m -j nothing # which runs tests
Change-Id: I171dddd102590df558053b615d39c75c00b6ac6e
2017-12-04 17:16:21 -08:00
Jeff Gaston
d70bf75491 Extract module naming into an interface
in facilitate moving name resolution to Soong

Bug: 65683273
Test: build/soong/scripts/diff_build_graphs.sh \
      --products=aosp_arm \
      'build/blueprint:work^' 'build/blueprint:work'
      # and see that the only changes were:
      # 1. adding the name_interface.go file
      # 2. changing some line numbers

Change-Id: Ifa7603cca59b3b3d592f2f146fdafe57012bd4b9
2017-11-29 12:01:09 -08:00
Colin Cross
1fa1a14853 Set fields in CreateModule to match current module
When a mutator calls CreateModule, set the blueprints file and line
number to the values of the module that the mutator was visiting.

Change-Id: I4526f14a744be944e42582bc46f11a9a7b502f03
2017-10-27 16:32:15 -07:00
Colin Cross
874a346904 Let mutators use ctx.AddNinjaFileDeps
Propagate extra ninja file deps through mutators so that they
can use ctx.AddNinjaFileDeps.

Test: blueprint tests
Change-Id: I299a0665c3f63b020ae345889fd78b91b91b215a
2017-08-01 15:12:12 -07:00
Colin Cross
af4fd215eb Add TopDownMutatorContext.CreateModule
Allow a module to create other modules as if they were specified
in a blueprint file.  CreateModule takes the name of a module type,
calls the factory function the module type, and then inserts
properties into the property structs returned by the factory.

Bug: 64161749
Test: TestCreateModule
Change-Id: Ic1903305d6b08eae1edc7f0fb4137e85544aac0f
2017-08-01 15:12:12 -07:00
Colin Cross
5fe225f5f9 Rename newModules to newVariations
The next patch will introduce creating new modules, so rename the
current variable that contains new variations of existing modules
to avoid confusion.

Test: blueprint tests
Change-Id: Ic1d3824e54e51c282a08f8ecef8fc658cc503a65
2017-08-01 15:12:12 -07:00
Nan Zhang
346b2d0d80 Added a check in BP level for BaseDependencyTag
It is not allowed to directly use BaseDependencyTag as customized
user dependency tag passed down to BP since it might cause issues
that different type of modules will be mixed when fetched based on
Tag.
2017-03-10 16:39:27 -08:00
Colin Cross
b519a7e1b6 Add globbing to filesystem mocking
Add globbing to filesystem mocking so that more code can be tested
against the mock.  Also moves the filesystem mock to pathtools,
and renames pathtools.GlobWithExcludes to pathtools.Glob, replacing
the existing pathtools.Glob.

Test: blueprint tests
Change-Id: I722df8121bc870c4a861d7c249245c57dcb607be
2017-02-02 16:48:06 -08:00
Colin Cross
dfb4c9f7af Add ModuleContext method to get dependency by name
Instead of forcing every mutator or module to use VisitDirectDeps
to iterate through its deps, allow it to request a dependency by
name to return the Module.

Change-Id: I18b23bffa324bb9d93a7743b6e2a19c07058c775
2016-12-14 10:42:00 -08:00
Colin Cross
0ce142ca05 Fix data race when applying replacements
Mutator context goroutines appending directly to the global Context's
replacements list causes a data race.  Send them over a channel
instead.

The renames and replacements are local to the mutator, so move them
out of Context and into the runMutator method.

Change-Id: I797edb1e27ee29f8946c58101b40fcfb50a32eb9
2016-12-09 10:35:33 -08:00
Colin Cross
127d2eae8b Import globbing from Soong
Add globbing with dependency checking to blueprint.  Calling
ModuleContext.GlobWithDeps or SingletonContext.GlobWithDeps will return
a list of files that match the globs, while also adding efficient
dependencies to rerun the primary builder if a file that matches the
glob is added or removed.

Also use the globbing support for optional_subdirs=, subdirs= and build=
lines in blueprints files.  The globbing slightly changes the behavior
of subname= lines, it no longer falls back to looking for a file called
"Blueprints".  Blueprint files that need to include a subdirectory with
a different name can use build= instead of subdir= to directly include
them.  The Blueprints file is updated to reset subname="Blueprints" in
case we want to include subdirectories inside blueprint and the primary
builder has changed the subname.

Also adds a new test directory that contains a simple primary builder
tree to test regeneration for globbing, and runs the tests in travis.

Change-Id: I83ce525fd11e11579cc58ba5308d01ca8eea7bc6
2016-11-03 13:54:03 -07:00
Colin Cross
9cfd198dd8 Add ReplaceDependencies
ReplaceDependencies allows a module to replace dependencies on a
matching variant of a target module with itself.

Change-Id: I22946dec23c38ed5e1ad23b87121d72668268c01
2016-10-12 13:33:37 -07:00
Colin Cross
c4e5b8157b Add Rename
Allow modules to be renamed by mutators.  This will allow modules to
dynamically adapt to the presence or absence of modules with the same
name.  For example, if a source module does not exist, a prebuilt module
could rename itself to the name of the source module so that
dependenices on the module name are satisified.

Change-Id: I44004604c6d9db041bb7d38fe6c1ca877bc7d6f1
2016-10-12 13:33:37 -07:00
Colin Cross
b3f96c3306 Add OtherModuleExists
Allow dependency modifying mutators to check if another module exists
based on its name.  Allows primary builders to have custom handling for
missing-module errors, for example by falling back to another module.

Change-Id: I04ddd66be43c514f1f8928e15b2a79cadebcfc17
2016-10-12 13:33:37 -07:00
Colin Cross
0b7e83e11a Ask primary builder for module names
Remove the assumed Name and Deps properties.  Instead, ask the Module
for the Name, and require them to use the existing replacements for
Deps.

Change-Id: I729045d86277686078b3aa0bba71c67d612ead2c
2016-10-12 13:33:37 -07:00
Colin Cross
2c62844274 Improve error reporting
Report module name and variant and property names in errors.

Change-Id: I747f840402497b2c92bf8c565d7c50af33e6ab0e
2016-10-12 11:14:18 -07:00
Colin Cross
49c279ab26 Parallelize BottomUpMutators
Allow BottomUpMutators to run in parallel by calling Parallel() on the
return value of RegisterBottomUpMutator.  To avoid locking, moves
updates of global state into a separate goroutine that receives updates
over channels from the mutator goroutines.

Change-Id: Ic59b612da9b406cf59ec44940f0c1dee0c051a51
2016-08-10 16:31:35 -07:00
Colin Cross
93c4cf6861 Revert "Add dependency visiting methods to BottomUpMutatorContext"
This reverts commit a2b2080fcd.

Dependency visiting methods conflict with the dependency adding methods
already present on BottomUpMutatorContext - mixing calls to visit
dependencies and adding dependencies produces requires hard-to-define
semantics, and complicates parallizing mutators.

Change-Id: I2f793c8db45b97f4d79badc9fe88315fe38d90cd
2016-08-10 16:31:35 -07:00