Commit graph

20 commits

Author SHA1 Message Date
Paul Duffin
5ec73ecc08 Reduce duplication in visibility property management
Adds a couple of new methods to manage visibility property instances to
reduce duplication and encapsulate the implementation slightly better.

The AddVisibilityProperty method is exported as it will be needed by
other packages in follow up commits.

Bug: 155295806
Test: m nothing
Change-Id: Ic1a9bb1e151fc6ae65761344fd210b4e4ba74fbc
2020-05-01 18:35:05 +01:00
Colin Cross
eabaedd520 Fix product variables in defaults modules
Product variables structs are generated at runtime to contain only
the properties that apply to the current module.  Defaults modules
always contained all product variable properties. Defaults modules
apply their properties to the target module using
proptools.PrependProperties, which prepends structs that have
matching types.  Filtered property structs had a different type
and were dropped.

Even after adding filtering to the defaults product variable
properties, defaults modules may contain more property structs
than the target module they are applied to, so the product
variables struct for the defaults module could contain more
fields than the product variables struct for the target module.
Use proptools.PrependMatchingProperties when applying defaults
of product variables instead, which will apply matching properties
across types.

Test: defaults_test.go
Test: variable_test.go
Change-Id: I281bdefef92053457a3b7b65383493a4e7d999df
2020-02-06 17:43:29 -08:00
Jiyong Park
3814f4df2b apex_available is defaultable
Previously, it was defaultable only for cc_library. Now, it is
defaultable for all module types.

Bug: 128708192
Test: m
Change-Id: If248f593da6f4b724bf889ccd7f2e077d48069b5
2019-12-02 13:48:33 +09:00
Paul Duffin
95d53b584f Add defaults_visibility support
Bug: 130796911
Test: m nothing
Change-Id: I7b9462d3360be2bbeaf6ff38c5328f45ff5b5ebb
2019-07-25 11:48:21 +01:00
Paul Duffin
63c6e183d5 Refactor visibility to support visibility on defaults modules
Existing modules, either general one or package ones have a single
visibility property, called visibility in general, and
default_visibility on package, that controls access to that module, or
in the case of package sets the default visibility of all modules in
that package. The property is checked and gathered during the similarly
named phases of visibility processing.

The defaults module will be different as it will have two properties.
The first, visibility, will not affect the visibility of the module, it
only affects the visibility of modules that 'extend' the defaults. So,
it will need checking but not parsing. The second property,
defaults_visibility, will affect the visibility of the module and so
will need both checking and parsing.

The current implementation does not handle those cases because:
1) It does not differentiate between the property that affects the
   module and those that do not. It checks and gathers all of them with
   the last property gathered overriding the rules for the previous
   properties.

2) It relies on overriding methods in MethodBase in order to change the
   default behavior for the package module. That works because
   packageModule embeds ModuleBase but will not work for
   DefaultsModuleBase as it does not embed ModuleBase and instead is
   embedded alongside it so attempting to override a method in
   MethodBase leads to ambiguity.

This change addresses the issues as follows:
1) It adds a new visibility() []string method to get access to the
   primary visibility rules, i.e. the ones that affect the module.

2) It adds two fields, 'visibilityPropertyInfo []visibilityProperty'
   to provide information about all the properties that need checking,
   and 'primaryVisibilityProperty visibilityProperty' to specify the
   property that affects the module.

The PackageFactory() and InitAndroidModule(Module) functions are
modified to initialize the fields. The override of the
visibilityProperties() method for packageModule is removed and the
default implementations of visibilityProperties() and visibility()
on ModuleBase return information from the two new fields.

The InitDefaultsModule is updated to also initialize the two new
fields. It uses nil for primaryVisibilityProperty for now but that
will be changed to return defaults_visibility. It also uses the
commonProperties structure created for the defaults directly instead
of having to search for it through properties().

Changed the visibilityProperty to take a pointer to the property that
can be used to retrieve the value rather than a lambda function.

Bug: 130796911
Test: m nothing
Change-Id: Icadd470a5f692a48ec61de02bf3dfde3e2eea2ef
2019-07-25 11:31:42 +01:00
Paul Duffin
e62432feee Add DefaultsModule interface
Changes the InitDefaultsModule method from taking a DefaultableModule
to taking a DefaultsModule in preparation for adding visibility support
to defaults modules.

Bug: 130796911
Test: m nothing
Change-Id: I1d459da1017ae7f2654e7eb275cb424e52d85730
2019-07-25 10:51:27 +01:00
Paul Duffin
7df7fb0dff Improve documentation of defaults mechanism
Also, removes unnecessary cast from DefaultableModule to Defaultable.

Bug: 130796911
Test: m nothing
Change-Id: I01d8f5186927215a1aa6b7431558041f427d7381
2019-07-25 10:50:57 +01:00
Treehugger Robot
188236ff23 Merge "Document how properties work in defaults modules." 2019-07-09 02:25:36 +00:00
Colin Cross
59037628f4 Add GenerateAndroidBuildActions to DefaultsModuleBase
Add an empty GenerateAndroidBuildActiosn to DefaultsModuleBase
so that every defaults module doesn't need to provide one.  This
will also allow adding an implementation in the next patch.

