diff options
56 files changed, 1033 insertions, 526 deletions
diff --git a/Android.bp b/Android.bp index 72592554b..0ca11d338 100644 --- a/Android.bp +++ b/Android.bp @@ -51,6 +51,7 @@ bootstrap_go_package { "android/expand.go", "android/filegroup.go", "android/hooks.go", + "android/image.go", "android/makevars.go", "android/module.go", "android/mutator.go", diff --git a/android/androidmk_test.go b/android/androidmk_test.go index 0bb455bb3..940e32418 100644 --- a/android/androidmk_test.go +++ b/android/androidmk_test.go @@ -47,8 +47,8 @@ func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testin config.inMake = true // Enable androidmk Singleton ctx := NewTestContext() - ctx.RegisterSingletonType("androidmk", SingletonFactoryAdaptor(AndroidMkSingleton)) - ctx.RegisterModuleType("custom", ModuleFactoryAdaptor(customModuleFactory)) + ctx.RegisterSingletonType("androidmk", AndroidMkSingleton) + ctx.RegisterModuleType("custom", customModuleFactory) ctx.Register() bp := ` diff --git a/android/apex.go b/android/apex.go index 5118a0abb..44387cd59 100644 --- a/android/apex.go +++ b/android/apex.go @@ -17,8 +17,6 @@ package android import ( "sort" "sync" - - "github.com/google/blueprint" ) // ApexModule is the interface that a module type is expected to implement if @@ -69,7 +67,7 @@ type ApexModule interface { // Mutate this module into one or more variants each of which is built // for an APEX marked via BuildForApex(). - CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module + CreateApexVariations(mctx BottomUpMutatorContext) []Module // Sets the name of the apex variant of this module. Called inside // CreateApexVariations. @@ -176,7 +174,7 @@ func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) { } } -func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module { +func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Module { if len(m.apexVariations) > 0 { m.checkApexAvailableProperty(mctx) sort.Strings(m.apexVariations) diff --git a/android/arch_test.go b/android/arch_test.go index 52a66847e..b41e1ab95 100644 --- a/android/arch_test.go +++ b/android/arch_test.go @@ -338,7 +338,7 @@ func TestArchMutator(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { ctx := NewTestArchContext() - ctx.RegisterModuleType("module", ModuleFactoryAdaptor(archTestModuleFactory)) + ctx.RegisterModuleType("module", archTestModuleFactory) ctx.MockFileSystem(mockFS) ctx.Register() config := TestArchConfig(buildDir, nil) diff --git a/android/csuite_config_test.go b/android/csuite_config_test.go index e534bb71c..5f86bbbfe 100644 --- a/android/csuite_config_test.go +++ b/android/csuite_config_test.go @@ -22,7 +22,7 @@ func testCSuiteConfig(test *testing.T, bpFileContents string) *TestContext { config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("csuite_config", ModuleFactoryAdaptor(CSuiteConfigFactory)) + ctx.RegisterModuleType("csuite_config", CSuiteConfigFactory) ctx.Register() mockFiles := map[string][]byte{ "Android.bp": []byte(bpFileContents), diff --git a/android/defaults_test.go b/android/defaults_test.go index fa2659563..80980f78b 100644 --- a/android/defaults_test.go +++ b/android/defaults_test.go @@ -64,8 +64,8 @@ func TestDefaultsAllowMissingDependencies(t *testing.T) { ctx := NewTestContext() ctx.SetAllowMissingDependencies(true) - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(defaultsTestModuleFactory)) - ctx.RegisterModuleType("defaults", ModuleFactoryAdaptor(defaultsTestDefaultsFactory)) + ctx.RegisterModuleType("test", defaultsTestModuleFactory) + ctx.RegisterModuleType("defaults", defaultsTestDefaultsFactory) ctx.PreArchMutators(RegisterDefaultsPreArchMutators) diff --git a/android/image.go b/android/image.go new file mode 100644 index 000000000..5ec1b16f5 --- /dev/null +++ b/android/image.go @@ -0,0 +1,83 @@ +// Copyright 2019 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package android + +// ImageInterface is implemented by modules that need to be split by the ImageMutator. +type ImageInterface interface { + // ImageMutatorBegin is called before any other method in the ImageInterface. + ImageMutatorBegin(ctx BaseModuleContext) + + // CoreVariantNeeded should return true if the module needs a core variant (installed on the system image). + CoreVariantNeeded(ctx BaseModuleContext) bool + + // RecoveryVariantNeeded should return true if the module needs a recovery variant (installed on the + // recovery partition). + RecoveryVariantNeeded(ctx BaseModuleContext) bool + + // ExtraImageVariations should return a list of the additional variations needed for the module. After the + // variants are created the SetImageVariation method will be called on each newly created variant with the + // its variation. + ExtraImageVariations(ctx BaseModuleContext) []string + + // SetImageVariation will be passed a newly created recovery variant of the module. ModuleBase implements + // SetImageVariation, most module types will not need to override it, and those that do must call the + // overridden method. Implementors of SetImageVariation must be careful to modify the module argument + // and not the receiver. + SetImageVariation(ctx BaseModuleContext, variation string, module Module) +} + +const ( + // CoreVariation is the variant used for framework-private libraries, or + // SDK libraries. (which framework-private libraries can use), which + // will be installed to the system image. + CoreVariation string = "core" + + // RecoveryVariation means a module to be installed to recovery image. + RecoveryVariation string = "recovery" +) + +// ImageMutator creates variants for modules that implement the ImageInterface that +// allow them to build differently for each partition (recovery, core, vendor, etc.). +func ImageMutator(ctx BottomUpMutatorContext) { + if ctx.Os() != Android { + return + } + + if m, ok := ctx.Module().(ImageInterface); ok { + m.ImageMutatorBegin(ctx) + + var variations []string + + if m.CoreVariantNeeded(ctx) { + variations = append(variations, CoreVariation) + } + if m.RecoveryVariantNeeded(ctx) { + variations = append(variations, RecoveryVariation) + } + + extraVariations := m.ExtraImageVariations(ctx) + variations = append(variations, extraVariations...) + + if len(variations) == 0 { + return + } + + mod := ctx.CreateVariations(variations...) + for i, v := range variations { + mod[i].base().setImageVariation(v) + m.SetImageVariation(ctx, v, mod[i]) + } + } +} diff --git a/android/makevars.go b/android/makevars.go index c011ea61f..38a028caf 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -80,6 +80,12 @@ type MakeVarsContext interface { // Eval(). StrictRaw(name, value string) CheckRaw(name, value string) + + // GlobWithDeps returns a list of files that match the specified pattern but do not match any + // of the patterns in excludes. It also adds efficient dependencies to rerun the primary + // builder whenever a file matching the pattern as added or removed, without rerunning if a + // file that does not match the pattern is added to a searched directory. + GlobWithDeps(pattern string, excludes []string) ([]string, error) } var _ PathContext = MakeVarsContext(nil) diff --git a/android/module.go b/android/module.go index 891babc32..5b2f9d39c 100644 --- a/android/module.go +++ b/android/module.go @@ -431,6 +431,9 @@ type commonProperties struct { DebugName string `blueprint:"mutated"` DebugMutators []string `blueprint:"mutated"` DebugVariations []string `blueprint:"mutated"` + + // set by ImageMutator + ImageVariation string `blueprint:"mutated"` } type hostAndDeviceProperties struct { @@ -865,6 +868,21 @@ func (m *ModuleBase) NoticeFile() OptionalPath { return m.noticeFile } +func (m *ModuleBase) setImageVariation(variant string) { + m.commonProperties.ImageVariation = variant +} + +func (m *ModuleBase) ImageVariation() blueprint.Variation { + return blueprint.Variation{ + Mutator: "image", + Variation: m.base().commonProperties.ImageVariation, + } +} + +func (m *ModuleBase) InRecovery() bool { + return m.base().commonProperties.ImageVariation == RecoveryVariation +} + func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) { allInstalledFiles := Paths{} allCheckbuildFiles := Paths{} diff --git a/android/module_test.go b/android/module_test.go index 6dca29f79..fef1766a3 100644 --- a/android/module_test.go +++ b/android/module_test.go @@ -165,7 +165,7 @@ func depsModuleFactory() Module { func TestErrorDependsOnDisabledModule(t *testing.T) { ctx := NewTestContext() - ctx.RegisterModuleType("deps", ModuleFactoryAdaptor(depsModuleFactory)) + ctx.RegisterModuleType("deps", depsModuleFactory) bp := ` deps { diff --git a/android/mutator.go b/android/mutator.go index df68726d2..0d253eb5c 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -143,8 +143,8 @@ type BottomUpMutatorContext interface { AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) - CreateVariations(...string) []blueprint.Module - CreateLocalVariations(...string) []blueprint.Module + CreateVariations(...string) []Module + CreateLocalVariations(...string) []Module SetDependencyVariation(string) SetDefaultDependencyVariation(*string) AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) @@ -285,28 +285,32 @@ func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, t b.bp.AddReverseDependency(module, tag, name) } -func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []blueprint.Module { +func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module { modules := b.bp.CreateVariations(variations...) + aModules := make([]Module, len(modules)) for i := range variations { - base := modules[i].(Module).base() + aModules[i] = modules[i].(Module) + base := aModules[i].base() base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) } - return modules + return aModules } -func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []blueprint.Module { +func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module { modules := b.bp.CreateLocalVariations(variations...) + aModules := make([]Module, len(modules)) for i := range variations { - base := modules[i].(Module).base() + aModules[i] = modules[i].(Module) + base := aModules[i].base() base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) } - return modules + return aModules } func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) { diff --git a/android/mutator_test.go b/android/mutator_test.go index 0b23434af..2350fdb0a 100644 --- a/android/mutator_test.go +++ b/android/mutator_test.go @@ -62,7 +62,7 @@ func TestMutatorAddMissingDependencies(t *testing.T) { ctx := NewTestContext() ctx.SetAllowMissingDependencies(true) - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(mutatorTestModuleFactory)) + ctx.RegisterModuleType("test", mutatorTestModuleFactory) ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { ctx.TopDown("add_missing_dependencies", addMissingDependenciesMutator) }) @@ -131,7 +131,7 @@ func TestModuleString(t *testing.T) { }) }) - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(mutatorTestModuleFactory)) + ctx.RegisterModuleType("test", mutatorTestModuleFactory) bp := ` test { diff --git a/android/namespace_test.go b/android/namespace_test.go index 20241fe1b..90058e3f5 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -637,9 +637,9 @@ func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) ctx = NewTestContext() ctx.MockFileSystem(bps) - ctx.RegisterModuleType("test_module", ModuleFactoryAdaptor(newTestModule)) - ctx.RegisterModuleType("soong_namespace", ModuleFactoryAdaptor(NamespaceFactory)) - ctx.RegisterModuleType("blueprint_test_module", newBlueprintTestModule) + ctx.RegisterModuleType("test_module", newTestModule) + ctx.RegisterModuleType("soong_namespace", NamespaceFactory) + ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule) ctx.PreArchMutators(RegisterNamespaceMutator) ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { ctx.BottomUp("rename", renameMutator) diff --git a/android/neverallow_test.go b/android/neverallow_test.go index b75b5b788..bd94e376c 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -269,10 +269,10 @@ func TestNeverallow(t *testing.T) { func testNeverallow(config Config, fs map[string][]byte) (*TestContext, []error) { ctx := NewTestContext() - ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule)) - ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule)) - ctx.RegisterModuleType("java_library_host", ModuleFactoryAdaptor(newMockJavaLibraryModule)) - ctx.RegisterModuleType("java_device_for_host", ModuleFactoryAdaptor(newMockJavaLibraryModule)) + ctx.RegisterModuleType("cc_library", newMockCcLibraryModule) + ctx.RegisterModuleType("java_library", newMockJavaLibraryModule) + ctx.RegisterModuleType("java_library_host", newMockJavaLibraryModule) + ctx.RegisterModuleType("java_device_for_host", newMockJavaLibraryModule) ctx.PostDepsMutators(registerNeverallowMutator) ctx.Register() diff --git a/android/package_test.go b/android/package_test.go index e5b055667..ae286d662 100644 --- a/android/package_test.go +++ b/android/package_test.go @@ -87,7 +87,7 @@ func testPackage(fs map[string][]byte) (*TestContext, []error) { config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("package", ModuleFactoryAdaptor(PackageFactory)) + ctx.RegisterModuleType("package", PackageFactory) ctx.PreArchMutators(registerPackageRenamer) ctx.Register() diff --git a/android/path_properties_test.go b/android/path_properties_test.go index 59bfa6c21..c859bc530 100644 --- a/android/path_properties_test.go +++ b/android/path_properties_test.go @@ -100,8 +100,8 @@ func TestPathDepsMutator(t *testing.T) { config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(pathDepsMutatorTestModuleFactory)) - ctx.RegisterModuleType("filegroup", ModuleFactoryAdaptor(FileGroupFactory)) + ctx.RegisterModuleType("test", pathDepsMutatorTestModuleFactory) + ctx.RegisterModuleType("filegroup", FileGroupFactory) bp := test.bp + ` filegroup { diff --git a/android/paths_test.go b/android/paths_test.go index 2e67272e0..1d8afa9c1 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -865,9 +865,9 @@ func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSr config := TestConfig(buildDir, nil) ctx := NewTestContext() - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(pathForModuleSrcTestModuleFactory)) - ctx.RegisterModuleType("output_file_provider", ModuleFactoryAdaptor(pathForModuleSrcOutputFileProviderModuleFactory)) - ctx.RegisterModuleType("filegroup", ModuleFactoryAdaptor(FileGroupFactory)) + ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) + ctx.RegisterModuleType("output_file_provider", pathForModuleSrcOutputFileProviderModuleFactory) + ctx.RegisterModuleType("filegroup", FileGroupFactory) fgBp := ` filegroup { @@ -1079,7 +1079,7 @@ func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) { ctx := NewTestContext() ctx.SetAllowMissingDependencies(true) - ctx.RegisterModuleType("test", ModuleFactoryAdaptor(pathForModuleSrcTestModuleFactory)) + ctx.RegisterModuleType("test", pathForModuleSrcTestModuleFactory) bp := ` test { diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go index 6c8037051..270118584 100644 --- a/android/prebuilt_etc.go +++ b/android/prebuilt_etc.go @@ -25,10 +25,6 @@ func init() { RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory) RegisterModuleType("prebuilt_font", PrebuiltFontFactory) RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) - - PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel() - }) } type prebuiltEtcProperties struct { @@ -48,8 +44,6 @@ type prebuiltEtcProperties struct { // Make this module available when building for recovery. Recovery_available *bool - InRecovery bool `blueprint:"mutated"` - // Whether this module is directly installable to one of the partitions. Default: true. Installable *bool } @@ -76,7 +70,7 @@ type PrebuiltEtc struct { } func (p *PrebuiltEtc) inRecovery() bool { - return p.properties.InRecovery || p.ModuleBase.InstallInRecovery() + return p.ModuleBase.InRecovery() || p.ModuleBase.InstallInRecovery() } func (p *PrebuiltEtc) onlyInRecovery() bool { @@ -87,6 +81,25 @@ func (p *PrebuiltEtc) InstallInRecovery() bool { return p.inRecovery() } +var _ ImageInterface = (*PrebuiltEtc)(nil) + +func (p *PrebuiltEtc) ImageMutatorBegin(ctx BaseModuleContext) {} + +func (p *PrebuiltEtc) CoreVariantNeeded(ctx BaseModuleContext) bool { + return !p.ModuleBase.InstallInRecovery() +} + +func (p *PrebuiltEtc) RecoveryVariantNeeded(ctx BaseModuleContext) bool { + return Bool(p.properties.Recovery_available) || p.ModuleBase.InstallInRecovery() +} + +func (p *PrebuiltEtc) ExtraImageVariations(ctx BaseModuleContext) []string { + return nil +} + +func (p *PrebuiltEtc) SetImageVariation(ctx BaseModuleContext, variation string, module Module) { +} + func (p *PrebuiltEtc) DepsMutator(ctx BottomUpMutatorContext) { if p.properties.Src == nil { ctx.PropertyErrorf("src", "missing prebuilt source file") @@ -222,49 +235,6 @@ func PrebuiltUserShareHostFactory() Module { return module } -const ( - // coreMode is the variant for modules to be installed to system. - coreMode = "core" - - // recoveryMode means a module to be installed to recovery image. - recoveryMode = "recovery" -) - -// prebuiltEtcMutator creates the needed variants to install the module to -// system or recovery. -func prebuiltEtcMutator(mctx BottomUpMutatorContext) { - m, ok := mctx.Module().(*PrebuiltEtc) - if !ok || m.Host() { - return - } - - var coreVariantNeeded bool = true - var recoveryVariantNeeded bool = false - if Bool(m.properties.Recovery_available) { - recoveryVariantNeeded = true - } - - if m.ModuleBase.InstallInRecovery() { - recoveryVariantNeeded = true - coreVariantNeeded = false - } - - var variants []string - if coreVariantNeeded { - variants = append(variants, coreMode) - } - if recoveryVariantNeeded { - variants = append(variants, recoveryMode) - } - mod := mctx.CreateVariations(variants...) - for i, v := range variants { - if v == recoveryMode { - m := mod[i].(*PrebuiltEtc) - m.properties.InRecovery = true - } - } -} - // prebuilt_font installs a font in <partition>/fonts directory. func PrebuiltFontFactory() Module { module := &PrebuiltEtc{} diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go index f675ea3c3..3855dac8f 100644 --- a/android/prebuilt_etc_test.go +++ b/android/prebuilt_etc_test.go @@ -23,14 +23,14 @@ import ( func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) { config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("prebuilt_etc", ModuleFactoryAdaptor(PrebuiltEtcFactory)) - ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory)) - ctx.RegisterModuleType("prebuilt_usr_share", ModuleFactoryAdaptor(PrebuiltUserShareFactory)) - ctx.RegisterModuleType("prebuilt_usr_share_host", ModuleFactoryAdaptor(PrebuiltUserShareHostFactory)) - ctx.RegisterModuleType("prebuilt_font", ModuleFactoryAdaptor(PrebuiltFontFactory)) - ctx.RegisterModuleType("prebuilt_firmware", ModuleFactoryAdaptor(PrebuiltFirmwareFactory)) + ctx.RegisterModuleType("prebuilt_etc", PrebuiltEtcFactory) + ctx.RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory) + ctx.RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory) + ctx.RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory) + ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory) + ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { - ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel() + ctx.BottomUp("prebuilt_etc", ImageMutator).Parallel() }) ctx.Register() mockFiles := map[string][]byte{ diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go index 0a18e2c90..81fb2783f 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -132,9 +132,9 @@ func TestPrebuilts(t *testing.T) { ctx := NewTestContext() ctx.PreArchMutators(RegisterPrebuiltsPreArchMutators) ctx.PostDepsMutators(RegisterPrebuiltsPostDepsMutators) - ctx.RegisterModuleType("filegroup", ModuleFactoryAdaptor(FileGroupFactory)) - ctx.RegisterModuleType("prebuilt", ModuleFactoryAdaptor(newPrebuiltModule)) - ctx.RegisterModuleType("source", ModuleFactoryAdaptor(newSourceModule)) + ctx.RegisterModuleType("filegroup", FileGroupFactory) + ctx.RegisterModuleType("prebuilt", newPrebuiltModule) + ctx.RegisterModuleType("source", newSourceModule) ctx.Register() ctx.MockFileSystem(map[string][]byte{ "prebuilt_file": nil, diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go index b4848112a..52c32df5c 100644 --- a/android/rule_builder_test.go +++ b/android/rule_builder_test.go @@ -465,8 +465,8 @@ func TestRuleBuilder_Build(t *testing.T) { "bar": nil, "cp": nil, }) - ctx.RegisterModuleType("rule_builder_test", ModuleFactoryAdaptor(testRuleBuilderFactory)) - ctx.RegisterSingletonType("rule_builder_test", SingletonFactoryAdaptor(testRuleBuilderSingletonFactory)) + ctx.RegisterModuleType("rule_builder_test", testRuleBuilderFactory) + ctx.RegisterSingletonType("rule_builder_test", testRuleBuilderSingletonFactory) ctx.Register() _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) diff --git a/android/sdk.go b/android/sdk.go index d66816dc8..73cb2565f 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -164,6 +164,9 @@ type SnapshotBuilder interface { // to the zip CopyToSnapshot(src Path, dest string) + // Unzip the supplied zip into the snapshot relative directory destDir. + UnzipToSnapshot(zipPath Path, destDir string) + // Get the AndroidBpFile for the snapshot. AndroidBpFile() GeneratedSnapshotFile diff --git a/android/sh_binary_test.go b/android/sh_binary_test.go index 9df769ca2..a13875414 100644 --- a/android/sh_binary_test.go +++ b/android/sh_binary_test.go @@ -9,8 +9,8 @@ func testShBinary(t *testing.T, bp string) (*TestContext, Config) { config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("sh_test", ModuleFactoryAdaptor(ShTestFactory)) - ctx.RegisterModuleType("sh_test_host", ModuleFactoryAdaptor(ShTestHostFactory)) + ctx.RegisterModuleType("sh_test", ShTestFactory) + ctx.RegisterModuleType("sh_test_host", ShTestHostFactory) ctx.Register() mockFiles := map[string][]byte{ "Android.bp": []byte(bp), diff --git a/android/testing.go b/android/testing.go index 447ffd6d4..4b55920c5 100644 --- a/android/testing.go +++ b/android/testing.go @@ -71,7 +71,15 @@ func (ctx *TestContext) PostDepsMutators(f RegisterMutatorFunc) { func (ctx *TestContext) Register() { registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps) - ctx.RegisterSingletonType("env", SingletonFactoryAdaptor(EnvSingleton)) + ctx.RegisterSingletonType("env", EnvSingleton) +} + +func (ctx *TestContext) RegisterModuleType(name string, factory ModuleFactory) { + ctx.Context.RegisterModuleType(name, ModuleFactoryAdaptor(factory)) +} + +func (ctx *TestContext) RegisterSingletonType(name string, factory SingletonFactory) { + ctx.Context.RegisterSingletonType(name, SingletonFactoryAdaptor(factory)) } func (ctx *TestContext) ModuleForTests(name, variant string) TestingModule { diff --git a/android/variable_test.go b/android/variable_test.go index c1910fe03..1826e3901 100644 --- a/android/variable_test.go +++ b/android/variable_test.go @@ -159,17 +159,17 @@ func testProductVariableModuleFactoryFactory(props interface{}) func() Module { func TestProductVariables(t *testing.T) { ctx := NewTestContext() // A module type that has a srcs property but not a cflags property. - ctx.RegisterModuleType("module1", ModuleFactoryAdaptor(testProductVariableModuleFactoryFactory(struct { + ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(struct { Srcs []string - }{}))) + }{})) // A module type that has a cflags property but not a srcs property. - ctx.RegisterModuleType("module2", ModuleFactoryAdaptor(testProductVariableModuleFactoryFactory(struct { + ctx.RegisterModuleType("module2", testProductVariableModuleFactoryFactory(struct { Cflags []string - }{}))) + }{})) // A module type that does not have any properties that match product_variables. - ctx.RegisterModuleType("module3", ModuleFactoryAdaptor(testProductVariableModuleFactoryFactory(struct { + ctx.RegisterModuleType("module3", testProductVariableModuleFactoryFactory(struct { Foo []string - }{}))) + }{})) ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { ctx.BottomUp("variable", variableMutator).Parallel() }) diff --git a/android/visibility_test.go b/android/visibility_test.go index d13fadf6a..fd9e98c55 100644 --- a/android/visibility_test.go +++ b/android/visibility_test.go @@ -871,9 +871,9 @@ func testVisibility(buildDir string, fs map[string][]byte) (*TestContext, []erro config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("package", ModuleFactoryAdaptor(PackageFactory)) - ctx.RegisterModuleType("mock_library", ModuleFactoryAdaptor(newMockLibraryModule)) - ctx.RegisterModuleType("mock_defaults", ModuleFactoryAdaptor(defaultsFactory)) + ctx.RegisterModuleType("package", PackageFactory) + ctx.RegisterModuleType("mock_library", newMockLibraryModule) + ctx.RegisterModuleType("mock_defaults", defaultsFactory) ctx.PreArchMutators(registerPackageRenamer) ctx.PreArchMutators(registerVisibilityRuleChecker) ctx.PreArchMutators(RegisterDefaultsPreArchMutators) diff --git a/android/vts_config_test.go b/android/vts_config_test.go index 142b2f591..162944d07 100644 --- a/android/vts_config_test.go +++ b/android/vts_config_test.go @@ -22,7 +22,7 @@ func testVtsConfig(test *testing.T, bpFileContents string) *TestContext { config := TestArchConfig(buildDir, nil) ctx := NewTestArchContext() - ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory)) + ctx.RegisterModuleType("vts_config", VtsConfigFactory) ctx.Register() mockFiles := map[string][]byte{ "Android.bp": []byte(bpFileContents), diff --git a/apex/apex.go b/apex/apex.go index 4dfbdb4fa..4c5e06b8f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -16,6 +16,7 @@ package apex import ( "fmt" + "path" "path/filepath" "sort" "strings" @@ -118,16 +119,11 @@ func apexDepsMutator(mctx android.BottomUpMutatorContext) { func apexMutator(mctx android.BottomUpMutatorContext) { if am, ok := mctx.Module().(android.ApexModule); ok && am.CanHaveApexVariants() { am.CreateApexVariations(mctx) - } else if a, ok := mctx.Module().(*apexBundle); ok { + } else if _, ok := mctx.Module().(*apexBundle); ok { // apex bundle itself is mutated so that it and its modules have same // apex variant. apexBundleName := mctx.ModuleName() mctx.CreateVariations(apexBundleName) - - // collects APEX list - if mctx.Device() && a.installable() { - addApexFileContextsInfos(mctx, a) - } } else if o, ok := mctx.Module().(*OverrideApex); ok { apexBundleName := o.GetOverriddenModuleName() if apexBundleName == "" { @@ -150,14 +146,11 @@ func apexFileContextsInfos(config android.Config) *[]string { }).(*[]string) } -func addApexFileContextsInfos(ctx android.BaseModuleContext, a *apexBundle) { - apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) - fileContextsName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) - +func addFlattenedFileContextsInfos(ctx android.BaseModuleContext, fileContextsInfo string) { apexFileContextsInfosMutex.Lock() defer apexFileContextsInfosMutex.Unlock() apexFileContextsInfos := apexFileContextsInfos(ctx.Config()) - *apexFileContextsInfos = append(*apexFileContextsInfos, apexName+":"+fileContextsName) + *apexFileContextsInfos = append(*apexFileContextsInfos, fileContextsInfo) } func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { @@ -272,10 +265,9 @@ type apexBundleProperties struct { Apex_name *string // Determines the file contexts file for setting security context to each file in this APEX bundle. - // Specifically, when this is set to <value>, /system/sepolicy/apex/<value>_file_contexts file is - // used. - // Default: <name_of_this_module> - File_contexts *string + // For platform APEXes, this should points to a file under /system/sepolicy + // Default: /system/sepolicy/apex/<module_name>_file_contexts. + File_contexts *string `android:"path"` // List of native shared libs that are embedded inside this APEX bundle Native_shared_libs []string @@ -481,6 +473,8 @@ type apexBundle struct { container_certificate_file android.Path container_private_key_file android.Path + fileContexts android.Path + // list of files to be included in this apex filesInfo []apexFile @@ -722,12 +716,12 @@ func (a *apexBundle) installable() bool { func (a *apexBundle) getImageVariation(config android.DeviceConfig) string { if a.vndkApex { - return "vendor." + a.vndkVersion(config) + return cc.VendorVariationPrefix + a.vndkVersion(config) } if config.VndkVersion() != "" && proptools.Bool(a.properties.Use_vendor) { - return "vendor." + config.PlatformVndkVersion() + return cc.VendorVariationPrefix + config.PlatformVndkVersion() } else { - return "core" + return android.CoreVariation } } @@ -1168,12 +1162,29 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // prepend the name of this APEX to the module names. These names will be the names of // modules that will be defined if the APEX is flattened. for i := range filesInfo { - filesInfo[i].moduleName = filesInfo[i].moduleName + "." + ctx.ModuleName() + a.suffix + filesInfo[i].moduleName = filesInfo[i].moduleName + "." + a.Name() + a.suffix } a.installDir = android.PathForModuleInstall(ctx, "apex") a.filesInfo = filesInfo + if a.properties.ApexType != zipApex { + if a.properties.File_contexts == nil { + a.fileContexts = android.PathForSource(ctx, "system/sepolicy/apex", ctx.ModuleName()+"-file_contexts") + } else { + a.fileContexts = android.PathForModuleSrc(ctx, *a.properties.File_contexts) + if a.Platform() { + if matched, err := path.Match("system/sepolicy/**/*", a.fileContexts.String()); err != nil || !matched { + ctx.PropertyErrorf("file_contexts", "should be under system/sepolicy, but %q", a.fileContexts) + } + } + } + if !android.ExistentPathForSource(ctx, a.fileContexts.String()).Valid() { + ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", a.fileContexts) + return + } + } + // prepare apex_manifest.json a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) @@ -1184,7 +1195,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.buildUnflattenedApex(ctx) } - apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) + apexName := proptools.StringDefault(a.properties.Apex_name, a.Name()) a.compatSymlinks = makeCompatSymlinks(apexName, ctx) } diff --git a/apex/apex_test.go b/apex/apex_test.go index f4b8e35fe..51cb74e08 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -101,46 +101,46 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") ctx := android.NewTestArchContext() - ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(BundleFactory)) - ctx.RegisterModuleType("apex_test", android.ModuleFactoryAdaptor(testApexBundleFactory)) - ctx.RegisterModuleType("apex_vndk", android.ModuleFactoryAdaptor(vndkApexBundleFactory)) - ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(ApexKeyFactory)) - ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) - ctx.RegisterModuleType("prebuilt_apex", android.ModuleFactoryAdaptor(PrebuiltFactory)) - ctx.RegisterModuleType("override_apex", android.ModuleFactoryAdaptor(overrideApexFactory)) - - ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) - ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) - ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory)) - ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory)) - ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory)) - ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory)) - ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) - ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(func() android.Module { + ctx.RegisterModuleType("apex", BundleFactory) + ctx.RegisterModuleType("apex_test", testApexBundleFactory) + ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory) + ctx.RegisterModuleType("apex_key", ApexKeyFactory) + ctx.RegisterModuleType("apex_defaults", defaultsFactory) + ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) + ctx.RegisterModuleType("override_apex", overrideApexFactory) + + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) + ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory) + ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) + ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) + ctx.RegisterModuleType("cc_binary", cc.BinaryFactory) + ctx.RegisterModuleType("cc_object", cc.ObjectFactory) + ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() - })) - ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory)) - ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) - ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory)) - ctx.RegisterModuleType("vndk_libraries_txt", android.ModuleFactoryAdaptor(cc.VndkLibrariesTxtFactory)) - ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) - ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) - ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory)) - ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory)) - ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) - ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) - ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory)) - ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory)) - ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory)) - ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(java.AndroidAppImportFactory)) - ctx.RegisterModuleType("override_android_app", android.ModuleFactoryAdaptor(java.OverrideAndroidAppModuleFactory)) + }) + ctx.RegisterModuleType("cc_test", cc.TestFactory) + ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory) + ctx.RegisterModuleType("vndk_prebuilt_shared", cc.VndkPrebuiltSharedFactory) + ctx.RegisterModuleType("vndk_libraries_txt", cc.VndkLibrariesTxtFactory) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) + ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory) + ctx.RegisterModuleType("sh_binary", android.ShBinaryFactory) + ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) + ctx.RegisterModuleType("java_library", java.LibraryFactory) + ctx.RegisterModuleType("java_import", java.ImportFactory) + ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory) + ctx.RegisterModuleType("android_app", java.AndroidAppFactory) + ctx.RegisterModuleType("android_app_import", java.AndroidAppImportFactory) + ctx.RegisterModuleType("override_android_app", java.OverrideAndroidAppModuleFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel() }) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("image", cc.ImageMutator).Parallel() + ctx.BottomUp("image", android.ImageMutator).Parallel() ctx.BottomUp("link", cc.LinkageMutator).Parallel() ctx.BottomUp("vndk", cc.VndkMutator).Parallel() ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel() @@ -263,50 +263,57 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr symbol_file: "", native_bridge_supported: true, } + + filegroup { + name: "myapex-file_contexts", + srcs: [ + "system/sepolicy/apex/myapex-file_contexts", + ], + } ` bp = bp + java.GatherRequiredDepsForTest() fs := map[string][]byte{ - "Android.bp": []byte(bp), - "a.java": nil, - "PrebuiltAppFoo.apk": nil, - "PrebuiltAppFooPriv.apk": nil, - "build/make/target/product/security": nil, - "apex_manifest.json": nil, - "AndroidManifest.xml": nil, - "system/sepolicy/apex/myapex-file_contexts": nil, - "system/sepolicy/apex/myapex_keytest-file_contexts": nil, - "system/sepolicy/apex/otherapex-file_contexts": nil, - "system/sepolicy/apex/commonapex-file_contexts": nil, - "mylib.cpp": nil, - "mylib_common.cpp": nil, - "mytest.cpp": nil, - "mytest1.cpp": nil, - "mytest2.cpp": nil, - "mytest3.cpp": nil, - "myprebuilt": nil, - "my_include": nil, - "foo/bar/MyClass.java": nil, - "prebuilt.jar": nil, - "vendor/foo/devkeys/test.x509.pem": nil, - "vendor/foo/devkeys/test.pk8": nil, - "testkey.x509.pem": nil, - "testkey.pk8": nil, - "testkey.override.x509.pem": nil, - "testkey.override.pk8": nil, - "vendor/foo/devkeys/testkey.avbpubkey": nil, - "vendor/foo/devkeys/testkey.pem": nil, - "NOTICE": nil, - "custom_notice": nil, - "testkey2.avbpubkey": nil, - "testkey2.pem": nil, - "myapex-arm64.apex": nil, - "myapex-arm.apex": nil, - "frameworks/base/api/current.txt": nil, - "framework/aidl/a.aidl": nil, - "build/make/core/proguard.flags": nil, - "build/make/core/proguard_basic_keeps.flags": nil, - "dummy.txt": nil, + "Android.bp": []byte(bp), + "a.java": nil, + "PrebuiltAppFoo.apk": nil, + "PrebuiltAppFooPriv.apk": nil, + "build/make/target/product/security": nil, + "apex_manifest.json": nil, + "AndroidManifest.xml": nil, + "system/sepolicy/apex/myapex-file_contexts": nil, + "system/sepolicy/apex/otherapex-file_contexts": nil, + "system/sepolicy/apex/commonapex-file_contexts": nil, + "system/sepolicy/apex/com.android.vndk-file_contexts": nil, + "mylib.cpp": nil, + "mylib_common.cpp": nil, + "mytest.cpp": nil, + "mytest1.cpp": nil, + "mytest2.cpp": nil, + "mytest3.cpp": nil, + "myprebuilt": nil, + "my_include": nil, + "foo/bar/MyClass.java": nil, + "prebuilt.jar": nil, + "vendor/foo/devkeys/test.x509.pem": nil, + "vendor/foo/devkeys/test.pk8": nil, + "testkey.x509.pem": nil, + "testkey.pk8": nil, + "testkey.override.x509.pem": nil, + "testkey.override.pk8": nil, + "vendor/foo/devkeys/testkey.avbpubkey": nil, + "vendor/foo/devkeys/testkey.pem": nil, + "NOTICE": nil, + "custom_notice": nil, + "testkey2.avbpubkey": nil, + "testkey2.pem": nil, + "myapex-arm64.apex": nil, + "myapex-arm.apex": nil, + "frameworks/base/api/current.txt": nil, + "framework/aidl/a.aidl": nil, + "build/make/core/proguard.flags": nil, + "build/make/core/proguard_basic_keeps.flags": nil, + "dummy.txt": nil, } for _, handler := range handlers { @@ -1201,6 +1208,7 @@ func TestKeys(t *testing.T) { key: "myapex.key", certificate: ":myapex.certificate", native_shared_libs: ["mylib"], + file_contexts: ":myapex-file_contexts", } cc_library { @@ -1411,7 +1419,6 @@ func TestVndkApexCurrent(t *testing.T) { apex_vndk { name: "myapex", key: "myapex.key", - file_contexts: "myapex", } apex_key { @@ -1462,7 +1469,6 @@ func TestVndkApexWithPrebuilt(t *testing.T) { apex_vndk { name: "myapex", key: "myapex.key", - file_contexts: "myapex", } apex_key { @@ -1541,7 +1547,7 @@ func TestVndkApexVersion(t *testing.T) { apex_vndk { name: "myapex_v27", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", vndk_version: "27", } @@ -1606,13 +1612,13 @@ func TestVndkApexErrorWithDuplicateVersion(t *testing.T) { apex_vndk { name: "myapex_v27", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", vndk_version: "27", } apex_vndk { name: "myapex_v27_other", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", vndk_version: "27", } @@ -1652,12 +1658,12 @@ func TestVndkApexNameRule(t *testing.T) { apex_vndk { name: "myapex", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", } apex_vndk { name: "myapex_v28", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", vndk_version: "28", } apex_key { @@ -1683,7 +1689,7 @@ func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { apex_vndk { name: "myapex", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", } apex_key { @@ -1726,7 +1732,7 @@ func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { apex_vndk { name: "myapex", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", native_bridge_supported: true, } @@ -1756,7 +1762,7 @@ func TestVndkApexWithBinder32(t *testing.T) { apex_vndk { name: "myapex_v27", key: "myapex.key", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", vndk_version: "27", } @@ -1822,7 +1828,7 @@ func TestDependenciesInApexManifest(t *testing.T) { key: "myapex.key", native_shared_libs: ["lib_nodep"], compile_multilib: "both", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", } apex { @@ -1830,7 +1836,7 @@ func TestDependenciesInApexManifest(t *testing.T) { key: "myapex.key", native_shared_libs: ["lib_dep"], compile_multilib: "both", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", } apex { @@ -1838,7 +1844,7 @@ func TestDependenciesInApexManifest(t *testing.T) { key: "myapex.key", native_shared_libs: ["libfoo"], compile_multilib: "both", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", } apex { @@ -1846,7 +1852,7 @@ func TestDependenciesInApexManifest(t *testing.T) { key: "myapex.key", native_shared_libs: ["lib_dep", "libfoo"], compile_multilib: "both", - file_contexts: "myapex", + file_contexts: ":myapex-file_contexts", } apex_key { @@ -2145,6 +2151,7 @@ func TestApexInProductPartition(t *testing.T) { key: "myapex.key", native_shared_libs: ["mylib"], product_specific: true, + file_contexts: "myapex_file_contexts", } apex_key { @@ -2160,7 +2167,9 @@ func TestApexInProductPartition(t *testing.T) { system_shared_libs: [], stl: "none", } - `) + `, withFiles(map[string][]byte{ + "myapex_file_contexts": nil, + })) apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) expected := buildDir + "/target/product/test_device/product/apex" @@ -2170,6 +2179,112 @@ func TestApexInProductPartition(t *testing.T) { } } +func TestFileContexts(t *testing.T) { + ctx, _ := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `) + module := ctx.ModuleForTests("myapex", "android_common_myapex_image") + apexRule := module.Rule("apexRule") + actual := apexRule.Args["file_contexts"] + expected := "system/sepolicy/apex/myapex-file_contexts" + if actual != expected { + t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) + } + + testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` + apex { + name: "myapex", + key: "myapex.key", + file_contexts: "my_own_file_contexts", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `, withFiles(map[string][]byte{ + "my_own_file_contexts": nil, + })) + + testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` + apex { + name: "myapex", + key: "myapex.key", + product_specific: true, + file_contexts: "product_specific_file_contexts", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `) + + ctx, _ = testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + product_specific: true, + file_contexts: "product_specific_file_contexts", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `, withFiles(map[string][]byte{ + "product_specific_file_contexts": nil, + })) + module = ctx.ModuleForTests("myapex", "android_common_myapex_image") + apexRule = module.Rule("apexRule") + actual = apexRule.Args["file_contexts"] + expected = "product_specific_file_contexts" + if actual != expected { + t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) + } + + ctx, _ = testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + product_specific: true, + file_contexts: ":my-file-contexts", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + filegroup { + name: "my-file-contexts", + srcs: ["product_specific_file_contexts"], + } + `, withFiles(map[string][]byte{ + "product_specific_file_contexts": nil, + })) + module = ctx.ModuleForTests("myapex", "android_common_myapex_image") + apexRule = module.Rule("apexRule") + actual = apexRule.Args["file_contexts"] + expected = "product_specific_file_contexts" + if actual != expected { + t.Errorf("wrong file_contexts. expected %q. actual %q", expected, actual) + } +} + func TestApexKeyFromOtherModule(t *testing.T) { ctx, _ := testApex(t, ` apex_key { @@ -2819,7 +2934,7 @@ func TestApexAvailable(t *testing.T) { } func TestOverrideApex(t *testing.T) { - ctx, _ := testApex(t, ` + ctx, config := testApex(t, ` apex { name: "myapex", key: "myapex.key", @@ -2859,6 +2974,23 @@ func TestOverrideApex(t *testing.T) { ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") ensureContains(t, copyCmds, "image.apex/app/app/override_app.apk") + + apexBundle := module.Module().(*apexBundle) + name := apexBundle.Name() + if name != "override_myapex" { + t.Errorf("name should be \"override_myapex\", but was %q", name) + } + + data := android.AndroidMkDataForTest(t, config, "", apexBundle) + var builder strings.Builder + data.Custom(&builder, name, "TARGET_", "", data) + androidMk := builder.String() + ensureContains(t, androidMk, "LOCAL_MODULE := app.override_myapex") + ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") + ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") + ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") + ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") + ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") } func TestMain(m *testing.M) { diff --git a/apex/builder.go b/apex/builder.go index b29bc2c78..70f3e1ad2 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -244,7 +244,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { apexType := a.properties.ApexType suffix := apexType.suffix() - unsignedOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+".unsigned") + unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned") filesToCopy := []android.Path{} for _, f := range a.filesInfo { @@ -253,7 +253,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { copyCommands := []string{} emitCommands := []string{} - imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt") + imageContentFile := android.PathForModuleOut(ctx, a.Name()+"-content.txt") emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String()) for i, src := range filesToCopy { dest := filepath.Join(a.filesInfo[i].installDir, src.Base()) @@ -284,7 +284,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { implicitInputs = append(implicitInputs, imageContentFile) whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files)) - phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output") + phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output") ctx.Build(pctx, android.BuildParams{ Rule: diffApexContentRule, Implicits: implicitInputs, @@ -293,7 +293,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { Args: map[string]string{ "whitelisted_files_file": whitelistedFilesFile.String(), "image_content_file": imageContentFile.String(), - "apex_module_name": ctx.ModuleName(), + "apex_module_name": a.Name(), }, }) @@ -340,22 +340,13 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { }, }) - fcName := proptools.StringDefault(a.properties.File_contexts, ctx.ModuleName()) - fileContextsPath := "system/sepolicy/apex/" + fcName + "-file_contexts" - fileContextsOptionalPath := android.ExistentPathForSource(ctx, fileContextsPath) - if !fileContextsOptionalPath.Valid() { - ctx.ModuleErrorf("Cannot find file_contexts file: %q", fileContextsPath) - return - } - fileContexts := fileContextsOptionalPath.Path() - optFlags := []string{} // Additional implicit inputs. - implicitInputs = append(implicitInputs, cannedFsConfig, fileContexts, a.private_key_file, a.public_key_file) + implicitInputs = append(implicitInputs, cannedFsConfig, a.fileContexts, a.private_key_file, a.public_key_file) optFlags = append(optFlags, "--pubkey "+a.public_key_file.String()) - manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) + manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(a.Name()) if overridden { optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) } @@ -377,7 +368,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { } optFlags = append(optFlags, "--target_sdk_version "+targetSdkVersion) - noticeFile := a.buildNoticeFile(ctx, ctx.ModuleName()+suffix) + noticeFile := a.buildNoticeFile(ctx, a.Name()+suffix) if noticeFile.Valid() { // If there's a NOTICE file, embed it as an asset file in the APEX. implicitInputs = append(implicitInputs, noticeFile.Path()) @@ -409,15 +400,15 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { "manifest_json_full": a.manifestJsonFullOut.String(), "manifest_json": a.manifestJsonOut.String(), "manifest": a.manifestPbOut.String(), - "file_contexts": fileContexts.String(), + "file_contexts": a.fileContexts.String(), "canned_fs_config": cannedFsConfig.String(), "key": a.private_key_file.String(), "opt_flags": strings.Join(optFlags, " "), }, }) - apexProtoFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".pb"+suffix) - bundleModuleFile := android.PathForModuleOut(ctx, ctx.ModuleName()+suffix+"-base.zip") + apexProtoFile := android.PathForModuleOut(ctx, a.Name()+".pb"+suffix) + bundleModuleFile := android.PathForModuleOut(ctx, a.Name()+suffix+"-base.zip") a.bundleModuleFile = bundleModuleFile ctx.Build(pctx, android.BuildParams{ @@ -452,7 +443,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { }) } - a.outputFile = android.PathForModuleOut(ctx, ctx.ModuleName()+suffix) + a.outputFile = android.PathForModuleOut(ctx, a.Name()+suffix) ctx.Build(pctx, android.BuildParams{ Rule: java.Signapk, Description: "signapk", @@ -470,7 +461,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { // Install to $OUT/soong/{target,host}/.../apex if a.installable() { - ctx.InstallFile(a.installDir, ctx.ModuleName()+suffix, a.outputFile) + ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile) } a.buildFilesInfo(ctx) } @@ -485,6 +476,11 @@ func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) a.outputFile = android.PathForModuleInstall(&factx, "apex", apexName) + if a.installable() { + installPath := android.PathForModuleInstall(ctx, "apex", apexName) + devicePath := android.InstallPathToOnDevicePath(ctx, installPath) + addFlattenedFileContextsInfos(ctx, apexName+":"+devicePath+":"+a.fileContexts.String()) + } a.buildFilesInfo(ctx) } @@ -505,8 +501,8 @@ func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) { if a.installable() { // For flattened APEX, do nothing but make sure that apex_manifest.json and apex_pubkey are also copied along // with other ordinary files. - a.filesInfo = append(a.filesInfo, apexFile{a.manifestJsonOut, "apex_manifest.json." + ctx.ModuleName() + a.suffix, ".", etc, nil, nil}) - a.filesInfo = append(a.filesInfo, apexFile{a.manifestPbOut, "apex_manifest.pb." + ctx.ModuleName() + a.suffix, ".", etc, nil, nil}) + a.filesInfo = append(a.filesInfo, apexFile{a.manifestJsonOut, "apex_manifest.json." + a.Name() + a.suffix, ".", etc, nil, nil}) + a.filesInfo = append(a.filesInfo, apexFile{a.manifestPbOut, "apex_manifest.pb." + a.Name() + a.suffix, ".", etc, nil, nil}) // rename to apex_pubkey copiedPubkey := android.PathForModuleOut(ctx, "apex_pubkey") @@ -515,10 +511,10 @@ func (a *apexBundle) buildFilesInfo(ctx android.ModuleContext) { Input: a.public_key_file, Output: copiedPubkey, }) - a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, "apex_pubkey." + ctx.ModuleName() + a.suffix, ".", etc, nil, nil}) + a.filesInfo = append(a.filesInfo, apexFile{copiedPubkey, "apex_pubkey." + a.Name() + a.suffix, ".", etc, nil, nil}) if a.properties.ApexType == flattenedApex { - apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) + apexName := proptools.StringDefault(a.properties.Apex_name, a.Name()) for _, fi := range a.filesInfo { dir := filepath.Join("apex", apexName, fi.installDir) target := ctx.InstallFile(android.PathForModuleInstall(ctx, dir), fi.builtFile.Base(), fi.builtFile) diff --git a/bpf/bpf_test.go b/bpf/bpf_test.go index cbb251fad..73b90ba0f 100644 --- a/bpf/bpf_test.go +++ b/bpf/bpf_test.go @@ -55,7 +55,7 @@ func testContext(bp string) *android.TestContext { } ctx := cc.CreateTestContext(bp, mockFS, android.Android) - ctx.RegisterModuleType("bpf", android.ModuleFactoryAdaptor(bpfFactory)) + ctx.RegisterModuleType("bpf", bpfFactory) ctx.Register() return ctx @@ -37,7 +37,7 @@ func init() { android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("vndk", VndkMutator).Parallel() - ctx.BottomUp("image", ImageMutator).Parallel() + ctx.BottomUp("image", android.ImageMutator).Parallel() ctx.BottomUp("link", LinkageMutator).Parallel() ctx.BottomUp("ndk_api", ndkApiMutator).Parallel() ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel() @@ -218,7 +218,10 @@ type BaseProperties struct { // Make this module available when building for recovery Recovery_available *bool - InRecovery bool `blueprint:"mutated"` + // Set by ImageMutator + CoreVariantNeeded bool `blueprint:"mutated"` + RecoveryVariantNeeded bool `blueprint:"mutated"` + VendorVariants []string `blueprint:"mutated"` // Allows this module to use non-APEX version of libraries. Useful // for building binaries that are started before APEXes are activated. @@ -826,7 +829,7 @@ func (c *Module) HasVendorVariant() bool { } func (c *Module) InRecovery() bool { - return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery() + return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery() } func (c *Module) OnlyInRecovery() bool { @@ -1588,8 +1591,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { depTag = headerExportDepTag } if buildStubs { - actx.AddFarVariationDependencies(append(ctx.Target().Variations(), - blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}), + actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()), depTag, lib) } else { actx.AddVariationDependencies(nil, depTag, lib) @@ -1727,14 +1729,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { if vndkdep := c.vndkdep; vndkdep != nil { if vndkdep.isVndkExt() { - var baseModuleMode string - if actx.DeviceConfig().VndkVersion() == "" { - baseModuleMode = coreMode - } else { - baseModuleMode = c.imageVariation() - } actx.AddVariationDependencies([]blueprint.Variation{ - {Mutator: "image", Variation: baseModuleMode}, + c.ImageVariation(), {Mutator: "link", Variation: "shared"}, }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName()) } @@ -2389,15 +2385,6 @@ func (c *Module) installable() bool { return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() } -func (c *Module) imageVariation() string { - if c.UseVndk() { - return vendorMode + "." + c.Properties.VndkVersion - } else if c.InRecovery() { - return recoveryMode - } - return coreMode -} - func (c *Module) IDEInfo(dpInfo *android.IdeInfo) { outputFiles, err := c.OutputFiles("") if err != nil { @@ -2481,15 +2468,9 @@ func DefaultsFactory(props ...interface{}) android.Module { } const ( - // coreMode is the variant used for framework-private libraries, or - // SDK libraries. (which framework-private libraries can use) - coreMode = "core" - - // vendorMode is the variant prefix used for /vendor code that compiles + // VendorVariationPrefix is the variant prefix used for /vendor code that compiles // against the VNDK. - vendorMode = "vendor" - - recoveryMode = "recovery" + VendorVariationPrefix = "vendor." ) func squashVendorSrcs(m *Module) { @@ -2512,74 +2493,9 @@ func squashRecoverySrcs(m *Module) { } } -func ImageMutator(mctx android.BottomUpMutatorContext) { - if mctx.Os() != android.Android { - return - } - - if g, ok := mctx.Module().(*genrule.Module); ok { - if props, ok := g.Extra.(*GenruleExtraProperties); ok { - var coreVariantNeeded bool = false - var vendorVariantNeeded bool = false - var recoveryVariantNeeded bool = false - if mctx.DeviceConfig().VndkVersion() == "" { - coreVariantNeeded = true - } else if Bool(props.Vendor_available) { - coreVariantNeeded = true - vendorVariantNeeded = true - } else if mctx.SocSpecific() || mctx.DeviceSpecific() { - vendorVariantNeeded = true - } else { - coreVariantNeeded = true - } - if Bool(props.Recovery_available) { - recoveryVariantNeeded = true - } - - if recoveryVariantNeeded { - primaryArch := mctx.Config().DevicePrimaryArchType() - moduleArch := g.Target().Arch.ArchType - if moduleArch != primaryArch { - recoveryVariantNeeded = false - } - } - - var variants []string - if coreVariantNeeded { - variants = append(variants, coreMode) - } - if vendorVariantNeeded { - variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion()) - if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" { - variants = append(variants, vendorMode+"."+vndkVersion) - } - } - if recoveryVariantNeeded { - variants = append(variants, recoveryMode) - } - mod := mctx.CreateVariations(variants...) - for i, v := range variants { - if v == recoveryMode { - m := mod[i].(*genrule.Module) - m.Extra.(*GenruleExtraProperties).InRecovery = true - } - } - } - } - - //TODO When LinkableInterface supports VNDK, this should be mctx.Module().(LinkableInterface) - m, ok := mctx.Module().(*Module) - if !ok { - if linkable, ok := mctx.Module().(LinkableInterface); ok { - variations := []string{coreMode} - if linkable.InRecovery() { - variations = append(variations, recoveryMode) - } - mctx.CreateVariations(variations...) - } - return - } +var _ android.ImageInterface = (*Module)(nil) +func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { // Sanity check vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() productSpecific := mctx.ProductSpecific() @@ -2587,7 +2503,6 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { if m.VendorProperties.Vendor_available != nil && vendorSpecific { mctx.PropertyErrorf("vendor_available", "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`") - return } if vndkdep := m.vndkdep; vndkdep != nil { @@ -2595,38 +2510,32 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { if productSpecific { mctx.PropertyErrorf("product_specific", "product_specific must not be true when `vndk: {enabled: true}`") - return } if vendorSpecific { if !vndkdep.isVndkExt() { mctx.PropertyErrorf("vndk", "must set `extends: \"...\"` to vndk extension") - return } } else { if vndkdep.isVndkExt() { mctx.PropertyErrorf("vndk", "must set `vendor: true` to set `extends: %q`", m.getVndkExtendsModuleName()) - return } if m.VendorProperties.Vendor_available == nil { mctx.PropertyErrorf("vndk", "vendor_available must be set to either true or false when `vndk: {enabled: true}`") - return } } } else { if vndkdep.isVndkSp() { mctx.PropertyErrorf("vndk", "must set `enabled: true` to set `support_system_process: true`") - return } if vndkdep.isVndkExt() { mctx.PropertyErrorf("vndk", "must set `enabled: true` to set `extends: %q`", m.getVndkExtendsModuleName()) - return } } } @@ -2705,28 +2614,34 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { } } - var variants []string - if coreVariantNeeded { - variants = append(variants, coreMode) - } for _, variant := range android.FirstUniqueStrings(vendorVariants) { - variants = append(variants, vendorMode+"."+variant) + m.Properties.VendorVariants = append(m.Properties.VendorVariants, VendorVariationPrefix+variant) } - if recoveryVariantNeeded { - variants = append(variants, recoveryMode) - } - mod := mctx.CreateVariations(variants...) - for i, v := range variants { - if strings.HasPrefix(v, vendorMode+".") { - m := mod[i].(*Module) - m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".") - squashVendorSrcs(m) - } else if v == recoveryMode { - m := mod[i].(*Module) - m.Properties.InRecovery = true - m.MakeAsPlatform() - squashRecoverySrcs(m) - } + + m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded + m.Properties.CoreVariantNeeded = coreVariantNeeded +} + +func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { + return c.Properties.CoreVariantNeeded +} + +func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { + return c.Properties.RecoveryVariantNeeded +} + +func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string { + return c.Properties.VendorVariants +} + +func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { + m := module.(*Module) + if variant == android.RecoveryVariation { + m.MakeAsPlatform() + squashRecoverySrcs(m) + } else if strings.HasPrefix(variant, VendorVariationPrefix) { + m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix) + squashVendorSrcs(m) } } diff --git a/cc/config/vndk.go b/cc/config/vndk.go index 3e8abac53..c3cda4976 100644 --- a/cc/config/vndk.go +++ b/cc/config/vndk.go @@ -165,4 +165,5 @@ var VndkMustUseVendorVariantList = []string{ "libxml2", "libyuv", "libziparchive", + "vintf-vibrator-ndk_platform", } diff --git a/cc/genrule.go b/cc/genrule.go index e594f4b2f..e74dd4d72 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -26,9 +26,6 @@ func init() { type GenruleExtraProperties struct { Vendor_available *bool Recovery_available *bool - - // This genrule is for recovery variant - InRecovery bool `blueprint:"mutated"` } // cc_genrule is a genrule that can depend on other cc_* objects. @@ -37,7 +34,9 @@ type GenruleExtraProperties struct { func genRuleFactory() android.Module { module := genrule.NewGenRule() - module.Extra = &GenruleExtraProperties{} + extra := &GenruleExtraProperties{} + module.Extra = extra + module.ImageInterface = extra module.AddProperties(module.Extra) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth) @@ -46,3 +45,44 @@ func genRuleFactory() android.Module { return module } + +var _ android.ImageInterface = (*GenruleExtraProperties)(nil) + +func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {} + +func (g *GenruleExtraProperties) CoreVariantNeeded(ctx android.BaseModuleContext) bool { + if ctx.DeviceConfig().VndkVersion() == "" { + return true + } + + return Bool(g.Vendor_available) || !(ctx.SocSpecific() || ctx.DeviceSpecific()) +} + +func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { + if Bool(g.Recovery_available) { + primaryArch := ctx.Config().DevicePrimaryArchType() + moduleArch := ctx.Target().Arch.ArchType + return moduleArch == primaryArch + } + return false +} + +func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string { + if ctx.DeviceConfig().VndkVersion() == "" { + return nil + } + + if Bool(g.Vendor_available) || ctx.SocSpecific() || ctx.DeviceSpecific() { + var variants []string + variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) + if vndkVersion := ctx.DeviceConfig().VndkVersion(); vndkVersion != "current" { + variants = append(variants, VendorVariationPrefix+vndkVersion) + } + return variants + } + + return nil +} + +func (g *GenruleExtraProperties) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { +} diff --git a/cc/genrule_test.go b/cc/genrule_test.go index 92024ac14..785e3e1e4 100644 --- a/cc/genrule_test.go +++ b/cc/genrule_test.go @@ -25,7 +25,7 @@ func testGenruleContext(config android.Config, bp string, fs map[string][]byte) *android.TestContext { ctx := android.NewTestArchContext() - ctx.RegisterModuleType("cc_genrule", android.ModuleFactoryAdaptor(genRuleFactory)) + ctx.RegisterModuleType("cc_genrule", genRuleFactory) ctx.Register() mockFS := map[string][]byte{ diff --git a/cc/library.go b/cc/library.go index b8c4b5125..98cae3d49 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1359,9 +1359,11 @@ func VersionMutator(mctx android.BottomUpMutatorContext) { return } if genrule, ok := mctx.Module().(*genrule.Module); ok { - if props, ok := genrule.Extra.(*GenruleExtraProperties); ok && !props.InRecovery { - mctx.CreateVariations("") - return + if _, ok := genrule.Extra.(*GenruleExtraProperties); ok { + if !genrule.InRecovery() { + mctx.CreateVariations("") + return + } } } } diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go index edcd26eff..72f9f4ac3 100644 --- a/cc/prebuilt_test.go +++ b/cc/prebuilt_test.go @@ -72,9 +72,9 @@ func TestPrebuilt(t *testing.T) { ctx := CreateTestContext(bp, fs, android.Android) - ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(PrebuiltSharedLibraryFactory)) - ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(PrebuiltStaticLibraryFactory)) - ctx.RegisterModuleType("cc_prebuilt_binary", android.ModuleFactoryAdaptor(prebuiltBinaryFactory)) + ctx.RegisterModuleType("cc_prebuilt_library_shared", PrebuiltSharedLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PostDepsMutators(android.RegisterPrebuiltsPostDepsMutators) diff --git a/cc/sanitize.go b/cc/sanitize.go index 2bf051e5a..55bdd1c5c 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -886,13 +886,13 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { // static executable gets static runtime libs mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{ {Mutator: "link", Variation: "static"}, - {Mutator: "image", Variation: c.imageVariation()}, + c.ImageVariation(), }...), StaticDepTag, append([]string{runtimeLibrary}, extraStaticDeps...)...) } else if !c.static() && !c.header() { // dynamic executable and shared libs get shared runtime libs mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{ {Mutator: "link", Variation: "shared"}, - {Mutator: "image", Variation: c.imageVariation()}, + c.ImageVariation(), }...), earlySharedDepTag, runtimeLibrary) } // static lib does not have dependency to the runtime library. The diff --git a/cc/test_data_test.go b/cc/test_data_test.go index 21ea765eb..962ff2685 100644 --- a/cc/test_data_test.go +++ b/cc/test_data_test.go @@ -126,10 +126,8 @@ func TestDataTests(t *testing.T) { "dir/baz": nil, "dir/bar/baz": nil, }) - ctx.RegisterModuleType("filegroup", - android.ModuleFactoryAdaptor(android.FileGroupFactory)) - ctx.RegisterModuleType("test", - android.ModuleFactoryAdaptor(newTest)) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) + ctx.RegisterModuleType("test", newTest) ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Blueprints") diff --git a/cc/testing.go b/cc/testing.go index 9ad72d9f5..3b10f876f 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -253,25 +253,25 @@ func CreateTestContext(bp string, fs map[string][]byte, os android.OsType) *android.TestContext { ctx := android.NewTestArchContext() - ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) - ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) - ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) - ctx.RegisterModuleType("cc_fuzz", android.ModuleFactoryAdaptor(FuzzFactory)) - ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory)) - ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory)) - ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(LibraryStaticFactory)) - ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(LibraryHeaderFactory)) - ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(TestFactory)) - ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(ToolchainLibraryFactory)) - ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(LlndkLibraryFactory)) - ctx.RegisterModuleType("llndk_headers", android.ModuleFactoryAdaptor(llndkHeadersFactory)) - ctx.RegisterModuleType("vendor_public_library", android.ModuleFactoryAdaptor(vendorPublicLibraryFactory)) - ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(ObjectFactory)) - ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) - ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(VndkPrebuiltSharedFactory)) - ctx.RegisterModuleType("vndk_libraries_txt", android.ModuleFactoryAdaptor(VndkLibrariesTxtFactory)) + ctx.RegisterModuleType("cc_defaults", defaultsFactory) + ctx.RegisterModuleType("cc_binary", BinaryFactory) + ctx.RegisterModuleType("cc_binary_host", binaryHostFactory) + ctx.RegisterModuleType("cc_fuzz", FuzzFactory) + ctx.RegisterModuleType("cc_library", LibraryFactory) + ctx.RegisterModuleType("cc_library_shared", LibrarySharedFactory) + ctx.RegisterModuleType("cc_library_static", LibraryStaticFactory) + ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory) + ctx.RegisterModuleType("cc_test", TestFactory) + ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory) + ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory) + ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory) + ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory) + ctx.RegisterModuleType("cc_object", ObjectFactory) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) + ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) + ctx.RegisterModuleType("vndk_libraries_txt", VndkLibrariesTxtFactory) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("image", ImageMutator).Parallel() + ctx.BottomUp("image", android.ImageMutator).Parallel() ctx.BottomUp("link", LinkageMutator).Parallel() ctx.BottomUp("vndk", VndkMutator).Parallel() ctx.BottomUp("version", VersionMutator).Parallel() @@ -281,7 +281,7 @@ func CreateTestContext(bp string, fs map[string][]byte, ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() }) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) - ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton)) + ctx.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton) // add some modules that are required by the compiler and/or linker bp = bp + GatherRequiredDepsForTest(os) diff --git a/dexpreopt/config.go b/dexpreopt/config.go index 9215eff3f..f38d89297 100644 --- a/dexpreopt/config.go +++ b/dexpreopt/config.go @@ -44,9 +44,10 @@ type GlobalConfig struct { ProductUpdatableBootModules []string ProductUpdatableBootLocations []string - SystemServerJars []string // jars that form the system server - SystemServerApps []string // apps that are loaded into system server - SpeedApps []string // apps that should be speed optimized + SystemServerJars []string // jars that form the system server + SystemServerApps []string // apps that are loaded into system server + UpdatableSystemServerJars []string // jars within apex that are loaded into system server + SpeedApps []string // apps that should be speed optimized PreoptFlags []string // global dex2oat flags that should be used if no module-specific dex2oat flags are specified @@ -285,6 +286,7 @@ func GlobalConfigForTests(ctx android.PathContext) GlobalConfig { ProductUpdatableBootLocations: nil, SystemServerJars: nil, SystemServerApps: nil, + UpdatableSystemServerJars: nil, SpeedApps: nil, PreoptFlags: nil, DefaultCompilerFilter: "", diff --git a/genrule/genrule.go b/genrule/genrule.go index a7c5d65f6..57ca9bc6f 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -118,6 +118,7 @@ type Module struct { // For other packages to make their own genrules with extra // properties Extra interface{} + android.ImageInterface properties generatorProperties @@ -532,9 +533,20 @@ func generatorFactory(taskGenerator taskFunc, props ...interface{}) *Module { module.AddProperties(props...) module.AddProperties(&module.properties) + module.ImageInterface = noopImageInterface{} + return module } +type noopImageInterface struct{} + +func (x noopImageInterface) ImageMutatorBegin(android.BaseModuleContext) {} +func (x noopImageInterface) CoreVariantNeeded(android.BaseModuleContext) bool { return false } +func (x noopImageInterface) RecoveryVariantNeeded(android.BaseModuleContext) bool { return false } +func (x noopImageInterface) ExtraImageVariations(ctx android.BaseModuleContext) []string { return nil } +func (x noopImageInterface) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { +} + // replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>" func pathToSandboxOut(path android.Path, genDir android.Path) string { relOut, err := filepath.Rel(genDir.String(), path.String()) diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index 5ac0e8cd3..07de999bc 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -55,11 +55,11 @@ func testContext(config android.Config, bp string, fs map[string][]byte) *android.TestContext { ctx := android.NewTestArchContext() - ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) - ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(GenRuleFactory)) - ctx.RegisterModuleType("gensrcs", android.ModuleFactoryAdaptor(GenSrcsFactory)) - ctx.RegisterModuleType("genrule_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) - ctx.RegisterModuleType("tool", android.ModuleFactoryAdaptor(toolFactory)) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) + ctx.RegisterModuleType("genrule", GenRuleFactory) + ctx.RegisterModuleType("gensrcs", GenSrcsFactory) + ctx.RegisterModuleType("genrule_defaults", defaultsFactory) + ctx.RegisterModuleType("tool", toolFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.Register() diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go index a684ab232..29a5abe7f 100644 --- a/java/dexpreopt_bootjars_test.go +++ b/java/dexpreopt_bootjars_test.go @@ -53,7 +53,7 @@ func TestDexpreoptBootJars(t *testing.T) { ctx := testContext(bp, nil) - ctx.RegisterSingletonType("dex_bootjars", android.SingletonFactoryAdaptor(dexpreoptBootJarsFactory)) + ctx.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory) run(t, ctx, config) diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index a6661b33d..15f11e11c 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -15,6 +15,7 @@ package java import ( + "fmt" "path/filepath" "strings" @@ -65,6 +66,16 @@ func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt. var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig") var dexpreoptTestGlobalConfigKey = android.NewOnceKey("TestDexpreoptGlobalConfig") +// Expected format for apexJarValue = <apex name>:<jar name> +func splitApexJarPair(apexJarValue string) (string, string) { + var apexJarPair []string = strings.SplitN(apexJarValue, ":", 2) + if apexJarPair == nil || len(apexJarPair) != 2 { + panic(fmt.Errorf("malformed apexJarValue: %q, expected format: <apex>:<jar>", + apexJarValue)) + } + return apexJarPair[0], apexJarPair[1] +} + // systemServerClasspath returns the on-device locations of the modules in the system server classpath. It is computed // once the first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same // ctx.Config(). @@ -77,6 +88,11 @@ func systemServerClasspath(ctx android.PathContext) []string { systemServerClasspathLocations = append(systemServerClasspathLocations, filepath.Join("/system/framework", m+".jar")) } + for _, m := range global.UpdatableSystemServerJars { + apex, jar := splitApexJarPair(m) + systemServerClasspathLocations = append(systemServerClasspathLocations, + filepath.Join("/apex", apex, "javalib", jar + ".jar")) + } return systemServerClasspathLocations }) } diff --git a/java/droiddoc.go b/java/droiddoc.go index 54f93fec2..83a1ad588 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -37,6 +37,8 @@ func init() { android.RegisterModuleType("droidstubs", DroidstubsFactory) android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory) + + android.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory) } var ( @@ -1163,6 +1165,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { // type Droidstubs struct { Javadoc + android.SdkBase properties DroidstubsProperties apiFile android.WritablePath @@ -1208,6 +1211,7 @@ func DroidstubsFactory() android.Module { &module.Javadoc.properties) InitDroiddocModule(module, android.HostAndDeviceSupported) + android.InitSdkAwareModule(module) return module } @@ -1913,3 +1917,88 @@ func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder, func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) { rule.Command().Text("rm -rf").Text(srcJarDir.String()) } + +var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil) + +type PrebuiltStubsSourcesProperties struct { + Srcs []string `android:"path"` +} + +type PrebuiltStubsSources struct { + android.ModuleBase + android.DefaultableModuleBase + prebuilt android.Prebuilt + android.SdkBase + + properties PrebuiltStubsSourcesProperties + + srcs android.Paths + stubsSrcJar android.ModuleOutPath +} + +func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) { + p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs) +} + +func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt { + return &p.prebuilt +} + +func (p *PrebuiltStubsSources) Name() string { + return p.prebuilt.Name(p.ModuleBase.Name()) +} + +func (p *PrebuiltStubsSources) Srcs() android.Paths { + return append(android.Paths{}, p.srcs...) +} + +// prebuilt_stubs_sources imports a set of java source files as if they were +// generated by droidstubs. +// +// By default, a prebuilt_stubs_sources has a single variant that expects a +// set of `.java` files generated by droidstubs. +// +// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one +// for host modules. +// +// Intended only for use by sdk snapshots. +func PrebuiltStubsSourcesFactory() android.Module { + module := &PrebuiltStubsSources{} + + module.AddProperties(&module.properties) + + android.InitPrebuiltModule(module, &module.properties.Srcs) + android.InitSdkAwareModule(module) + InitDroiddocModule(module, android.HostAndDeviceSupported) + return module +} + +func (d *Droidstubs) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) { + stubsSrcJar := d.stubsSrcJar + + snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources") + builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir) + + name := d.Name() + bp := builder.AndroidBpFile() + bp.Printfln("prebuilt_stubs_sources {") + bp.Indent() + bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name)) + bp.Printfln("sdk_member_name: %q,", name) + bp.Printfln("srcs: [%q],", snapshotRelativeDir) + bp.Dedent() + bp.Printfln("}") + bp.Printfln("") + + // This module is for the case when the source tree for the unversioned module + // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false + // so that this module does not eclipse the unversioned module if it exists. + bp.Printfln("prebuilt_stubs_sources {") + bp.Indent() + bp.Printfln("name: %q,", name) + bp.Printfln("srcs: [%q],", snapshotRelativeDir) + bp.Printfln("prefer: false,") + bp.Dedent() + bp.Printfln("}") + bp.Printfln("") +} diff --git a/java/java.go b/java/java.go index d4f65ba42..110478574 100644 --- a/java/java.go +++ b/java/java.go @@ -1691,25 +1691,27 @@ func (j *Library) BuildSnapshot(sdkModuleContext android.ModuleContext, builder } } - name := j.Name() - bp := builder.AndroidBpFile() - bp.Printfln("java_import {") - bp.Indent() - bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name)) - bp.Printfln("sdk_member_name: %q,", name) - bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath) - bp.Dedent() - bp.Printfln("}") - bp.Printfln("") + j.generateJavaImport(builder, snapshotRelativeJavaLibPath, true) // This module is for the case when the source tree for the unversioned module // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false // so that this module does not eclipse the unversioned module if it exists. + j.generateJavaImport(builder, snapshotRelativeJavaLibPath, false) +} + +func (j *Library) generateJavaImport(builder android.SnapshotBuilder, snapshotRelativeJavaLibPath string, versioned bool) { + bp := builder.AndroidBpFile() + name := j.Name() bp.Printfln("java_import {") bp.Indent() - bp.Printfln("name: %q,", name) + if versioned { + bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name)) + bp.Printfln("sdk_member_name: %q,", name) + } else { + bp.Printfln("name: %q,", name) + bp.Printfln("prefer: false,") + } bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath) - bp.Printfln("prefer: false,") bp.Dedent() bp.Printfln("}") bp.Printfln("") diff --git a/java/java_test.go b/java/java_test.go index 0f7e6dee8..efef7c1cc 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -63,37 +63,38 @@ func testConfig(env map[string]string) android.Config { func testContext(bp string, fs map[string][]byte) *android.TestContext { ctx := android.NewTestArchContext() - ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory)) - ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(AndroidAppCertificateFactory)) - ctx.RegisterModuleType("android_app_import", android.ModuleFactoryAdaptor(AndroidAppImportFactory)) - ctx.RegisterModuleType("android_library", android.ModuleFactoryAdaptor(AndroidLibraryFactory)) - ctx.RegisterModuleType("android_test", android.ModuleFactoryAdaptor(AndroidTestFactory)) - ctx.RegisterModuleType("android_test_helper_app", android.ModuleFactoryAdaptor(AndroidTestHelperAppFactory)) - ctx.RegisterModuleType("android_test_import", android.ModuleFactoryAdaptor(AndroidTestImportFactory)) - ctx.RegisterModuleType("java_binary", android.ModuleFactoryAdaptor(BinaryFactory)) - ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory)) - ctx.RegisterModuleType("java_device_for_host", android.ModuleFactoryAdaptor(DeviceForHostFactory)) - ctx.RegisterModuleType("java_host_for_device", android.ModuleFactoryAdaptor(HostForDeviceFactory)) - ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory)) - ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory)) - ctx.RegisterModuleType("java_test", android.ModuleFactoryAdaptor(TestFactory)) - ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory)) - ctx.RegisterModuleType("java_import_host", android.ModuleFactoryAdaptor(ImportFactoryHost)) - ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) - ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(SystemModulesFactory)) - ctx.RegisterModuleType("java_genrule", android.ModuleFactoryAdaptor(genRuleFactory)) - ctx.RegisterModuleType("java_plugin", android.ModuleFactoryAdaptor(PluginFactory)) - ctx.RegisterModuleType("dex_import", android.ModuleFactoryAdaptor(DexImportFactory)) - ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) - ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory)) - ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory)) - ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory)) - ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(ExportedDroiddocDirFactory)) - ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(SdkLibraryFactory)) - ctx.RegisterModuleType("java_sdk_library_import", android.ModuleFactoryAdaptor(sdkLibraryImportFactory)) - ctx.RegisterModuleType("override_android_app", android.ModuleFactoryAdaptor(OverrideAndroidAppModuleFactory)) - ctx.RegisterModuleType("override_android_test", android.ModuleFactoryAdaptor(OverrideAndroidTestModuleFactory)) - ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(PrebuiltApisFactory)) + ctx.RegisterModuleType("android_app", AndroidAppFactory) + ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory) + ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory) + ctx.RegisterModuleType("android_library", AndroidLibraryFactory) + ctx.RegisterModuleType("android_test", AndroidTestFactory) + ctx.RegisterModuleType("android_test_helper_app", AndroidTestHelperAppFactory) + ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory) + ctx.RegisterModuleType("java_binary", BinaryFactory) + ctx.RegisterModuleType("java_binary_host", BinaryHostFactory) + ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory) + ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory) + ctx.RegisterModuleType("java_library", LibraryFactory) + ctx.RegisterModuleType("java_library_host", LibraryHostFactory) + ctx.RegisterModuleType("java_test", TestFactory) + ctx.RegisterModuleType("java_import", ImportFactory) + ctx.RegisterModuleType("java_import_host", ImportFactoryHost) + ctx.RegisterModuleType("java_defaults", defaultsFactory) + ctx.RegisterModuleType("java_system_modules", SystemModulesFactory) + ctx.RegisterModuleType("java_genrule", genRuleFactory) + ctx.RegisterModuleType("java_plugin", PluginFactory) + ctx.RegisterModuleType("dex_import", DexImportFactory) + ctx.RegisterModuleType("filegroup", android.FileGroupFactory) + ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) + ctx.RegisterModuleType("droiddoc", DroiddocFactory) + ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory) + ctx.RegisterModuleType("droiddoc_template", ExportedDroiddocDirFactory) + ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory) + ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) + ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) + ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory) + ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory) + ctx.RegisterModuleType("prebuilt_apis", PrebuiltApisFactory) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) @@ -105,11 +106,11 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext { ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory)) // Register module types and mutators from cc needed for JNI testing - ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) - ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) - ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) - ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) - ctx.RegisterModuleType("ndk_prebuilt_shared_stl", android.ModuleFactoryAdaptor(cc.NdkPrebuiltSharedStlFactory)) + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) + ctx.RegisterModuleType("cc_object", cc.ObjectFactory) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) + ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory) + ctx.RegisterModuleType("ndk_prebuilt_shared_stl", cc.NdkPrebuiltSharedStlFactory) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("link", cc.LinkageMutator).Parallel() ctx.BottomUp("begin", cc.BeginMutator).Parallel() @@ -207,6 +208,9 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext { "cert/new_cert.pk8": nil, "testdata/data": nil, + + "stubs-sources/foo/Foo.java": nil, + "stubs/sources/foo/Foo.java": nil, } for k, v := range fs { @@ -415,7 +419,7 @@ func TestPrebuilts(t *testing.T) { ctx, _ := testJava(t, ` java_library { name: "foo", - srcs: ["a.java"], + srcs: ["a.java", ":stubs-source"], libs: ["bar", "sdklib"], static_libs: ["baz"], } @@ -439,6 +443,11 @@ func TestPrebuilts(t *testing.T) { name: "sdklib", jars: ["b.jar"], } + + prebuilt_stubs_sources { + name: "stubs-source", + srcs: ["stubs/sources/**/*.java"], + } `) javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") @@ -447,6 +456,19 @@ func TestPrebuilts(t *testing.T) { bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output + inputs := []string{} + for _, p := range javac.BuildParams.Inputs { + inputs = append(inputs, p.String()) + } + + expected := []string{ + "a.java", + "stubs/sources/foo/Foo.java", + } + if !reflect.DeepEqual(expected, inputs) { + t.Errorf("foo inputs incorrect: expected %q, found %q", expected, inputs) + } + if !strings.Contains(javac.Args["classpath"], barJar.String()) { t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String()) } diff --git a/python/python_test.go b/python/python_test.go index e5fe126c1..ba5e7fadc 100644 --- a/python/python_test.go +++ b/python/python_test.go @@ -332,12 +332,9 @@ func TestPythonModule(t *testing.T) { ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("version_split", versionSplitMutator()).Parallel() }) - ctx.RegisterModuleType("python_library_host", - android.ModuleFactoryAdaptor(PythonLibraryHostFactory)) - ctx.RegisterModuleType("python_binary_host", - android.ModuleFactoryAdaptor(PythonBinaryHostFactory)) - ctx.RegisterModuleType("python_defaults", - android.ModuleFactoryAdaptor(defaultsFactory)) + ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory) + ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory) + ctx.RegisterModuleType("python_defaults", defaultsFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.Register() ctx.MockFileSystem(d.mockFiles) diff --git a/rust/rust.go b/rust/rust.go index 096f7b684..a3266f7a8 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -77,6 +77,25 @@ type Module struct { outputFile android.OptionalPath } +var _ android.ImageInterface = (*Module)(nil) + +func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {} + +func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { + return true +} + +func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool { + return mod.InRecovery() +} + +func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string { + return nil +} + +func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { +} + func (mod *Module) BuildStubs() bool { return false } @@ -687,7 +706,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { blueprint.Variation{Mutator: "version", Variation: ""}) if !mod.Host() { commonDepVariations = append(commonDepVariations, - blueprint.Variation{Mutator: "image", Variation: "core"}) + blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) } actx.AddVariationDependencies( diff --git a/rust/testing.go b/rust/testing.go index 24defa634..45dbbbdcf 100644 --- a/rust/testing.go +++ b/rust/testing.go @@ -164,28 +164,28 @@ func GatherRequiredDepsForTest() string { func CreateTestContext(bp string) *android.TestContext { ctx := android.NewTestArchContext() - ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) - ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) - ctx.RegisterModuleType("rust_binary", android.ModuleFactoryAdaptor(RustBinaryFactory)) - ctx.RegisterModuleType("rust_binary_host", android.ModuleFactoryAdaptor(RustBinaryHostFactory)) - ctx.RegisterModuleType("rust_test", android.ModuleFactoryAdaptor(RustTestFactory)) - ctx.RegisterModuleType("rust_test_host", android.ModuleFactoryAdaptor(RustTestHostFactory)) - ctx.RegisterModuleType("rust_library", android.ModuleFactoryAdaptor(RustLibraryFactory)) - ctx.RegisterModuleType("rust_library_host", android.ModuleFactoryAdaptor(RustLibraryHostFactory)) - ctx.RegisterModuleType("rust_library_host_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibHostFactory)) - ctx.RegisterModuleType("rust_library_host_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibHostFactory)) - ctx.RegisterModuleType("rust_library_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibFactory)) - ctx.RegisterModuleType("rust_library_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibFactory)) - ctx.RegisterModuleType("rust_library_shared", android.ModuleFactoryAdaptor(RustLibrarySharedFactory)) - ctx.RegisterModuleType("rust_library_static", android.ModuleFactoryAdaptor(RustLibraryStaticFactory)) - ctx.RegisterModuleType("rust_library_host_shared", android.ModuleFactoryAdaptor(RustLibrarySharedHostFactory)) - ctx.RegisterModuleType("rust_library_host_static", android.ModuleFactoryAdaptor(RustLibraryStaticHostFactory)) - ctx.RegisterModuleType("rust_proc_macro", android.ModuleFactoryAdaptor(ProcMacroFactory)) - ctx.RegisterModuleType("rust_prebuilt_dylib", android.ModuleFactoryAdaptor(PrebuiltDylibFactory)) - ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) + ctx.RegisterModuleType("cc_object", cc.ObjectFactory) + ctx.RegisterModuleType("rust_binary", RustBinaryFactory) + ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory) + ctx.RegisterModuleType("rust_test", RustTestFactory) + ctx.RegisterModuleType("rust_test_host", RustTestHostFactory) + ctx.RegisterModuleType("rust_library", RustLibraryFactory) + ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory) + ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory) + ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory) + ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory) + ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory) + ctx.RegisterModuleType("rust_library_shared", RustLibrarySharedFactory) + ctx.RegisterModuleType("rust_library_static", RustLibraryStaticFactory) + ctx.RegisterModuleType("rust_library_host_shared", RustLibrarySharedHostFactory) + ctx.RegisterModuleType("rust_library_host_static", RustLibraryStaticHostFactory) + ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory) + ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { // cc mutators - ctx.BottomUp("image", cc.ImageMutator).Parallel() + ctx.BottomUp("image", android.ImageMutator).Parallel() ctx.BottomUp("link", cc.LinkageMutator).Parallel() ctx.BottomUp("version", cc.VersionMutator).Parallel() ctx.BottomUp("begin", cc.BeginMutator).Parallel() diff --git a/sdk/sdk.go b/sdk/sdk.go index 4eb3665fb..ac6fce989 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -16,6 +16,7 @@ package sdk import ( "fmt" + "io" "strconv" "github.com/google/blueprint" @@ -50,6 +51,8 @@ type sdkProperties struct { Java_libs []string // The list of native libraries in this SDK Native_shared_libs []string + // The list of stub sources in this SDK + Stubs_sources []string Snapshot bool `blueprint:"mutated"` } @@ -121,6 +124,13 @@ func (s *sdk) AndroidMkEntries() android.AndroidMkEntries { OutputFile: s.snapshotFile, DistFile: s.snapshotFile, Include: "$(BUILD_PHONY_PACKAGE)", + ExtraFooters: []android.AndroidMkExtraFootersFunc{ + func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) { + // Allow the sdk to be built by simply passing its name on the command line. + fmt.Fprintln(w, ".PHONY:", s.Name()) + fmt.Fprintln(w, s.Name()+":", s.snapshotFile.String()) + }, + }, } } @@ -167,6 +177,7 @@ type sdkMemberVesionedDepTag struct { func memberMutator(mctx android.BottomUpMutatorContext) { if m, ok := mctx.Module().(*sdk); ok { mctx.AddVariationDependencies(nil, sdkMemberDepTag, m.properties.Java_libs...) + mctx.AddVariationDependencies(nil, sdkMemberDepTag, m.properties.Stubs_sources...) targets := mctx.MultiTargets() for _, target := range targets { @@ -176,7 +187,7 @@ func memberMutator(mctx android.BottomUpMutatorContext) { version = cc.LatestStubsVersionFor(mctx.Config(), name) } mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{ - {Mutator: "image", Variation: "core"}, + {Mutator: "image", Variation: android.CoreVariation}, {Mutator: "link", Variation: "shared"}, {Mutator: "version", Variation: version}, }...), sdkMemberDepTag, name) diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 3471bc9da..b40ec1308 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -42,20 +42,22 @@ func testSdkContext(t *testing.T, bp string) (*android.TestContext, android.Conf }) // from java package - ctx.RegisterModuleType("android_app_certificate", android.ModuleFactoryAdaptor(java.AndroidAppCertificateFactory)) - ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) - ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory)) + ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory) + ctx.RegisterModuleType("java_library", java.LibraryFactory) + ctx.RegisterModuleType("java_import", java.ImportFactory) + ctx.RegisterModuleType("droidstubs", java.DroidstubsFactory) + ctx.RegisterModuleType("prebuilt_stubs_sources", java.PrebuiltStubsSourcesFactory) // from cc package - ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) - ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) - ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) - ctx.RegisterModuleType("cc_prebuilt_library_shared", android.ModuleFactoryAdaptor(cc.PrebuiltSharedLibraryFactory)) - ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory)) - ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) - ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) + ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory) + ctx.RegisterModuleType("cc_object", cc.ObjectFactory) + ctx.RegisterModuleType("cc_prebuilt_library_shared", cc.PrebuiltSharedLibraryFactory) + ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory) + ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("image", cc.ImageMutator).Parallel() + ctx.BottomUp("image", android.ImageMutator).Parallel() ctx.BottomUp("link", cc.LinkageMutator).Parallel() ctx.BottomUp("vndk", cc.VndkMutator).Parallel() ctx.BottomUp("test_per_src", cc.TestPerSrcMutator).Parallel() @@ -64,13 +66,13 @@ func testSdkContext(t *testing.T, bp string) (*android.TestContext, android.Conf }) // from apex package - ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apex.BundleFactory)) - ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apex.ApexKeyFactory)) + ctx.RegisterModuleType("apex", apex.BundleFactory) + ctx.RegisterModuleType("apex_key", apex.ApexKeyFactory) ctx.PostDepsMutators(apex.RegisterPostDepsMutators) // from this package - ctx.RegisterModuleType("sdk", android.ModuleFactoryAdaptor(ModuleFactory)) - ctx.RegisterModuleType("sdk_snapshot", android.ModuleFactoryAdaptor(SnapshotModuleFactory)) + ctx.RegisterModuleType("sdk", ModuleFactory) + ctx.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory) ctx.PreDepsMutators(RegisterPreDepsMutators) ctx.PostDepsMutators(RegisterPostDepsMutators) @@ -104,6 +106,8 @@ func testSdkContext(t *testing.T, bp string) (*android.TestContext, android.Conf "include/Test.h": nil, "aidl/foo/bar/Test.aidl": nil, "libfoo.so": nil, + "stubs-sources/foo/bar/Foo.java": nil, + "foo/bar/Foo.java": nil, }) return ctx, config @@ -323,6 +327,39 @@ func TestBasicSdkWithCc(t *testing.T) { ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String()) } +// Note: This test does not verify that a droidstubs can be referenced, either +// directly or indirectly from an APEX as droidstubs can never be a part of an +// apex. +func TestBasicSdkWithDroidstubs(t *testing.T) { + testSdk(t, ` + sdk { + name: "mysdk", + stubs_sources: ["mystub"], + } + sdk_snapshot { + name: "mysdk@10", + stubs_sources: ["mystub_mysdk@10"], + } + prebuilt_stubs_sources { + name: "mystub_mysdk@10", + sdk_member_name: "mystub", + srcs: ["stubs-sources/foo/bar/Foo.java"], + } + droidstubs { + name: "mystub", + srcs: ["foo/bar/Foo.java"], + sdk_version: "none", + system_modules: "none", + } + java_library { + name: "myjavalib", + srcs: [":mystub"], + sdk_version: "none", + system_modules: "none", + } + `) +} + func TestDepNotInRequiredSdks(t *testing.T) { testSdkError(t, `module "myjavalib".*depends on "otherlib".*that isn't part of the required SDKs:.*`, ` sdk { @@ -417,6 +454,7 @@ func TestSnapshot(t *testing.T) { name: "mysdk", java_libs: ["myjavalib"], native_shared_libs: ["mynativelib"], + stubs_sources: ["myjavaapistubs"], } java_library { @@ -444,15 +482,26 @@ func TestSnapshot(t *testing.T) { system_shared_libs: [], stl: "none", } + + droidstubs { + name: "myjavaapistubs", + srcs: ["foo/bar/Foo.java"], + system_modules: "none", + sdk_version: "none", + } `) var copySrcs []string var copyDests []string buildParams := ctx.ModuleForTests("mysdk", "android_common").Module().BuildParamsForTests() + var zipBp android.BuildParams for _, bp := range buildParams { - if bp.Rule.String() == "android/soong/android.Cp" { + ruleString := bp.Rule.String() + if ruleString == "android/soong/android.Cp" { copySrcs = append(copySrcs, bp.Input.String()) copyDests = append(copyDests, bp.Output.Rel()) // rooted at the snapshot root + } else if ruleString == "<local rule>:m.mysdk_android_common.snapshot" { + zipBp = bp } } @@ -472,6 +521,19 @@ func TestSnapshot(t *testing.T) { ensureListContains(t, copyDests, "arm64/include_gen/mynativelib/aidl/foo/bar/Test.h") ensureListContains(t, copyDests, "java/myjavalib.jar") ensureListContains(t, copyDests, "arm64/lib/mynativelib.so") + + // Ensure that the droidstubs .srcjar as repackaged into a temporary zip file + // and then merged together with the intermediate snapshot zip. + snapshotCreationInputs := zipBp.Implicits.Strings() + ensureListContains(t, snapshotCreationInputs, + filepath.Join(buildDir, ".intermediates/mysdk/android_common/tmp/java/myjavaapistubs_stubs_sources.zip")) + ensureListContains(t, snapshotCreationInputs, + filepath.Join(buildDir, ".intermediates/mysdk/android_common/mysdk-current.unmerged.zip")) + actual := zipBp.Output.String() + expected := filepath.Join(buildDir, ".intermediates/mysdk/android_common/mysdk-current.zip") + if actual != expected { + t.Errorf("Expected snapshot output to be %q but was %q", expected, actual) + } } var buildDir string diff --git a/sdk/update.go b/sdk/update.go index 9fa9e0461..6d7b3ecba 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -80,6 +80,16 @@ func (s *sdk) javaLibs(ctx android.ModuleContext) []android.SdkAware { return result } +func (s *sdk) stubsSources(ctx android.ModuleContext) []android.SdkAware { + result := []android.SdkAware{} + ctx.VisitDirectDeps(func(m android.Module) { + if j, ok := m.(*java.Droidstubs); ok { + result = append(result, j) + } + }) + return result +} + // archSpecificNativeLibInfo represents an arch-specific variant of a native lib type archSpecificNativeLibInfo struct { name string @@ -236,8 +246,8 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { ctx: ctx, version: "current", snapshotDir: snapshotDir.OutputPath, - androidBpFile: bp, filesToZip: []android.Path{bp.path}, + androidBpFile: bp, } // copy exported AIDL files and stub jar files @@ -246,6 +256,12 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { m.BuildSnapshot(ctx, builder) } + // copy stubs sources + stubsSources := s.stubsSources(ctx) + for _, m := range stubsSources { + m.BuildSnapshot(ctx, builder) + } + // copy exported header files and stub *.so files nativeLibInfos := s.nativeMemberInfos(ctx) for _, info := range nativeLibInfos { @@ -266,6 +282,15 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { bp.Dedent() bp.Printfln("],") // java_libs } + if len(stubsSources) > 0 { + bp.Printfln("stubs_sources: [") + bp.Indent() + for _, m := range stubsSources { + bp.Printfln("%q,", builder.VersionedSdkMemberName(m.Name())) + } + bp.Dedent() + bp.Printfln("],") // stubs_sources + } if len(nativeLibInfos) > 0 { bp.Printfln("native_shared_libs: [") bp.Indent() @@ -284,16 +309,45 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { filesToZip := builder.filesToZip // zip them all - zipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath + outputZipFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.zip").OutputPath + outputRuleName := "snapshot" + outputDesc := "Building snapshot for " + ctx.ModuleName() + + // If there are no zips to merge then generate the output zip directly. + // Otherwise, generate an intermediate zip file into which other zips can be + // merged. + var zipFile android.OutputPath + var ruleName string + var desc string + if len(builder.zipsToMerge) == 0 { + zipFile = outputZipFile + ruleName = outputRuleName + desc = outputDesc + } else { + zipFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"-current.unmerged.zip").OutputPath + ruleName = "intermediate snapshot" + desc = "Building intermediate snapshot for " + ctx.ModuleName() + } + rb := android.NewRuleBuilder() rb.Command(). BuiltTool(ctx, "soong_zip"). FlagWithArg("-C ", builder.snapshotDir.String()). FlagWithRspFileInputList("-l ", filesToZip). FlagWithOutput("-o ", zipFile) - rb.Build(pctx, ctx, "snapshot", "Building snapshot for "+ctx.ModuleName()) + rb.Build(pctx, ctx, ruleName, desc) + + if len(builder.zipsToMerge) != 0 { + rb := android.NewRuleBuilder() + rb.Command(). + BuiltTool(ctx, "merge_zips"). + Output(outputZipFile). + Input(zipFile). + Inputs(builder.zipsToMerge) + rb.Build(pctx, ctx, outputRuleName, outputDesc) + } - return zipFile + return outputZipFile } func buildSharedNativeLibSnapshot(ctx android.ModuleContext, info *nativeLibInfo, builder android.SnapshotBuilder) { @@ -347,11 +401,26 @@ func buildSharedNativeLibSnapshot(ctx android.ModuleContext, info *nativeLibInfo } } + info.generatePrebuiltLibrary(ctx, builder, true) + + // This module is for the case when the source tree for the unversioned module + // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false + // so that this module does not eclipse the unversioned module if it exists. + info.generatePrebuiltLibrary(ctx, builder, false) +} + +func (info *nativeLibInfo) generatePrebuiltLibrary(ctx android.ModuleContext, builder android.SnapshotBuilder, versioned bool) { bp := builder.AndroidBpFile() bp.Printfln("cc_prebuilt_library_shared {") bp.Indent() - bp.Printfln("name: %q,", builder.VersionedSdkMemberName(info.name)) - bp.Printfln("sdk_member_name: %q,", info.name) + name := info.name + if versioned { + bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name)) + bp.Printfln("sdk_member_name: %q,", name) + } else { + bp.Printfln("name: %q,", name) + bp.Printfln("prefer: false,") + } // a function for emitting include dirs printExportedDirsForNativeLibs := func(lib archSpecificNativeLibInfo, systemInclude bool) { @@ -404,8 +473,9 @@ type snapshotBuilder struct { ctx android.ModuleContext version string snapshotDir android.OutputPath - filesToZip android.Paths androidBpFile *generatedFile + filesToZip android.Paths + zipsToMerge android.Paths } func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) { @@ -418,6 +488,25 @@ func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) { s.filesToZip = append(s.filesToZip, path) } +func (s *snapshotBuilder) UnzipToSnapshot(zipPath android.Path, destDir string) { + ctx := s.ctx + + // Repackage the zip file so that the entries are in the destDir directory. + // This will allow the zip file to be merged into the snapshot. + tmpZipPath := android.PathForModuleOut(ctx, "tmp", destDir+".zip").OutputPath + rb := android.NewRuleBuilder() + rb.Command(). + BuiltTool(ctx, "zip2zip"). + FlagWithInput("-i ", zipPath). + FlagWithOutput("-o ", tmpZipPath). + Flag("**/*:" + destDir) + rb.Build(pctx, ctx, "repackaging "+destDir, + "Repackaging zip file "+destDir+" for snapshot "+ctx.ModuleName()) + + // Add the repackaged zip file to the files to merge. + s.zipsToMerge = append(s.zipsToMerge, tmpZipPath) +} + func (s *snapshotBuilder) AndroidBpFile() android.GeneratedSnapshotFile { return s.androidBpFile } diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go index 6b4337a04..5e0eb35c7 100644 --- a/sysprop/sysprop_test.go +++ b/sysprop/sysprop_test.go @@ -56,9 +56,9 @@ func testContext(config android.Config, bp string, fs map[string][]byte) *android.TestContext { ctx := android.NewTestArchContext() - ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory)) - ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory)) - ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory)) + ctx.RegisterModuleType("android_app", java.AndroidAppFactory) + ctx.RegisterModuleType("java_library", java.LibraryFactory) + ctx.RegisterModuleType("java_system_modules", java.SystemModulesFactory) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) @@ -66,14 +66,14 @@ func testContext(config android.Config, bp string, ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel() }) - ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) - ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory)) - ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(cc.LibraryFactory)) - ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) - ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) - ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) + ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) + ctx.RegisterModuleType("cc_library_static", cc.LibraryFactory) + ctx.RegisterModuleType("cc_object", cc.ObjectFactory) + ctx.RegisterModuleType("llndk_library", cc.LlndkLibraryFactory) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("image", cc.ImageMutator).Parallel() + ctx.BottomUp("image", android.ImageMutator).Parallel() ctx.BottomUp("link", cc.LinkageMutator).Parallel() ctx.BottomUp("vndk", cc.VndkMutator).Parallel() ctx.BottomUp("version", cc.VersionMutator).Parallel() @@ -81,7 +81,7 @@ func testContext(config android.Config, bp string, ctx.BottomUp("sysprop", cc.SyspropMutator).Parallel() }) - ctx.RegisterModuleType("sysprop_library", android.ModuleFactoryAdaptor(syspropLibraryFactory)) + ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory) ctx.Register() diff --git a/xml/xml_test.go b/xml/xml_test.go index f2a440f9a..0a1156670 100644 --- a/xml/xml_test.go +++ b/xml/xml_test.go @@ -50,8 +50,8 @@ func TestMain(m *testing.M) { func testXml(t *testing.T, bp string) *android.TestContext { config := android.TestArchConfig(buildDir, nil) ctx := android.NewTestArchContext() - ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) - ctx.RegisterModuleType("prebuilt_etc_xml", android.ModuleFactoryAdaptor(PrebuiltEtcXmlFactory)) + ctx.RegisterModuleType("prebuilt_etc", android.PrebuiltEtcFactory) + ctx.RegisterModuleType("prebuilt_etc_xml", PrebuiltEtcXmlFactory) ctx.Register() mockFiles := map[string][]byte{ "Android.bp": []byte(bp), |