Implement sysprop type checker

sysprop type checker compares a sysprop_library API file and
property_contexts files, and detects if there are any mismatches of
property types. For example, the following snippets are detected.

// foo.sysprop
prop {
prop_name: "ro.foo.bar"
type: Integer
...
}

// property_contexts
ro.foo.bar u:object_r:foo_prop:s0 exact string

"ro.foo.bar" is an Integer in .sysprop file, but it's a string in
property_contexts file.

Bug: 151879375
Test: sysprop_test
Test: run "m PlatformProperties" and see existing mismatches.
Change-Id: Iad86d0770011e13a6d8f3e9596e730200942e3fd
This commit is contained in:
Inseob Kim 2020-03-21 03:38:32 +09:00
parent b358ebb759
commit 628d7ef0c7

View file

@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"io" "io"
"path" "path"
"sync"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@ -154,8 +155,21 @@ type syspropLibraryProperties struct {
var ( var (
pctx = android.NewPackageContext("android/soong/sysprop") pctx = android.NewPackageContext("android/soong/sysprop")
syspropCcTag = dependencyTag{name: "syspropCc"} syspropCcTag = dependencyTag{name: "syspropCc"}
syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
syspropLibrariesLock sync.Mutex
) )
func syspropLibraries(config android.Config) *[]string {
return config.Once(syspropLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
func SyspropLibraries(config android.Config) []string {
return append([]string{}, *syspropLibraries(config)...)
}
func init() { func init() {
android.RegisterModuleType("sysprop_library", syspropLibraryFactory) android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
} }
@ -195,6 +209,10 @@ func (m *syspropLibrary) HasPublicStub() bool {
return proptools.Bool(m.properties.Public_stub) return proptools.Bool(m.properties.Public_stub)
} }
func (m *syspropLibrary) CurrentSyspropApiFile() android.Path {
return m.currentApiFile
}
func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
baseModuleName := m.BaseModuleName() baseModuleName := m.BaseModuleName()
@ -463,6 +481,12 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Stem: proptools.StringPtr(m.BaseModuleName()), Stem: proptools.StringPtr(m.BaseModuleName()),
}) })
} }
syspropLibrariesLock.Lock()
defer syspropLibrariesLock.Unlock()
libraries := syspropLibraries(ctx.Config())
*libraries = append(*libraries, ctx.ModuleName())
} }
func syspropDepsMutator(ctx android.BottomUpMutatorContext) { func syspropDepsMutator(ctx android.BottomUpMutatorContext) {