Merge "Allow stubs implementation to be omitted" am: 378124baf1
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2301917 Change-Id: I6fb94bba4db679feb806ff8712d21eb7191b8b1c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -59,6 +59,7 @@ func init() {
|
|||||||
AddNeverAllowRules(createInitFirstStageRules()...)
|
AddNeverAllowRules(createInitFirstStageRules()...)
|
||||||
AddNeverAllowRules(createProhibitFrameworkAccessRules()...)
|
AddNeverAllowRules(createProhibitFrameworkAccessRules()...)
|
||||||
AddNeverAllowRules(createBp2BuildRule())
|
AddNeverAllowRules(createBp2BuildRule())
|
||||||
|
AddNeverAllowRules(createCcStubsRule())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a NeverAllow rule to the set of rules to apply.
|
// Add a NeverAllow rule to the set of rules to apply.
|
||||||
@@ -214,6 +215,17 @@ func createCcSdkVariantRules() []Rule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createCcStubsRule() Rule {
|
||||||
|
ccStubsImplementationInstallableProjectsAllowedList := []string{
|
||||||
|
"packages/modules/Virtualization/vm_payload",
|
||||||
|
}
|
||||||
|
|
||||||
|
return NeverAllow().
|
||||||
|
NotIn(ccStubsImplementationInstallableProjectsAllowedList...).
|
||||||
|
WithMatcher("stubs.implementation_installable", isSetMatcherInstance).
|
||||||
|
Because("implementation_installable can only be used in allowed projects.")
|
||||||
|
}
|
||||||
|
|
||||||
func createUncompressDexRules() []Rule {
|
func createUncompressDexRules() []Rule {
|
||||||
return []Rule{
|
return []Rule{
|
||||||
NeverAllow().
|
NeverAllow().
|
||||||
|
@@ -367,6 +367,22 @@ var neverallowTests = []struct {
|
|||||||
"framework can't be used when building against SDK",
|
"framework can't be used when building against SDK",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Test for the rule restricting use of implementation_installable
|
||||||
|
{
|
||||||
|
name: `"implementation_installable" outside allowed list`,
|
||||||
|
fs: map[string][]byte{
|
||||||
|
"Android.bp": []byte(`
|
||||||
|
cc_library {
|
||||||
|
name: "outside_allowed_list",
|
||||||
|
stubs: {
|
||||||
|
implementation_installable: true,
|
||||||
|
},
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
expectedErrors: []string{
|
||||||
|
`module "outside_allowed_list": violates neverallow`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var prepareForNeverAllowTest = GroupFixturePreparers(
|
var prepareForNeverAllowTest = GroupFixturePreparers(
|
||||||
@@ -419,6 +435,10 @@ type mockCcLibraryProperties struct {
|
|||||||
Platform struct {
|
Platform struct {
|
||||||
Shared_libs []string
|
Shared_libs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stubs struct {
|
||||||
|
Implementation_installable *bool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockCcLibraryModule struct {
|
type mockCcLibraryModule struct {
|
||||||
|
@@ -2301,7 +2301,7 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
|
|||||||
//
|
//
|
||||||
// Always include if we are a host-apex however since those won't have any
|
// Always include if we are a host-apex however since those won't have any
|
||||||
// system libraries.
|
// system libraries.
|
||||||
if !am.DirectlyInAnyApex() {
|
if ch.IsStubsImplementationRequired() && !am.DirectlyInAnyApex() {
|
||||||
// we need a module name for Make
|
// we need a module name for Make
|
||||||
name := ch.ImplementationModuleNameForMake(ctx) + ch.Properties.SubName
|
name := ch.ImplementationModuleNameForMake(ctx) + ch.Properties.SubName
|
||||||
if !android.InList(name, a.requiredDeps) {
|
if !android.InList(name, a.requiredDeps) {
|
||||||
|
7
cc/cc.go
7
cc/cc.go
@@ -1376,6 +1376,13 @@ func (c *Module) HasStubsVariants() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Module) IsStubsImplementationRequired() bool {
|
||||||
|
if lib := c.library; lib != nil {
|
||||||
|
return lib.isStubsImplementationRequired()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
|
// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
|
||||||
// the implementation. If it is an implementation library it returns its own name.
|
// the implementation. If it is an implementation library it returns its own name.
|
||||||
func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
|
func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
|
||||||
|
@@ -71,6 +71,12 @@ type LibraryProperties struct {
|
|||||||
// List versions to generate stubs libs for. The version name "current" is always
|
// List versions to generate stubs libs for. The version name "current" is always
|
||||||
// implicitly added.
|
// implicitly added.
|
||||||
Versions []string
|
Versions []string
|
||||||
|
|
||||||
|
// Whether to not require the implementation of the library to be installed if a
|
||||||
|
// client of the stubs is installed. Defaults to true; set to false if the
|
||||||
|
// implementation is made available by some other means, e.g. in a Microdroid
|
||||||
|
// virtual machine.
|
||||||
|
Implementation_installable *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the name of the output
|
// set the name of the output
|
||||||
@@ -1339,6 +1345,7 @@ type versionedInterface interface {
|
|||||||
buildStubs() bool
|
buildStubs() bool
|
||||||
setBuildStubs(isLatest bool)
|
setBuildStubs(isLatest bool)
|
||||||
hasStubsVariants() bool
|
hasStubsVariants() bool
|
||||||
|
isStubsImplementationRequired() bool
|
||||||
setStubsVersion(string)
|
setStubsVersion(string)
|
||||||
stubsVersion() string
|
stubsVersion() string
|
||||||
|
|
||||||
@@ -2298,6 +2305,10 @@ func (library *libraryDecorator) hasStubsVariants() bool {
|
|||||||
len(library.Properties.Stubs.Versions) > 0
|
len(library.Properties.Stubs.Versions) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (library *libraryDecorator) isStubsImplementationRequired() bool {
|
||||||
|
return BoolDefault(library.Properties.Stubs.Implementation_installable, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
|
func (library *libraryDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
|
||||||
if !library.hasStubsVariants() {
|
if !library.hasStubsVariants() {
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user