Test: m checkbuild
Change-Id: I13554bdb3a287c2f18e1efab74d4f08a1ba8620c
2019-06-10 13:51:17 -07:00
Martin Stjernholm
ebd757d609 Document how properties work in defaults modules.
Also remove an unused field in DefaultsModuleBase.

Test: m nothing
Test: Verify no diffs in ninja files:
  <check out clean tree>
  m nothing && shasum out/*.ninja | sort -k2 > before
  <apply patch>
  m nothing && shasum out/*.ninja | sort -k2 > after
  diff before after
Bug: 112158820
Change-Id: Id819cea10f7af1603b4e4e1b14c0b49afcd0fecd
2019-05-24 11:27:08 +01:00
Colin Cross
a1ce2a0071 Update soong for blueprint change to allow multiple deps
Blueprint allows multiple dependencies on the same module after
https://github.com/google/blueprint/pull/210.

Fix defaults, WalkDeps can now find the same defaults module multiple
times.

Fix droiddoc, if the srcs_lib points to a lib module that is
specified multiple times, for example through explicit properties
and implicit default libraries, the srcs would be listed on the
command line multiple times.  Move srcs_lib to use its own dependency
tag.

Test: m checkbuild
Change-Id: Ia30ce83be1382820d76bca5046ad18cbffe8af1a
2018-06-20 22:56:36 +00:00
Colin Cross
d11fcda940 Convert Visit*Deps from blueprint.Module to android.Module
Also adds checks that the dependencies are android.Modules and
are not disabled.

Test: m checkbuild
Change-Id: I05e945f38915d49cd3c0ab72a86576949bc7eff2
2017-10-24 13:01:03 -07:00
Colin Cross
89536d4948 Add support for java_defaults modules
Test: java_test.go
Change-Id: I6dba1671c7eb019183af94bb7b10810296740101
2017-07-20 05:47:27 +00:00
Colin Cross
1f44a3aa4f Don't pass same argument twice for defaults modules initialization
InitDefaultsModule and InitDefaultableModule were requiring the
module to be passed in as an argument twice, once as a
android.Module and once as an android.DefaultableMOdule.  Use
a type assertion instead.

Test: builds
Change-Id: I57d721e68a4f016e02c17a678af5f2ba25a9a430
2017-07-19 23:14:36 +00:00
Colin Cross
cec8171420 Add integration testing infrastructure
Fix mutator registration for tests to allow different tests
in the same package to register different mutators.

Allow tests to track the resulting ModuleBuildParams objects
to use in assertions, and provide helpers for getting them.
For example:
    config := android.TestConfig(buildDir)
    ctx := android.NewTestContext()
    ctx.RegisterModuleType(...)
    ctx.MockFileSystem(...)
    ctx.ParseBlueprintsFile("Android.bp")
    ctx.PrepareBuildActions(config)
    ctx.Register()
    // Get the Inputs value passed to the javac rule for the foo module
    inputs := ctx.ModuleForTests("foo".Rule("javac").Inputs

Test: java_test.go
Change-Id: I10c82967f5f3586d2c176f169906b571ed82fc73
2017-07-14 14:19:51 -07:00
Colin Cross
36242850fd Refactor factories
Change module factories from returning a blueprint.Module and a list
of property structs to returning an android.Module, which holds the
list of property structs.

Test: build.ninja identical except for Factory: comment lines
Change-Id: Ica1d823f009db812c518f271a386fbff39c9766f
2017-06-30 21:08:36 +00:00
Colin Cross
fc754581fc Add a Name property
Blueprint is going to abdicate responsibility for determining the name
of a module.  Add a name property, and a method to retreive the name.

Test: build.ninja identical
Change-Id: I09c6f5283cd6e28ad4b04c24c5ab8b00f71ae2ab
2016-10-12 17:24:49 -07:00
Colin Cross
1317701114 Convert defaults to a top down mutator
BottomUpMutators are going to lose their ctx.Visit* functions in order
to allow parallelizing them, move defaults to a TopDownMutator using
WalkDeps to only visit defaults modules.

Test: no changes to out/soong/build.ninja
Change-Id: I54ba65a7e2ae9503f4d217f63aa9178a7c5341f0
2016-08-09 13:54:03 -07:00
Colin Cross
e7b07137d4 Allow defaults modules to have defaults
Allow chaining defaults modules by making Defaults be a Defaultable.

Change-Id: I4ba86c07f7aad9c396ed33d55fe95d1fb78e487d
2016-07-27 10:15:06 -07:00
Colin Cross
635c3b0157 Rename common to android
Rename the "common" package to "android", because common is too
generic.  Also removes all android.Android naming stutter.

Ran:
gomvpkg -from 'android/soong/common' -to 'android/soong/android'
gorename -from '"android/soong/android".AndroidModuleContext' -to 'ModuleContext'
gorename -from '"android/soong/android".AndroidBaseContext' -to 'BaseContext'
gorename -from '"android/soong/android".AndroidModuleBase' -to 'ModuleBase'
gorename -from '"android/soong/android".AndroidBottomUpMutatorContext' -to 'BottomUpMutatorContext'
gorename -from '"android/soong/android".AndroidTopDownMutatorContext' -to 'TopDownMutatorContext'
gorename -from '"android/soong/android".AndroidModule' -to 'Module'

Change-Id: I3b23590b8ce7c8a1ea1139411d84a53163288da7
2016-05-18 15:37:25 -07:00
Renamed from common/defaults.go (Browse further)