diff options
| author | Colin Cross <ccross@android.com> | 2021-02-26 16:20:32 -0800 |
|---|---|---|
| committer | Colin Cross <ccross@android.com> | 2021-02-26 16:28:12 -0800 |
| commit | 75ce9eccf3651991ccd2897bba03b8a9bba9b733 (patch) | |
| tree | f203d0f649e0ec582982950481c1945bc1e2901f /sysprop | |
| parent | b014f0787edaa598e4d7186fc174c28b0091ed3a (diff) | |
Remove global state from sysprop libraries
Sysprop libraries use a global list to rewrite dependencies from
implementation libraries to public stub libraries when appropriate.
Remove the global list, and instead add a dependency from the
implementation to the public stub that forwards the JavaInfo.
Bug: 181367697
Test: sysprop_test.go
Change-Id: Ia7995feb3c079ca9bb6a403daaae3e3329fd7f6a
Diffstat (limited to 'sysprop')
| -rw-r--r-- | sysprop/sysprop_library.go | 109 | ||||
| -rw-r--r-- | sysprop/sysprop_test.go | 21 |
2 files changed, 53 insertions, 77 deletions
diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go index 2ccce1524..4ad68eadc 100644 --- a/sysprop/sysprop_library.go +++ b/sysprop/sysprop_library.go @@ -37,9 +37,10 @@ type dependencyTag struct { } type syspropGenProperties struct { - Srcs []string `android:"path"` - Scope string - Name *string + Srcs []string `android:"path"` + Scope string + Name *string + Check_api *string } type syspropJavaGenRule struct { @@ -68,10 +69,6 @@ var ( func init() { pctx.HostBinToolVariable("soongZipCmd", "soong_zip") pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java") - - android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel() - }) } // syspropJavaGenRule module generates srcjar containing generated java APIs. @@ -103,6 +100,12 @@ func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleConte } } +func (g *syspropJavaGenRule) DepsMutator(ctx android.BottomUpMutatorContext) { + // Add a dependency from the stubs to sysprop library so that the generator rule can depend on + // the check API rule of the sysprop library. + ctx.AddFarVariationDependencies(nil, nil, proptools.String(g.properties.Check_api)) +} + func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) { switch tag { case "": @@ -157,9 +160,6 @@ type syspropLibraryProperties struct { // If set to true, build a variant of the module for the host. Defaults to false. Host_supported *bool - // Whether public stub exists or not. - Public_stub *bool `blueprint:"mutated"` - Cpp struct { // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). // Forwarded to cc_library.min_sdk_version @@ -202,11 +202,8 @@ func (m *syspropLibrary) CcImplementationModuleName() string { return "lib" + m.BaseModuleName() } -func (m *syspropLibrary) JavaPublicStubName() string { - if proptools.Bool(m.properties.Public_stub) { - return m.BaseModuleName() + "_public" - } - return "" +func (m *syspropLibrary) javaPublicStubName() string { + return m.BaseModuleName() + "_public" } func (m *syspropLibrary) javaGenModuleName() string { @@ -221,10 +218,6 @@ func (m *syspropLibrary) BaseModuleName() string { return m.ModuleBase.Name() } -func (m *syspropLibrary) HasPublicStub() bool { - return proptools.Bool(m.properties.Public_stub) -} - func (m *syspropLibrary) CurrentSyspropApiFile() android.OptionalPath { return m.currentApiFile } @@ -399,16 +392,17 @@ type ccLibraryProperties struct { } type javaLibraryProperties struct { - Name *string - Srcs []string - Soc_specific *bool - Device_specific *bool - Product_specific *bool - Required []string - Sdk_version *string - Installable *bool - Libs []string - Stem *string + Name *string + Srcs []string + Soc_specific *bool + Device_specific *bool + Product_specific *bool + Required []string + Sdk_version *string + Installable *bool + Libs []string + Stem *string + SyspropPublicStub string } func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) { @@ -490,35 +484,42 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) { // Contrast to C++, syspropJavaGenRule module will generate srcjar and the srcjar will be fed // to Java implementation library. ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{ - Srcs: m.properties.Srcs, - Scope: scope, - Name: proptools.StringPtr(m.javaGenModuleName()), - }) - - ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ - Name: proptools.StringPtr(m.BaseModuleName()), - Srcs: []string{":" + m.javaGenModuleName()}, - Soc_specific: proptools.BoolPtr(ctx.SocSpecific()), - Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()), - Product_specific: proptools.BoolPtr(ctx.ProductSpecific()), - Installable: m.properties.Installable, - Sdk_version: proptools.StringPtr("core_current"), - Libs: []string{javaSyspropStub}, + Srcs: m.properties.Srcs, + Scope: scope, + Name: proptools.StringPtr(m.javaGenModuleName()), + Check_api: proptools.StringPtr(ctx.ModuleName()), }) // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API // and allow any modules (even from different partition) to link against the sysprop_library. // To do that, we create a public stub and expose it to modules with sdk_version: system_*. + var publicStub string if isOwnerPlatform && installedInSystem { - m.properties.Public_stub = proptools.BoolPtr(true) + publicStub = m.javaPublicStubName() + } + + ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ + Name: proptools.StringPtr(m.BaseModuleName()), + Srcs: []string{":" + m.javaGenModuleName()}, + Soc_specific: proptools.BoolPtr(ctx.SocSpecific()), + Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()), + Product_specific: proptools.BoolPtr(ctx.ProductSpecific()), + Installable: m.properties.Installable, + Sdk_version: proptools.StringPtr("core_current"), + Libs: []string{javaSyspropStub}, + SyspropPublicStub: publicStub, + }) + + if publicStub != "" { ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{ - Srcs: m.properties.Srcs, - Scope: "public", - Name: proptools.StringPtr(m.javaGenPublicStubName()), + Srcs: m.properties.Srcs, + Scope: "public", + Name: proptools.StringPtr(m.javaGenPublicStubName()), + Check_api: proptools.StringPtr(ctx.ModuleName()), }) ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ - Name: proptools.StringPtr(m.JavaPublicStubName()), + Name: proptools.StringPtr(publicStub), Srcs: []string{":" + m.javaGenPublicStubName()}, Installable: proptools.BoolPtr(false), Sdk_version: proptools.StringPtr("core_current"), @@ -537,15 +538,3 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) { *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName()) } } - -// syspropDepsMutator adds dependencies from java implementation library to sysprop library. -// java implementation library then depends on check API rule of sysprop library. -func syspropDepsMutator(ctx android.BottomUpMutatorContext) { - if m, ok := ctx.Module().(*syspropLibrary); ok { - ctx.AddReverseDependency(m, nil, m.javaGenModuleName()) - - if proptools.Bool(m.properties.Public_stub) { - ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName()) - } - } -} diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go index 5cb9e64ee..9d914e317 100644 --- a/sysprop/sysprop_test.go +++ b/sysprop/sysprop_test.go @@ -26,7 +26,6 @@ import ( "strings" "testing" - "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -61,16 +60,10 @@ func testContext(config android.Config) *android.TestContext { java.RegisterRequiredBuildComponentsForTest(ctx) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) - ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel() - }) android.RegisterPrebuiltMutators(ctx) cc.RegisterRequiredBuildComponentsForTest(ctx) - ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("sysprop_java", java.SyspropMutator).Parallel() - }) ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory) @@ -392,15 +385,9 @@ func TestSyspropLibrary(t *testing.T) { } // Java modules linking against system API should use public stub - javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common") - publicStubFound := false - ctx.VisitDirectDeps(javaSystemApiClient.Module(), func(dep blueprint.Module) { - if dep.Name() == "sysprop-platform_public" { - publicStubFound = true - } - }) - if !publicStubFound { - t.Errorf("system api client should use public stub") + javaSystemApiClient := ctx.ModuleForTests("java-platform", "android_common").Rule("javac") + syspropPlatformPublic := ctx.ModuleForTests("sysprop-platform_public", "android_common").Description("for turbine") + if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) { + t.Errorf("system api client should use public stub %q, got %q", w, g) } - } |
