diff options
35 files changed, 527 insertions, 519 deletions
diff --git a/android/apex.go b/android/apex.go index c1e7a5cd0..4d36a9396 100644 --- a/android/apex.go +++ b/android/apex.go @@ -147,6 +147,13 @@ type ApexTestForInfo struct { var ApexTestForInfoProvider = blueprint.NewMutatorProvider[ApexTestForInfo]("apex_test_for") +// ApexBundleInfo contains information about the dependencies of an apex +type ApexBundleInfo struct { + Contents *ApexContents +} + +var ApexBundleInfoProvider = blueprint.NewMutatorProvider[ApexBundleInfo]("apex_info") + // DepIsInSameApex defines an interface that should be used to determine whether a given dependency // should be considered as part of the same APEX as the current module or not. Note: this was // extracted from ApexModule to make it easier to define custom subsets of the ApexModule interface diff --git a/android/config.go b/android/config.go index eb1e647d4..d94a86f71 100644 --- a/android/config.go +++ b/android/config.go @@ -1309,6 +1309,10 @@ func (c *config) VendorApiLevel() string { return String(c.productVariables.VendorApiLevel) } +func (c *config) VendorApiLevelFrozen() bool { + return c.productVariables.GetBuildFlagBool("RELEASE_BOARD_API_LEVEL_FROZEN") +} + func (c *deviceConfig) Arches() []Arch { var arches []Arch for _, target := range c.config.Targets[Android] { @@ -1970,6 +1974,10 @@ func (c *config) GetBuildFlag(name string) (string, bool) { return val, ok } +func (c *config) UseResourceProcessorByDefault() bool { + return c.productVariables.GetBuildFlagBool("RELEASE_USE_RESOURCE_PROCESSOR_BY_DEFAULT") +} + var ( mainlineApexContributionBuildFlags = []string{ "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", diff --git a/android/team_proto/Android.bp b/android/team_proto/Android.bp index 061e77e03..7e2a4c137 100644 --- a/android/team_proto/Android.bp +++ b/android/team_proto/Android.bp @@ -27,3 +27,17 @@ bootstrap_go_package { "team.pb.go", ], } + +python_library_host { + name: "teams-proto-py", + pkg_path: "teams", + srcs: [ + "team.proto", + ], + libs: [ + "libprotobuf-python", + ], + proto: { + canonical_path_from_root: false, + }, +} diff --git a/apex/apex.go b/apex/apex.go index 5b0def0d8..276ac80d5 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -929,12 +929,6 @@ type DCLAInfo struct { var DCLAInfoProvider = blueprint.NewMutatorProvider[DCLAInfo]("apex_info") -type ApexBundleInfo struct { - Contents *android.ApexContents -} - -var ApexBundleInfoProvider = blueprint.NewMutatorProvider[ApexBundleInfo]("apex_info") - var _ ApexInfoMutator = (*apexBundle)(nil) func (a *apexBundle) ApexVariationName() string { @@ -1035,7 +1029,7 @@ func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) { // The membership information is saved for later access apexContents := android.NewApexContents(contents) - android.SetProvider(mctx, ApexBundleInfoProvider, ApexBundleInfo{ + android.SetProvider(mctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{ Contents: apexContents, }) @@ -1243,7 +1237,7 @@ func apexTestForMutator(mctx android.BottomUpMutatorContext) { if _, ok := mctx.Module().(android.ApexModule); ok { var contents []*android.ApexContents for _, testFor := range mctx.GetDirectDepsWithTag(testForTag) { - abInfo, _ := android.OtherModuleProvider(mctx, testFor, ApexBundleInfoProvider) + abInfo, _ := android.OtherModuleProvider(mctx, testFor, android.ApexBundleInfoProvider) contents = append(contents, abInfo.Contents) } android.SetProvider(mctx, android.ApexTestForInfoProvider, android.ApexTestForInfo{ @@ -1418,7 +1412,7 @@ func (a *apexBundle) TaggedOutputs() map[string]android.Paths { var _ cc.Coverage = (*apexBundle)(nil) // Implements cc.Coverage -func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (a *apexBundle) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return ctx.DeviceConfig().NativeCoverageEnabled() } @@ -2192,7 +2186,7 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, af := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs) af.transitiveDep = true - abInfo, _ := android.ModuleProvider(ctx, ApexBundleInfoProvider) + abInfo, _ := android.ModuleProvider(ctx, android.ApexBundleInfoProvider) if !abInfo.Contents.DirectlyInApex(depName) && (ch.IsStubs() || ch.HasStubsVariants()) { // If the dependency is a stubs lib, don't include it in this APEX, // but make sure that the lib is installed on the device. @@ -2658,7 +2652,7 @@ func (a *apexBundle) checkStaticLinkingToStubLibraries(ctx android.ModuleContext return } - abInfo, _ := android.ModuleProvider(ctx, ApexBundleInfoProvider) + abInfo, _ := android.ModuleProvider(ctx, android.ApexBundleInfoProvider) a.WalkPayloadDeps(ctx, func(ctx android.ModuleContext, from blueprint.Module, to android.ApexModule, externalDep bool) bool { if ccm, ok := to.(*cc.Module); ok { diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index f1e71b05c..778c20a56 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -316,6 +316,7 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ `art-bootclasspath-fragment`, `com.android.art.key`, + `dex2oatd`, }) // Make sure that the source bootclasspath_fragment copies its dex files to the predefined @@ -387,6 +388,7 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ `art-bootclasspath-fragment`, `com.android.art.key`, + `dex2oatd`, `prebuilt_com.android.art`, }) @@ -650,6 +652,7 @@ func TestBootclasspathFragmentContentsNoName(t *testing.T) { }) java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{ + `dex2oatd`, `myapex.key`, `mybootclasspathfragment`, }) diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go index 161941d6e..2bd3159be 100644 --- a/apex/platform_bootclasspath_test.go +++ b/apex/platform_bootclasspath_test.go @@ -155,7 +155,7 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) { info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) for _, category := range java.HiddenAPIFlagFileCategories { - name := category.PropertyName + name := category.PropertyName() message := fmt.Sprintf("category %s", name) filename := strings.ReplaceAll(name, "_", "-") expected := []string{fmt.Sprintf("%s.txt", filename), fmt.Sprintf("bar-%s.txt", filename)} diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 1ec38eb94..551942d31 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -201,6 +201,10 @@ func (p *prebuiltCommon) dexpreoptSystemServerJars(ctx android.ModuleContext) { if !p.hasExportedDeps() { return } + // If this prebuilt apex has not been selected, return + if p.IsHideFromMake() { + return + } // Use apex_name to determine the api domain of this prebuilt apex apexName := p.ApexVariationName() di, err := android.FindDeapexerProviderForModule(ctx) @@ -438,7 +442,7 @@ func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) { // Create contents for the prebuilt_apex and store it away for later use. apexContents := android.NewApexContents(contents) - android.SetProvider(mctx, ApexBundleInfoProvider, ApexBundleInfo{ + android.SetProvider(mctx, android.ApexBundleInfoProvider, android.ApexBundleInfo{ Contents: apexContents, }) diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go index 01629c9d2..6b2c39777 100644 --- a/apex/systemserver_classpath_fragment_test.go +++ b/apex/systemserver_classpath_fragment_test.go @@ -106,6 +106,7 @@ func TestSystemserverclasspathFragmentContents(t *testing.T) { }) java.CheckModuleDependencies(t, ctx, "myapex", "android_common_myapex", []string{ + `dex2oatd`, `myapex.key`, `mysystemserverclasspathfragment`, }) @@ -162,6 +163,7 @@ func TestSystemserverclasspathFragmentNoGeneratedProto(t *testing.T) { }) java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{ + `dex2oatd`, `myapex.key`, `mysystemserverclasspathfragment`, }) @@ -219,6 +221,8 @@ func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) { } func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) { + // TODO(spandandas): Fix the rules for profile guided dexpreopt of deapexed prebuilt jars + t.Skip() result := android.GroupFixturePreparers( prepareForTestWithSystemserverclasspathFragment, prepareForTestWithMyapex, @@ -377,6 +381,8 @@ func TestSystemserverclasspathFragmentStandaloneContents(t *testing.T) { } func TestPrebuiltStandaloneSystemserverclasspathFragmentContents(t *testing.T) { + // TODO(spandandas): Fix the rules for profile guided dexpreopt of deapexed prebuilt jars + t.Skip() result := android.GroupFixturePreparers( prepareForTestWithSystemserverclasspathFragment, prepareForTestWithMyapex, @@ -68,16 +68,14 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) { ctx.TopDown("fuzz_deps", fuzzMutatorDeps) - ctx.BottomUp("coverage", coverageMutator).Parallel() + ctx.Transition("coverage", &coverageTransitionMutator{}) ctx.TopDown("afdo_deps", afdoDepsMutator) ctx.BottomUp("afdo", afdoMutator).Parallel() - ctx.TopDown("orderfile_deps", orderfileDepsMutator) - ctx.BottomUp("orderfile", orderfileMutator).Parallel() + ctx.Transition("orderfile", &orderfileTransitionMutator{}) - ctx.TopDown("lto_deps", ltoDepsMutator) - ctx.BottomUp("lto", ltoMutator).Parallel() + ctx.Transition("lto", <oTransitionMutator{}) ctx.BottomUp("check_linktype", checkLinkTypeMutator).Parallel() ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() @@ -1608,9 +1606,10 @@ func (ctx *moduleContextImpl) useSdk() bool { func (ctx *moduleContextImpl) sdkVersion() string { if ctx.ctx.Device() { - if ctx.useVndk() { + config := ctx.ctx.Config() + if !config.IsVndkDeprecated() && ctx.useVndk() { vndkVer := ctx.mod.VndkVersion() - if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) { + if inList(vndkVer, config.PlatformVersionActiveCodenames()) { return "current" } return vndkVer @@ -1628,6 +1627,17 @@ func (ctx *moduleContextImpl) minSdkVersion() string { if ver == "apex_inherit" || ver == "" { ver = ctx.sdkVersion() } + + if ctx.ctx.Device() { + config := ctx.ctx.Config() + if config.IsVndkDeprecated() && ctx.inVendor() { + // If building for vendor with final API, then use the latest _stable_ API as "current". + if config.VendorApiLevelFrozen() && (ver == "" || ver == "current") { + ver = config.PlatformSdkVersion().String() + } + } + } + // For crt objects, the meaning of min_sdk_version is very different from other types of // module. For them, min_sdk_version defines the oldest version that the build system will // create versioned variants for. For example, if min_sdk_version is 16, then sdk variant of diff --git a/cc/cc_test.go b/cc/cc_test.go index 321bd380b..6cc500b5f 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -43,6 +43,7 @@ var prepareForCcTest = android.GroupFixturePreparers( android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.VendorApiLevel = StringPtr("202404") variables.DeviceVndkVersion = StringPtr("current") + variables.KeepVndk = BoolPtr(true) variables.Platform_vndk_version = StringPtr("29") }), ) @@ -4843,3 +4844,43 @@ func TestImageVariantsWithoutVndk(t *testing.T) { testDepWithVariant("vendor") testDepWithVariant("product") } + +func TestVendorSdkVersionWithoutVndk(t *testing.T) { + t.Parallel() + + bp := ` + cc_library { + name: "libfoo", + srcs: ["libfoo.cc"], + vendor_available: true, + } + + cc_library { + name: "libbar", + srcs: ["libbar.cc"], + vendor_available: true, + min_sdk_version: "29", + } + ` + + ctx := prepareForCcTestWithoutVndk.RunTestWithBp(t, bp) + testSdkVersionFlag := func(module, version string) { + flags := ctx.ModuleForTests(module, "android_vendor_arm64_armv8-a_static").Rule("cc").Args["cFlags"] + android.AssertStringDoesContain(t, "min sdk version", flags, "-target aarch64-linux-android"+version) + } + + testSdkVersionFlag("libfoo", "10000") + testSdkVersionFlag("libbar", "29") + + ctx = android.GroupFixturePreparers( + prepareForCcTestWithoutVndk, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + if variables.BuildFlags == nil { + variables.BuildFlags = make(map[string]string) + } + variables.BuildFlags["RELEASE_BOARD_API_LEVEL_FROZEN"] = "true" + }), + ).RunTestWithBp(t, bp) + testSdkVersionFlag("libfoo", "30") + testSdkVersionFlag("libbar", "29") +} diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index 3d6890cf0..603bc6de7 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -28,13 +28,20 @@ var ( armCflags = []string{ "-fomit-frame-pointer", + // Revert this after b/322359235 is fixed + "-mllvm", "-enable-shrink-wrap=false", } - armCppflags = []string{} + armCppflags = []string{ + // Revert this after b/322359235 is fixed + "-mllvm", "-enable-shrink-wrap=false", + } armLdflags = []string{ "-Wl,--hash-style=gnu", "-Wl,-m,armelf", + // Revert this after b/322359235 is fixed + "-Wl,-mllvm", "-Wl,-enable-shrink-wrap=false", } armLldflags = armLdflags diff --git a/cc/coverage.go b/cc/coverage.go index 393a8a6b4..43f5e0762 100644 --- a/cc/coverage.go +++ b/cc/coverage.go @@ -246,7 +246,7 @@ func SetCoverageProperties(ctx android.BaseModuleContext, properties CoveragePro type UseCoverage interface { android.Module - IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool + IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool } // Coverage is an interface for non-CC modules to implement to be mutated for coverage @@ -258,43 +258,86 @@ type Coverage interface { EnableCoverageIfNeeded() } -func coverageMutator(mctx android.BottomUpMutatorContext) { - if c, ok := mctx.Module().(*Module); ok && c.coverage != nil { - needCoverageVariant := c.coverage.Properties.NeedCoverageVariant - needCoverageBuild := c.coverage.Properties.NeedCoverageBuild - if needCoverageVariant { - m := mctx.CreateVariations("", "cov") +type coverageTransitionMutator struct{} + +var _ android.TransitionMutator = (*coverageTransitionMutator)(nil) +func (c coverageTransitionMutator) Split(ctx android.BaseModuleContext) []string { + if c, ok := ctx.Module().(*Module); ok && c.coverage != nil { + if c.coverage.Properties.NeedCoverageVariant { + return []string{"", "cov"} + } + } else if cov, ok := ctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(ctx) { + // APEX and Rust modules fall here + + // Note: variant "" is also created because an APEX can be depended on by another + // module which are split into "" and "cov" variants. e.g. when cc_test refers + // to an APEX via 'data' property. + return []string{"", "cov"} + } else if cov, ok := ctx.Module().(UseCoverage); ok && cov.IsNativeCoverageNeeded(ctx) { + // Module itself doesn't have to have "cov" variant, but it should use "cov" variants of + // deps. + return []string{"cov"} + } + + return []string{""} +} + +func (c coverageTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { + return sourceVariation +} + +func (c coverageTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { + if c, ok := ctx.Module().(*Module); ok && c.coverage != nil { + if !c.coverage.Properties.NeedCoverageVariant { + return "" + } + } else if cov, ok := ctx.Module().(Coverage); ok { + if !cov.IsNativeCoverageNeeded(ctx) { + return "" + } + } else if cov, ok := ctx.Module().(UseCoverage); ok && cov.IsNativeCoverageNeeded(ctx) { + // Module only has a "cov" variation, so all incoming variations should use "cov". + return "cov" + } else { + return "" + } + + return incomingVariation +} + +func (c coverageTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) { + if c, ok := ctx.Module().(*Module); ok && c.coverage != nil { + if variation == "" && c.coverage.Properties.NeedCoverageVariant { // Setup the non-coverage version and set HideFromMake and // PreventInstall to true. - m[0].(*Module).coverage.Properties.CoverageEnabled = false - m[0].(*Module).coverage.Properties.IsCoverageVariant = false - m[0].(*Module).Properties.HideFromMake = true - m[0].(*Module).Properties.PreventInstall = true - + c.coverage.Properties.CoverageEnabled = false + c.coverage.Properties.IsCoverageVariant = false + c.Properties.HideFromMake = true + c.Properties.PreventInstall = true + } else if variation == "cov" { // The coverage-enabled version inherits HideFromMake, // PreventInstall from the original module. - m[1].(*Module).coverage.Properties.CoverageEnabled = needCoverageBuild - m[1].(*Module).coverage.Properties.IsCoverageVariant = true + c.coverage.Properties.CoverageEnabled = c.coverage.Properties.NeedCoverageBuild + c.coverage.Properties.IsCoverageVariant = true } - } else if cov, ok := mctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(mctx) { + } else if cov, ok := ctx.Module().(Coverage); ok && cov.IsNativeCoverageNeeded(ctx) { // APEX and Rust modules fall here // Note: variant "" is also created because an APEX can be depended on by another // module which are split into "" and "cov" variants. e.g. when cc_test refers // to an APEX via 'data' property. - m := mctx.CreateVariations("", "cov") - m[0].(Coverage).MarkAsCoverageVariant(false) - m[0].(Coverage).SetPreventInstall() - m[0].(Coverage).HideFromMake() - - m[1].(Coverage).MarkAsCoverageVariant(true) - m[1].(Coverage).EnableCoverageIfNeeded() - } else if cov, ok := mctx.Module().(UseCoverage); ok && cov.IsNativeCoverageNeeded(mctx) { + if variation == "" { + cov.MarkAsCoverageVariant(false) + cov.SetPreventInstall() + cov.HideFromMake() + } else if variation == "cov" { + cov.MarkAsCoverageVariant(true) + cov.EnableCoverageIfNeeded() + } + } else if cov, ok := ctx.Module().(UseCoverage); ok && cov.IsNativeCoverageNeeded(ctx) { // Module itself doesn't have to have "cov" variant, but it should use "cov" variants of // deps. - mctx.CreateVariations("cov") - mctx.AliasVariation("cov") } } @@ -15,9 +15,12 @@ package cc import ( - "android/soong/android" + "fmt" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" + + "android/soong/android" ) // LTO (link-time optimization) allows the compiler to optimize and generate @@ -49,11 +52,6 @@ type LTOProperties struct { LtoEnabled bool `blueprint:"mutated"` LtoDefault bool `blueprint:"mutated"` - // Dep properties indicate that this module needs to be built with LTO - // since it is an object dependency of an LTO module. - LtoDep bool `blueprint:"mutated"` - NoLtoDep bool `blueprint:"mutated"` - // Use -fwhole-program-vtables cflag. Whole_program_vtables *bool } @@ -176,86 +174,83 @@ func (lto *lto) Never() bool { return lto != nil && proptools.Bool(lto.Properties.Lto.Never) } -// Propagate lto requirements down from binaries -func ltoDepsMutator(mctx android.TopDownMutatorContext) { - if m, ok := mctx.Module().(*Module); ok { - if m.lto == nil || m.lto.Properties.LtoEnabled == m.lto.Properties.LtoDefault { - return - } - - mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { - tag := mctx.OtherModuleDependencyTag(dep) - libTag, isLibTag := tag.(libraryDependencyTag) +func ltoPropagateViaDepTag(tag blueprint.DependencyTag) bool { + libTag, isLibTag := tag.(libraryDependencyTag) + // Do not recurse down non-static dependencies + if isLibTag { + return libTag.static() + } else { + return tag == objDepTag || tag == reuseObjTag || tag == staticVariantTag + } +} - // Do not recurse down non-static dependencies - if isLibTag { - if !libTag.static() { - return false - } - } else { - if tag != objDepTag && tag != reuseObjTag { - return false - } - } +// ltoTransitionMutator creates LTO variants of cc modules. Variant "" is the default variant, which may +// or may not have LTO enabled depending on the config and the module's type and properties. "lto-thin" or +// "lto-none" variants are created when a module needs to compile in the non-default state for that module. +type ltoTransitionMutator struct{} - if dep, ok := dep.(*Module); ok { - if m.lto.Properties.LtoEnabled { - dep.lto.Properties.LtoDep = true - } else { - dep.lto.Properties.NoLtoDep = true - } - } +const LTO_NONE_VARIATION = "lto-none" +const LTO_THIN_VARIATION = "lto-thin" - // Recursively walk static dependencies - return true - }) - } +func (l *ltoTransitionMutator) Split(ctx android.BaseModuleContext) []string { + return []string{""} } -// Create lto variants for modules that need them -func ltoMutator(mctx android.BottomUpMutatorContext) { - if m, ok := mctx.Module().(*Module); ok && m.lto != nil { - // Create variations for LTO types required as static - // dependencies - variationNames := []string{""} - if m.lto.Properties.LtoDep { - variationNames = append(variationNames, "lto-thin") - } - if m.lto.Properties.NoLtoDep { - variationNames = append(variationNames, "lto-none") +func (l *ltoTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { + if m, ok := ctx.Module().(*Module); ok && m.lto != nil { + if !ltoPropagateViaDepTag(ctx.DepTag()) { + return "" } - if !m.lto.Properties.LtoEnabled { - mctx.SetDependencyVariation("lto-none") + if sourceVariation != "" { + return sourceVariation } + + // Always request an explicit variation, IncomingTransition will rewrite it back to the default variation + // if necessary. if m.lto.Properties.LtoEnabled { - mctx.SetDependencyVariation("lto-thin") + return LTO_THIN_VARIATION + } else { + return LTO_NONE_VARIATION } + } + return "" +} - if len(variationNames) > 1 { - modules := mctx.CreateVariations(variationNames...) - for i, name := range variationNames { - variation := modules[i].(*Module) - // Default module which will be - // installed. Variation set above according to - // explicit LTO properties - if name == "" { - continue - } - - // LTO properties for dependencies - if name == "lto-thin" { - variation.lto.Properties.LtoEnabled = true - } - if name == "lto-none" { - variation.lto.Properties.LtoEnabled = false - } - variation.Properties.PreventInstall = true - variation.Properties.HideFromMake = true - variation.lto.Properties.LtoDefault = m.lto.Properties.LtoDefault - variation.lto.Properties.LtoDep = false - variation.lto.Properties.NoLtoDep = false - } +func (l *ltoTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { + if m, ok := ctx.Module().(*Module); ok && m.lto != nil { + if m.lto.Never() { + return "" + } + // Rewrite explicit variations back to the default variation if the default variation matches. + if incomingVariation == LTO_THIN_VARIATION && m.lto.Properties.LtoDefault { + return "" + } else if incomingVariation == LTO_NONE_VARIATION && !m.lto.Properties.LtoDefault { + return "" + } + return incomingVariation + } + return "" +} + +func (l *ltoTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) { + // Default module which will be installed. Variation set above according to explicit LTO properties. + if variation == "" { + return + } + + if m, ok := ctx.Module().(*Module); ok && m.lto != nil { + // Non-default variation, set the LTO properties to match the variation. + switch variation { + case LTO_THIN_VARIATION: + m.lto.Properties.LtoEnabled = true + case LTO_NONE_VARIATION: + m.lto.Properties.LtoEnabled = false + default: + panic(fmt.Errorf("unknown variation %s", variation)) } + // Non-default variations are never installed. + m.Properties.PreventInstall = true + m.Properties.HideFromMake = true } } diff --git a/cc/lto_test.go b/cc/lto_test.go index 7b7fe8c8a..e4b5a3a01 100644 --- a/cc/lto_test.go +++ b/cc/lto_test.go @@ -146,8 +146,9 @@ func TestThinLtoOnlyOnStaticDep(t *testing.T) { t.Errorf("'root' missing dependency on the default variant of 'foo'") } - if !hasDep(result, libRootLtoNever, libFoo.Module()) { - t.Errorf("'root_no_lto' missing dependency on the default variant of 'foo'") + libFooNoLto := result.ModuleForTests("foo", "android_arm64_armv8-a_static_lto-none") + if !hasDep(result, libRootLtoNever, libFooNoLto.Module()) { + t.Errorf("'root_no_lto' missing dependency on the lto_none variant of 'foo'") } libFooCFlags := libFoo.Rule("cc").Args["cFlags"] diff --git a/cc/object_test.go b/cc/object_test.go index e6a3fdd45..c0d133190 100644 --- a/cc/object_test.go +++ b/cc/object_test.go @@ -22,7 +22,7 @@ import ( ) func TestMinSdkVersionsOfCrtObjects(t *testing.T) { - ctx := testCc(t, ` + bp := ` cc_object { name: "crt_foo", srcs: ["foo.c"], @@ -30,8 +30,8 @@ func TestMinSdkVersionsOfCrtObjects(t *testing.T) { stl: "none", min_sdk_version: "28", vendor_available: true, - }`) - + } + ` variants := []struct { variant string num string @@ -43,11 +43,17 @@ func TestMinSdkVersionsOfCrtObjects(t *testing.T) { {"android_arm64_armv8-a_sdk_current", "10000"}, {"android_vendor.29_arm64_armv8-a", "29"}, } + + ctx := prepareForCcTest.RunTestWithBp(t, bp) for _, v := range variants { cflags := ctx.ModuleForTests("crt_foo", v.variant).Rule("cc").Args["cFlags"] expected := "-target aarch64-linux-android" + v.num + " " android.AssertStringDoesContain(t, "cflag", cflags, expected) } + ctx = prepareForCcTestWithoutVndk.RunTestWithBp(t, bp) + android.AssertStringDoesContain(t, "cflag", + ctx.ModuleForTests("crt_foo", "android_vendor_arm64_armv8-a").Rule("cc").Args["cFlags"], + "-target aarch64-linux-android10000 ") } func TestUseCrtObjectOfCorrectVersion(t *testing.T) { diff --git a/cc/orderfile.go b/cc/orderfile.go index 9192e8168..38b89059b 100644 --- a/cc/orderfile.go +++ b/cc/orderfile.go @@ -20,6 +20,8 @@ package cc import ( "fmt" + "github.com/google/blueprint" + "android/soong/android" ) @@ -190,66 +192,61 @@ func (orderfile *orderfile) flags(ctx ModuleContext, flags Flags) Flags { return flags } -// Propagate profile orderfile flags down from binaries and shared libraries -// We do not allow propagation for load flags because the orderfile is specific -// to the module (binary / shared library) -func orderfileDepsMutator(mctx android.TopDownMutatorContext) { - if m, ok := mctx.Module().(*Module); ok { - if !m.orderfile.orderfileLinkEnabled() { - return - } - mctx.WalkDeps(func(dep android. - Module, parent android.Module) bool { - tag := mctx.OtherModuleDependencyTag(dep) - libTag, isLibTag := tag.(libraryDependencyTag) - - // Do not recurse down non-static dependencies - if isLibTag { - if !libTag.static() { - return false - } - } else { - if tag != objDepTag && tag != reuseObjTag { - return false - } - } - - if dep, ok := dep.(*Module); ok { - if m.orderfile.Properties.OrderfileInstrLink { - dep.orderfile.Properties.OrderfileInstrLink = true - } - } - - return true - }) +func orderfilePropagateViaDepTag(tag blueprint.DependencyTag) bool { + libTag, isLibTag := tag.(libraryDependencyTag) + // Do not recurse down non-static dependencies + if isLibTag { + return libTag.static() + } else { + return tag == objDepTag || tag == reuseObjTag || tag == staticVariantTag } } -// Create orderfile variants for modules that need them -func orderfileMutator(mctx android.BottomUpMutatorContext) { - if m, ok := mctx.Module().(*Module); ok && m.orderfile != nil { - if !m.static() && m.orderfile.orderfileEnabled() { - mctx.SetDependencyVariation("orderfile") - return +// orderfileTransitionMutator creates orderfile variants of cc modules. +type orderfileTransitionMutator struct{} + +const ORDERFILE_VARIATION = "orderfile" + +func (o *orderfileTransitionMutator) Split(ctx android.BaseModuleContext) []string { + return []string{""} +} + +func (o *orderfileTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { + if m, ok := ctx.Module().(*Module); ok && m.orderfile != nil { + if !orderfilePropagateViaDepTag(ctx.DepTag()) { + return "" } - variationNames := []string{""} - if m.orderfile.Properties.OrderfileInstrLink { - variationNames = append(variationNames, "orderfile") + if sourceVariation != "" { + return sourceVariation } - if len(variationNames) > 1 { - modules := mctx.CreateVariations(variationNames...) - for i, name := range variationNames { - if name == "" { - continue - } - variation := modules[i].(*Module) - variation.Properties.PreventInstall = true - variation.Properties.HideFromMake = true - variation.orderfile.Properties.ShouldProfileModule = true - variation.orderfile.Properties.OrderfileLoad = false - } + // Propagate profile orderfile flags down from binaries and shared libraries + if m.orderfile.orderfileLinkEnabled() { + return ORDERFILE_VARIATION } } + return "" +} + +func (o *orderfileTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { + if m, ok := ctx.Module().(*Module); ok && m.orderfile != nil { + return incomingVariation + } + return "" +} + +func (o *orderfileTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) { + if variation == "" { + return + } + + if m, ok := ctx.Module().(*Module); ok && m.orderfile != nil { + m.Properties.PreventInstall = true + m.Properties.HideFromMake = true + m.orderfile.Properties.ShouldProfileModule = true + // We do not allow propagation for load flags because the orderfile is specific + // to the module (binary / shared library) + m.orderfile.Properties.OrderfileLoad = false + } } diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index 3fb445480..6d1caf978 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -651,7 +651,7 @@ var bpDepsTemplate = template.Must(template.New("bp").Parse(` {{- end}} ], {{- end}} - java_version: "1.7", + java_version: "1.8", } `)) diff --git a/cmd/pom2mk/pom2mk.go b/cmd/pom2mk/pom2mk.go index b3471556a..5ca770eca 100644 --- a/cmd/pom2mk/pom2mk.go +++ b/cmd/pom2mk/pom2mk.go @@ -262,7 +262,7 @@ LOCAL_STATIC_ANDROID_LIBRARIES :={{if .IsAar}} \ {{.MkName}}-nodeps{{end}}{{range .MkAarDeps}} \ {{.}}{{end}} LOCAL_JAR_EXCLUDE_FILES := none -LOCAL_JAVA_LANGUAGE_VERSION := 1.7 +LOCAL_JAVA_LANGUAGE_VERSION := 1.8 LOCAL_USE_AAPT2 := true include $(BUILD_STATIC_JAVA_LIBRARY) `)) diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index 7b207d6ce..2f6476c82 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -512,6 +512,6 @@ func sha1sum(values []string) string { var _ cc.UseCoverage = (*filesystem)(nil) -func (*filesystem) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (*filesystem) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } diff --git a/genrule/allowlists.go b/genrule/allowlists.go index 33836509a..60b1366d0 100644 --- a/genrule/allowlists.go +++ b/genrule/allowlists.go @@ -15,12 +15,6 @@ package genrule var ( - DepfileAllowList = []string{ - // go/keep-sorted start - "depfile_allowed_for_test", - // go/keep-sorted end - } - SandboxingDenyModuleList = []string{ // go/keep-sorted start "aidl_camera_build_version", diff --git a/genrule/genrule.go b/genrule/genrule.go index fbda07483..6f6608817 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -124,14 +124,10 @@ type generatorProperties struct { // $(locations <label>): the paths to the tools, tool_files, inputs or outputs with name <label>. Use $(locations) if <label> refers to a rule that outputs two or more files. // $(in): one or more input files. // $(out): a single output file. - // $(depfile): a file to which dependencies will be written, if the depfile property is set to true. // $(genDir): the sandbox directory for this tool; contains $(out). // $$: a literal $ Cmd *string - // Enable reading a file containing dependencies in gcc format after the command completes - Depfile *bool - // name of the modules (if any) that produces the host executable. Leave empty for // prebuilts or scripts that do not need a module to build them. Tools []string @@ -194,10 +190,8 @@ type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles androi type generateTask struct { in android.Paths out android.WritablePaths - depFile android.WritablePath copyTo android.WritablePaths // For gensrcs to set on gensrcsMerge rule. genDir android.WritablePath - extraTools android.Paths // dependencies on tools used by the generator extraInputs map[string][]string cmd string @@ -448,8 +442,6 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { addLocationLabel(out.Rel(), outputLocation{out}) } - referencedDepfile := false - rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) { // report the error directly without returning an error to android.Expand to catch multiple errors in a // single run @@ -481,12 +473,6 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { sandboxOuts = append(sandboxOuts, cmd.PathForOutput(out)) } return strings.Join(proptools.ShellEscapeList(sandboxOuts), " "), nil - case "depfile": - referencedDepfile = true - if !Bool(g.properties.Depfile) { - return reportError("$(depfile) used without depfile property") - } - return "__SBOX_DEPFILE__", nil case "genDir": return proptools.ShellEscape(cmd.PathForOutput(task.genDir)), nil default: @@ -526,10 +512,6 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { return } - if Bool(g.properties.Depfile) && !referencedDepfile { - ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd") - return - } g.rawCommands = append(g.rawCommands, rawCommand) cmd.Text(rawCommand) @@ -538,11 +520,7 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { cmd.ImplicitOutputs(task.out) cmd.Implicits(task.in) cmd.ImplicitTools(tools) - cmd.ImplicitTools(task.extraTools) cmd.ImplicitPackagedTools(packagedTools) - if Bool(g.properties.Depfile) { - cmd.ImplicitDepFile(task.depFile) - } // Create the rule to run the genrule command inside sbox. rule.Build(name, desc) @@ -583,19 +561,6 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { } func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { - // Allowlist genrule to use depfile until we have a solution to remove it. - // TODO(b/307824623): Remove depfile property - if Bool(g.properties.Depfile) { - sandboxingAllowlistSets := getSandboxingAllowlistSets(ctx) - if ctx.DeviceConfig().GenruleSandboxing() && !sandboxingAllowlistSets.depfileAllowSet[g.Name()] { - ctx.PropertyErrorf( - "depfile", - "Deprecated because with genrule sandboxing, dependencies must be known before the action is run "+ - "in order to add them to the sandbox. "+ - "Please specify the dependencies explicitly so that there is no need to use depfile.") - } - } - g.generateCommonBuildActions(ctx) // For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of @@ -721,7 +686,6 @@ func NewGenSrcs() *Module { for i, shard := range shards { var commands []string var outFiles android.WritablePaths - var commandDepFiles []string var copyTo android.WritablePaths // When sharding is enabled (i.e. len(shards) > 1), the sbox rules for each @@ -761,12 +725,6 @@ func NewGenSrcs() *Module { return in.String(), nil case "out": return rule.Command().PathForOutput(outFile), nil - case "depfile": - // Generate a depfile for each output file. Store the list for - // later in order to combine them all into a single depfile. - depFile := rule.Command().PathForOutput(outFile.ReplaceExtension(ctx, "d")) - commandDepFiles = append(commandDepFiles, depFile) - return depFile, nil default: return "$(" + name + ")", nil } @@ -781,30 +739,14 @@ func NewGenSrcs() *Module { } fullCommand := strings.Join(commands, " && ") - var outputDepfile android.WritablePath - var extraTools android.Paths - if len(commandDepFiles) > 0 { - // Each command wrote to a depfile, but ninja can only handle one - // depfile per rule. Use the dep_fixer tool at the end of the - // command to combine all the depfiles into a single output depfile. - outputDepfile = android.PathForModuleGen(ctx, genSubDir, "gensrcs.d") - depFixerTool := ctx.Config().HostToolPath(ctx, "dep_fixer") - fullCommand += fmt.Sprintf(" && %s -o $(depfile) %s", - rule.Command().PathForTool(depFixerTool), - strings.Join(commandDepFiles, " ")) - extraTools = append(extraTools, depFixerTool) - } - generateTasks = append(generateTasks, generateTask{ - in: shard, - out: outFiles, - depFile: outputDepfile, - copyTo: copyTo, - genDir: genDir, - cmd: fullCommand, - shard: i, - shards: len(shards), - extraTools: extraTools, + in: shard, + out: outFiles, + copyTo: copyTo, + genDir: genDir, + cmd: fullCommand, + shard: i, + shards: len(shards), extraInputs: map[string][]string{ "data": properties.Data, }, @@ -843,20 +785,14 @@ func NewGenRule() *Module { taskGenerator := func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask { outs := make(android.WritablePaths, len(properties.Out)) - var depFile android.WritablePath for i, out := range properties.Out { - outPath := android.PathForModuleGen(ctx, out) - if i == 0 { - depFile = outPath.ReplaceExtension(ctx, "d") - } - outs[i] = outPath + outs[i] = android.PathForModuleGen(ctx, out) } return []generateTask{{ - in: srcFiles, - out: outs, - depFile: depFile, - genDir: android.PathForModuleGen(ctx), - cmd: rawCommand, + in: srcFiles, + out: outs, + genDir: android.PathForModuleGen(ctx), + cmd: rawCommand, }} } @@ -907,22 +843,18 @@ var sandboxingAllowlistKey = android.NewOnceKey("genruleSandboxingAllowlistKey") type sandboxingAllowlistSets struct { sandboxingDenyModuleSet map[string]bool sandboxingDenyPathSet map[string]bool - depfileAllowSet map[string]bool } func getSandboxingAllowlistSets(ctx android.PathContext) *sandboxingAllowlistSets { return ctx.Config().Once(sandboxingAllowlistKey, func() interface{} { sandboxingDenyModuleSet := map[string]bool{} sandboxingDenyPathSet := map[string]bool{} - depfileAllowSet := map[string]bool{} - android.AddToStringSet(sandboxingDenyModuleSet, append(DepfileAllowList, SandboxingDenyModuleList...)) + android.AddToStringSet(sandboxingDenyModuleSet, SandboxingDenyModuleList) android.AddToStringSet(sandboxingDenyPathSet, SandboxingDenyPathList) - android.AddToStringSet(depfileAllowSet, DepfileAllowList) return &sandboxingAllowlistSets{ sandboxingDenyModuleSet: sandboxingDenyModuleSet, sandboxingDenyPathSet: sandboxingDenyPathSet, - depfileAllowSet: depfileAllowSet, } }).(*sandboxingAllowlistSets) } diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index fa0ee17c0..2dc6a7954 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -287,16 +287,6 @@ func TestGenruleCmd(t *testing.T) { expect: "echo foo > __SBOX_SANDBOX_DIR__/out/out2", }, { - name: "depfile", - moduleName: "depfile_allowed_for_test", - prop: ` - out: ["out"], - depfile: true, - cmd: "echo foo > $(out) && touch $(depfile)", - `, - expect: "echo foo > __SBOX_SANDBOX_DIR__/out/out && touch __SBOX_DEPFILE__", - }, - { name: "gendir", prop: ` out: ["out"], @@ -392,24 +382,6 @@ func TestGenruleCmd(t *testing.T) { err: `unknown variable '$(foo)'`, }, { - name: "error depfile", - prop: ` - out: ["out"], - cmd: "echo foo > $(out) && touch $(depfile)", - `, - err: "$(depfile) used without depfile property", - }, - { - name: "error no depfile", - moduleName: "depfile_allowed_for_test", - prop: ` - out: ["out"], - depfile: true, - cmd: "echo foo > $(out)", - `, - err: "specified depfile=true but did not include a reference to '${depfile}' in cmd", - }, - { name: "error no out", prop: ` cmd: "echo foo > $(out)", @@ -695,60 +667,6 @@ func TestGenSrcs(t *testing.T) { } } -func TestGenruleAllowlistingDepfile(t *testing.T) { - tests := []struct { - name string - prop string - err string - moduleName string - }{ - { - name: `error when module is not allowlisted`, - prop: ` - depfile: true, - cmd: "cat $(in) > $(out) && cat $(depfile)", - `, - err: "depfile: Deprecated because with genrule sandboxing, dependencies must be known before the action is run in order to add them to the sandbox", - }, - { - name: `no error when module is allowlisted`, - prop: ` - depfile: true, - cmd: "cat $(in) > $(out) && cat $(depfile)", - `, - moduleName: `depfile_allowed_for_test`, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - moduleName := "foo" - if test.moduleName != "" { - moduleName = test.moduleName - } - bp := fmt.Sprintf(` - gensrcs { - name: "%s", - srcs: ["data.txt"], - %s - }`, moduleName, test.prop) - - var expectedErrors []string - if test.err != "" { - expectedErrors = append(expectedErrors, test.err) - } - android.GroupFixturePreparers( - prepareForGenRuleTest, - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.GenruleSandboxing = proptools.BoolPtr(true) - }), - ). - ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(expectedErrors)). - RunTestWithBp(t, bp) - }) - - } -} - func TestGenruleDefaults(t *testing.T) { bp := ` genrule_defaults { diff --git a/java/aar.go b/java/aar.go index b162ef639..f61fc8374 100644 --- a/java/aar.go +++ b/java/aar.go @@ -159,8 +159,8 @@ func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { } } -func (a *aapt) useResourceProcessorBusyBox() bool { - return BoolDefault(a.aaptProperties.Use_resource_processor, false) +func (a *aapt) useResourceProcessorBusyBox(ctx android.BaseModuleContext) bool { + return BoolDefault(a.aaptProperties.Use_resource_processor, ctx.Config().UseResourceProcessorByDefault()) } func (a *aapt) filterProduct() string { @@ -414,7 +414,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio linkFlags = append(linkFlags, "--static-lib") } - if a.isLibrary && a.useResourceProcessorBusyBox() { + if a.isLibrary && a.useResourceProcessorBusyBox(ctx) { // When building an android_library using ResourceProcessorBusyBox the resources are merged into // package-res.apk with --merge-only, but --no-static-lib-packages is not used so that R.txt only // contains resources from this library. @@ -453,7 +453,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio // of transitiveStaticLibs. transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages()) - if a.isLibrary && a.useResourceProcessorBusyBox() { + if a.isLibrary && a.useResourceProcessorBusyBox(ctx) { // When building an android_library with ResourceProcessorBusyBox enabled treat static library dependencies // as imports. The resources from dependencies will not be merged into this module's package-res.apk, and // instead modules depending on this module will reference package-res.apk from all transitive static @@ -515,7 +515,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio }) } - if !a.useResourceProcessorBusyBox() { + if !a.useResourceProcessorBusyBox(ctx) { // the subdir "android" is required to be filtered by package names srcJar = android.PathForModuleGen(ctx, "android", "R.srcjar") } @@ -542,7 +542,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio a.assetPackage = android.OptionalPathForPath(assets) } - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { rJar := android.PathForModuleOut(ctx, "busybox/R.jar") resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary, a.aaptProperties.Aaptflags) aapt2ExtractExtraPackages(ctx, extraPackages, rJar) @@ -577,7 +577,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio rJar: a.rJar, assets: a.assetPackage, - usedResourceProcessor: a.useResourceProcessorBusyBox(), + usedResourceProcessor: a.useResourceProcessorBusyBox(ctx), }). Transitive(staticResourcesNodesDepSet).Build() a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL). @@ -823,7 +823,7 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) ctx.CheckbuildFile(a.aapt.proguardOptionsFile) ctx.CheckbuildFile(a.aapt.exportPackage) - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { ctx.CheckbuildFile(a.aapt.rJar) } else { ctx.CheckbuildFile(a.aapt.aaptSrcJar) @@ -849,7 +849,7 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) var extraSrcJars android.Paths var extraCombinedJars android.Paths var extraClasspathJars android.Paths - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { // When building a library with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox for this // library and each of the transitive static android_library dependencies has already created an // R.class file for the appropriate package. Add all of those R.class files to the classpath. @@ -889,7 +889,7 @@ func (a *AndroidLibrary) IDEInfo(dpInfo *android.IdeInfo) { } func (a *aapt) IDEInfo(dpInfo *android.IdeInfo) { - if a.useResourceProcessorBusyBox() { + if a.rJar != nil { dpInfo.Jars = append(dpInfo.Jars, a.rJar.String()) } } diff --git a/java/app.go b/java/app.go index cb05807b8..0c56d81fc 100755 --- a/java/app.go +++ b/java/app.go @@ -431,7 +431,7 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { return false } - return shouldUncompressDex(ctx, &a.dexpreopter) + return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) } func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { @@ -588,7 +588,7 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) (android.Path, a var extraSrcJars android.Paths var extraClasspathJars android.Paths var extraCombinedJars android.Paths - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { // When building an app with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox has already // created R.class files that provide IDs for resources in busybox/R.jar. Pass that file in the // classpath when compiling everything else, and add it to the final classes jar. @@ -1108,7 +1108,7 @@ func (a *AndroidApp) Privileged() bool { return Bool(a.appProperties.Privileged) } -func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } diff --git a/java/app_import.go b/java/app_import.go index 5f20fdd05..12ead0aa2 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -246,7 +246,7 @@ func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { return ctx.Config().UncompressPrivAppDex() } - return shouldUncompressDex(ctx, &a.dexpreopter) + return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) } func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -324,7 +324,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk) } - a.dexpreopter.dexpreopt(ctx, jnisUncompressed) + a.dexpreopter.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), jnisUncompressed) if a.dexpreopter.uncompressedDex { dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk") ctx.Build(pctx, android.BuildParams{ diff --git a/java/base.go b/java/base.go index 1ac3d30a6..e52ceddf7 100644 --- a/java/base.go +++ b/java/base.go @@ -1626,7 +1626,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) // Dexpreopting - j.dexpreopt(ctx, dexOutputFile) + j.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexOutputFile) outputFile = dexOutputFile } else { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index c89c64358..2c13d99e9 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -949,7 +949,7 @@ func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android. builder.CopyToSnapshot(p, dest) dests = append(dests, dest) } - hiddenAPISet.AddProperty(category.PropertyName, dests) + hiddenAPISet.AddProperty(category.PropertyName(), dests) } } } diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 95cd4a922..8bc0a7ef6 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -467,10 +467,10 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) for _, c := range HiddenAPIFlagFileCategories { expectedMaxTargetQPaths := []string(nil) - if c.PropertyName == "max_target_q" { + if c.PropertyName() == "max_target_q" { expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"} } - android.AssertPathsRelativeToTopEquals(t, c.PropertyName, expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) + android.AssertPathsRelativeToTopEquals(t, c.PropertyName(), expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) } // Make sure that the signature-patterns.csv is passed all the appropriate package properties diff --git a/java/dexpreopt.go b/java/dexpreopt.go index bd3cce412..4c0a0a155 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -29,7 +29,7 @@ type DexpreopterInterface interface { IsInstallable() bool // True if dexpreopt is disabled for the java module. - dexpreoptDisabled(ctx android.BaseModuleContext) bool + dexpreoptDisabled(ctx android.BaseModuleContext, libraryName string) bool // If the java module is to be installed into an APEX, this list contains information about the // dexpreopt outputs to be installed on devices. Note that these dexpreopt outputs are installed @@ -182,15 +182,9 @@ func forPrebuiltApex(ctx android.BaseModuleContext) bool { return apexInfo.ForPrebuiltApex } -func moduleName(ctx android.BaseModuleContext) string { - // Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not - // expected by dexpreopter. - return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()) -} - // Returns whether dexpreopt is applicable to the module. // When it returns true, neither profile nor dexpreopt artifacts will be generated. -func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { +func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName string) bool { if !ctx.Device() { return true } @@ -213,11 +207,20 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { return true } + if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex { + // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes + return false + } + global := dexpreopt.GetGlobalConfig(ctx) - isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) - if isApexVariant(ctx) { - // Don't preopt APEX variant module unless the module is an APEX system server jar. + // Use the libName argument to determine if the library being dexpreopt'd is a system server jar + // ctx.ModuleName() is not safe. In case of prebuilt apexes, the dexpreopt rules of system server jars + // are created in the ctx object of the top-level prebuilt apex. + isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(libName) + + if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex || isApexVariant(ctx) { + // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes if !isApexSystemServerJar { return true } @@ -234,14 +237,20 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { } func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) { - if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) || !dexpreopt.IsDex2oatNeeded(ctx) { + if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex && dexpreopt.IsDex2oatNeeded(ctx) { + // prebuilt apexes can genererate rules to dexpreopt deapexed jars + // Add a dex2oat dep aggressively on _every_ apex module + dexpreopt.RegisterToolDeps(ctx) + return + } + if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())) || !dexpreopt.IsDex2oatNeeded(ctx) { return } dexpreopt.RegisterToolDeps(ctx) } -func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool { - return dexpreopt.OdexOnSystemOtherByName(moduleName(ctx), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) +func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, libName string, installPath android.InstallPath) bool { + return dexpreopt.OdexOnSystemOtherByName(libName, android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) } // Returns the install path of the dex jar of a module. @@ -252,13 +261,13 @@ func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath a // This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a // system server jar, which is fine because we currently only preopt system server jars for APEXes. func (d *dexpreopter) getInstallPath( - ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath { + ctx android.ModuleContext, libName string, defaultInstallPath android.InstallPath) android.InstallPath { global := dexpreopt.GetGlobalConfig(ctx) - if global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) { - dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, moduleName(ctx)) + if global.AllApexSystemServerJars(ctx).ContainsJar(libName) { + dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, libName) return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/")) } - if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) && + if !d.dexpreoptDisabled(ctx, libName) && isApexVariant(ctx) && filepath.Base(defaultInstallPath.PartitionDir()) != "apex" { ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt") } @@ -273,10 +282,10 @@ func (d *Dexpreopter) DexpreoptPrebuiltApexSystemServerJars(ctx android.ModuleCo d.installPath = android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexpreopt.GetSystemServerDexLocation(ctx, dc, libraryName), "/")) // generate the rules for creating the .odex and .vdex files for this system server jar dexJarFile := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName)) - d.dexpreopt(ctx, dexJarFile) + d.dexpreopt(ctx, libraryName, dexJarFile) } -func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) { +func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJarFile android.WritablePath) { global := dexpreopt.GetGlobalConfig(ctx) // TODO(b/148690468): The check on d.installPath is to bail out in cases where @@ -289,7 +298,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) - providesUsesLib := moduleName(ctx) + providesUsesLib := libName if ulib, ok := ctx.Module().(ProvidesUsesLib); ok { name := ulib.ProvidesUsesLib() if name != nil { @@ -299,11 +308,11 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr // If it is test, make config files regardless of its dexpreopt setting. // The config files are required for apps defined in make which depend on the lib. - if d.isTest && d.dexpreoptDisabled(ctx) { + if d.isTest && d.dexpreoptDisabled(ctx, libName) { return } - isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(moduleName(ctx)) + isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(libName) bootImage := defaultBootImageConfig(ctx) // When `global.PreoptWithUpdatableBcp` is true, `bcpForDexpreopt` below includes the mainline @@ -322,7 +331,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr targets = append(targets, target) } } - if isSystemServerJar && moduleName(ctx) != "com.android.location.provider" { + if isSystemServerJar && libName != "com.android.location.provider" { // If the module is a system server jar, only preopt for the primary arch because the jar can // only be loaded by system server. "com.android.location.provider" is a special case because // it's also used by apps as a shared library. @@ -358,7 +367,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr profileIsTextListing = true } else if global.ProfileDir != "" { profileClassListing = android.ExistentPathForSource(ctx, - global.ProfileDir, moduleName(ctx)+".prof") + global.ProfileDir, libName+".prof") } } @@ -370,9 +379,9 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr // Full dexpreopt config, used to create dexpreopt build rules. dexpreoptConfig := &dexpreopt.ModuleConfig{ - Name: moduleName(ctx), + Name: libName, DexLocation: dexLocation, - BuildPath: android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, moduleName(ctx)+".jar").OutputPath, + BuildPath: android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, libName+".jar").OutputPath, DexPath: dexJarFile, ManifestPath: android.OptionalPathForPath(d.manifestFile), UncompressedDex: d.uncompressedDex, @@ -405,7 +414,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr d.configPath = android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, "dexpreopt.config") dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath) - if d.dexpreoptDisabled(ctx) { + if d.dexpreoptDisabled(ctx, libName) { return } @@ -476,7 +485,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr // The installs will be handled by Make as sub-modules of the java library. d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{ name: arch + "-" + installBase, - moduleName: dexJarStem, + moduleName: libName, outputPathOnHost: install.From, installDirOnDevice: installPath, installFileOnDevice: installBase, diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 3c7cf3ab6..e4beb5e55 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -435,122 +435,118 @@ type HiddenAPIFlagFileProperties struct { } } -type hiddenAPIFlagFileCategory struct { - // PropertyName is the name of the property for this category. - PropertyName string +type hiddenAPIFlagFileCategory int - // propertyValueReader retrieves the value of the property for this category from the set of - // properties. - propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string +const ( + // The flag file category for removed members of the API. + // + // This is extracted from HiddenAPIFlagFileCategories as it is needed to add the dex signatures + // list of removed API members that are generated automatically from the removed.txt files provided + // by API stubs. + hiddenAPIFlagFileCategoryRemoved hiddenAPIFlagFileCategory = iota + hiddenAPIFlagFileCategoryUnsupported + hiddenAPIFlagFileCategoryMaxTargetRLowPriority + hiddenAPIFlagFileCategoryMaxTargetQ + hiddenAPIFlagFileCategoryMaxTargetP + hiddenAPIFlagFileCategoryMaxTargetOLowPriority + hiddenAPIFlagFileCategoryBlocked + hiddenAPIFlagFileCategoryUnsupportedPackages +) - // commandMutator adds the appropriate command line options for this category to the supplied - // command - commandMutator func(command *android.RuleBuilderCommand, path android.Path) +func (c hiddenAPIFlagFileCategory) PropertyName() string { + switch c { + case hiddenAPIFlagFileCategoryRemoved: + return "removed" + case hiddenAPIFlagFileCategoryUnsupported: + return "unsupported" + case hiddenAPIFlagFileCategoryMaxTargetRLowPriority: + return "max_target_r_low_priority" + case hiddenAPIFlagFileCategoryMaxTargetQ: + return "max_target_q" + case hiddenAPIFlagFileCategoryMaxTargetP: + return "max_target_p" + case hiddenAPIFlagFileCategoryMaxTargetOLowPriority: + return "max_target_o_low_priority" + case hiddenAPIFlagFileCategoryBlocked: + return "blocked" + case hiddenAPIFlagFileCategoryUnsupportedPackages: + return "unsupported_packages" + default: + panic(fmt.Sprintf("Unknown hidden api flag file category type: %d", c)) + } } -// The flag file category for removed members of the API. -// -// This is extracted from HiddenAPIFlagFileCategories as it is needed to add the dex signatures -// list of removed API members that are generated automatically from the removed.txt files provided -// by API stubs. -var hiddenAPIRemovedFlagFileCategory = &hiddenAPIFlagFileCategory{ - // See HiddenAPIFlagFileProperties.Removed - PropertyName: "removed", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { +// propertyValueReader retrieves the value of the property for this category from the set of properties. +func (c hiddenAPIFlagFileCategory) propertyValueReader(properties *HiddenAPIFlagFileProperties) []string { + switch c { + case hiddenAPIFlagFileCategoryRemoved: return properties.Hidden_api.Removed - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") - }, + case hiddenAPIFlagFileCategoryUnsupported: + return properties.Hidden_api.Unsupported + case hiddenAPIFlagFileCategoryMaxTargetRLowPriority: + return properties.Hidden_api.Max_target_r_low_priority + case hiddenAPIFlagFileCategoryMaxTargetQ: + return properties.Hidden_api.Max_target_q + case hiddenAPIFlagFileCategoryMaxTargetP: + return properties.Hidden_api.Max_target_p + case hiddenAPIFlagFileCategoryMaxTargetOLowPriority: + return properties.Hidden_api.Max_target_o_low_priority + case hiddenAPIFlagFileCategoryBlocked: + return properties.Hidden_api.Blocked + case hiddenAPIFlagFileCategoryUnsupportedPackages: + return properties.Hidden_api.Unsupported_packages + default: + panic(fmt.Sprintf("Unknown hidden api flag file category type: %d", c)) + } } -type hiddenAPIFlagFileCategories []*hiddenAPIFlagFileCategory - -func (c hiddenAPIFlagFileCategories) byProperty(name string) *hiddenAPIFlagFileCategory { - for _, category := range c { - if category.PropertyName == name { - return category - } +// commandMutator adds the appropriate command line options for this category to the supplied command +func (c hiddenAPIFlagFileCategory) commandMutator(command *android.RuleBuilderCommand, path android.Path) { + switch c { + case hiddenAPIFlagFileCategoryRemoved: + command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") + case hiddenAPIFlagFileCategoryUnsupported: + command.FlagWithInput("--unsupported ", path) + case hiddenAPIFlagFileCategoryMaxTargetRLowPriority: + command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") + case hiddenAPIFlagFileCategoryMaxTargetQ: + command.FlagWithInput("--max-target-q ", path) + case hiddenAPIFlagFileCategoryMaxTargetP: + command.FlagWithInput("--max-target-p ", path) + case hiddenAPIFlagFileCategoryMaxTargetOLowPriority: + command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") + case hiddenAPIFlagFileCategoryBlocked: + command.FlagWithInput("--blocked ", path) + case hiddenAPIFlagFileCategoryUnsupportedPackages: + command.FlagWithInput("--unsupported ", path).Flag("--packages ") + default: + panic(fmt.Sprintf("Unknown hidden api flag file category type: %d", c)) } - panic(fmt.Errorf("no category exists with property name %q in %v", name, c)) } +type hiddenAPIFlagFileCategories []hiddenAPIFlagFileCategory + var HiddenAPIFlagFileCategories = hiddenAPIFlagFileCategories{ // See HiddenAPIFlagFileProperties.Unsupported - { - PropertyName: "unsupported", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Unsupported - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--unsupported ", path) - }, - }, - hiddenAPIRemovedFlagFileCategory, + hiddenAPIFlagFileCategoryUnsupported, + // See HiddenAPIFlagFileProperties.Removed + hiddenAPIFlagFileCategoryRemoved, // See HiddenAPIFlagFileProperties.Max_target_r_low_priority - { - PropertyName: "max_target_r_low_priority", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_r_low_priority - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") - }, - }, + hiddenAPIFlagFileCategoryMaxTargetRLowPriority, // See HiddenAPIFlagFileProperties.Max_target_q - { - PropertyName: "max_target_q", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_q - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-q ", path) - }, - }, + hiddenAPIFlagFileCategoryMaxTargetQ, // See HiddenAPIFlagFileProperties.Max_target_p - { - PropertyName: "max_target_p", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_p - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-p ", path) - }, - }, + hiddenAPIFlagFileCategoryMaxTargetP, // See HiddenAPIFlagFileProperties.Max_target_o_low_priority - { - PropertyName: "max_target_o_low_priority", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_o_low_priority - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") - }, - }, + hiddenAPIFlagFileCategoryMaxTargetOLowPriority, // See HiddenAPIFlagFileProperties.Blocked - { - PropertyName: "blocked", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Blocked - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--blocked ", path) - }, - }, + hiddenAPIFlagFileCategoryBlocked, // See HiddenAPIFlagFileProperties.Unsupported_packages - { - PropertyName: "unsupported_packages", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Unsupported_packages - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--unsupported ", path).Flag("--packages ") - }, - }, + hiddenAPIFlagFileCategoryUnsupportedPackages, } // FlagFilesByCategory maps a hiddenAPIFlagFileCategory to the paths to the files in that category. -type FlagFilesByCategory map[*hiddenAPIFlagFileCategory]android.Paths +type FlagFilesByCategory map[hiddenAPIFlagFileCategory]android.Paths // append the supplied flags files to the corresponding category in this map. func (s FlagFilesByCategory) append(other FlagFilesByCategory) { @@ -1014,7 +1010,7 @@ func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc st // If available then pass the automatically generated file containing dex signatures of removed // API members to the rule so they can be marked as removed. if generatedRemovedDexSignatures.Valid() { - hiddenAPIRemovedFlagFileCategory.commandMutator(command, generatedRemovedDexSignatures.Path()) + hiddenAPIFlagFileCategoryRemoved.commandMutator(command, generatedRemovedDexSignatures.Path()) } commitChangeForRestat(rule, tempPath, outputPath) diff --git a/java/java.go b/java/java.go index d18d915cc..d536ca11b 100644 --- a/java/java.go +++ b/java/java.go @@ -653,7 +653,7 @@ func (j *Library) PermittedPackagesForUpdatableBootJars() []string { return j.properties.Permitted_packages } -func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { +func shouldUncompressDex(ctx android.ModuleContext, libName string, dexpreopter *dexpreopter) bool { // Store uncompressed (and aligned) any dex files from jars in APEXes. if apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider); !apexInfo.IsForPlatform() { return true @@ -665,7 +665,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo } // Store uncompressed dex files that are preopted on /system. - if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, dexpreopter.installPath)) { + if !dexpreopter.dexpreoptDisabled(ctx, libName) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, libName, dexpreopter.installPath)) { return true } if ctx.Config().UncompressPrivAppDex() && @@ -680,7 +680,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) { if dexer.dexProperties.Uncompress_dex == nil { // If the value was not force-set by the user, use reasonable default based on the module. - dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, dexpreopter)) + dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexpreopter)) } } @@ -712,7 +712,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.checkHeadersOnly(ctx) if ctx.Device() { j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) + ctx, j.Name(), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -1084,7 +1084,7 @@ func (j *JavaTestImport) InstallInTestcases() bool { return true } -func (j *TestHost) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (j *TestHost) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return ctx.DeviceConfig().NativeCoverageEnabled() } @@ -2274,7 +2274,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, ApexRootRelativePathToJavaLib(j.BaseModuleName())) j.dexJarInstallFile = installPath - j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath) + j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath) setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -2282,8 +2282,6 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexpreopter.inputProfilePathOnHost = profilePath } - j.dexpreopt(ctx, dexOutputPath) - // Initialize the hiddenapi structure. j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex) } else { @@ -2304,7 +2302,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Dex compilation j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, android.PathForModuleInstall(ctx, "framework", jarName)) + ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), android.PathForModuleInstall(ctx, "framework", jarName)) setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -2592,8 +2590,8 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) - j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) + ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) + j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &j.dexpreopter) inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") @@ -2632,7 +2630,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) - j.dexpreopt(ctx, dexOutputFile) + j.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexOutputFile) if apexInfo.IsForPlatform() { ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), diff --git a/java/sdk_library.go b/java/sdk_library.go index 5ee713c15..2bf66449d 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2879,16 +2879,13 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo module.installFile = installPath module.initHiddenAPI(ctx, dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) - module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, installPath) + module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath) module.dexpreopter.isSDKLibrary = true - module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &module.dexpreopter) + module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &module.dexpreopter) if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { module.dexpreopter.inputProfilePathOnHost = profilePath } - - // Dexpreopting. - module.dexpreopt(ctx, dexOutputPath) } else { // This should never happen as a variant for a prebuilt_apex is only created if the // prebuilt_apex has been configured to export the java library dex file. diff --git a/rust/rust.go b/rust/rust.go index 34ce4c545..245ed2e8e 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -535,7 +535,7 @@ func (mod *Module) isCoverageVariant() bool { var _ cc.Coverage = (*Module)(nil) -func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (mod *Module) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant } diff --git a/testing/code_metadata_proto/Android.bp b/testing/code_metadata_proto/Android.bp index 8fcca1918..f07efffb3 100644 --- a/testing/code_metadata_proto/Android.bp +++ b/testing/code_metadata_proto/Android.bp @@ -20,10 +20,24 @@ bootstrap_go_package { name: "soong-testing-code_metadata_proto", pkgPath: "android/soong/testing/code_metadata_proto", deps: [ - "golang-protobuf-reflect-protoreflect", - "golang-protobuf-runtime-protoimpl", - ], + "golang-protobuf-reflect-protoreflect", + "golang-protobuf-runtime-protoimpl", + ], srcs: [ "code_metadata.pb.go", ], } + +python_library_host { + name: "code-metadata-proto-py", + pkg_path: "code_metadata", + srcs: [ + "code_metadata.proto", + ], + libs: [ + "libprotobuf-python", + ], + proto: { + canonical_path_from_root: false, + }, +} diff --git a/testing/test_spec_proto/Android.bp b/testing/test_spec_proto/Android.bp index 1cac492f1..d5ad70b73 100644 --- a/testing/test_spec_proto/Android.bp +++ b/testing/test_spec_proto/Android.bp @@ -20,10 +20,24 @@ bootstrap_go_package { name: "soong-testing-test_spec_proto", pkgPath: "android/soong/testing/test_spec_proto", deps: [ - "golang-protobuf-reflect-protoreflect", - "golang-protobuf-runtime-protoimpl", - ], + "golang-protobuf-reflect-protoreflect", + "golang-protobuf-runtime-protoimpl", + ], srcs: [ "test_spec.pb.go", ], } + +python_library_host { + name: "test-spec-proto-py", + pkg_path: "test_spec", + srcs: [ + "test_spec.proto", + ], + libs: [ + "libprotobuf-python", + ], + proto: { + canonical_path_from_root: false, + }, +} |