diff options
49 files changed, 1093 insertions, 1622 deletions
diff --git a/android/aconfig_providers.go b/android/aconfig_providers.go index 6bfbf3776..cb88e011c 100644 --- a/android/aconfig_providers.go +++ b/android/aconfig_providers.go @@ -187,6 +187,20 @@ func aconfigUpdateAndroidMkEntries(ctx fillInEntriesContext, mod Module, entries } } +func aconfigUpdateAndroidMkInfos(ctx fillInEntriesContext, mod Module, infos *AndroidMkProviderInfo) { + info, ok := OtherModuleProvider(ctx, mod, AconfigPropagatingProviderKey) + if !ok || len(info.AconfigFiles) == 0 { + return + } + // All of the files in the module potentially depend on the aconfig flag values. + infos.PrimaryInfo.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths(mod.base(), info.AconfigFiles)) + if len(infos.ExtraInfo) > 0 { + for _, ei := range (*infos).ExtraInfo { + ei.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths(mod.base(), info.AconfigFiles)) + } + } +} + func mergeAconfigFiles(ctx ModuleContext, container string, inputs Paths, generateRule bool) Paths { inputs = SortedUniquePaths(inputs) if len(inputs) == 1 { diff --git a/android/androidmk.go b/android/androidmk.go index 6426835af..5fb0cd167 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -502,6 +502,7 @@ type fillInEntriesContext interface { otherModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) ModuleType(module blueprint.Module) string OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) + HasMutatorFinished(mutatorName string) bool } func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { @@ -806,15 +807,21 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs // Additional cases here require review for correct license propagation to make. var err error - switch x := mod.(type) { - case AndroidMkDataProvider: - err = translateAndroidModule(ctx, w, moduleInfoJSONs, mod, x) - case bootstrap.GoBinaryTool: - err = translateGoBinaryModule(ctx, w, mod, x) - case AndroidMkEntriesProvider: - err = translateAndroidMkEntriesModule(ctx, w, moduleInfoJSONs, mod, x) - default: - // Not exported to make so no make variables to set. + + if info, ok := ctx.otherModuleProvider(mod, AndroidMkInfoProvider); ok { + androidMkEntriesInfos := info.(*AndroidMkProviderInfo) + err = translateAndroidMkEntriesInfoModule(ctx, w, moduleInfoJSONs, mod, androidMkEntriesInfos) + } else { + switch x := mod.(type) { + case AndroidMkDataProvider: + err = translateAndroidModule(ctx, w, moduleInfoJSONs, mod, x) + case bootstrap.GoBinaryTool: + err = translateGoBinaryModule(ctx, w, mod, x) + case AndroidMkEntriesProvider: + err = translateAndroidMkEntriesModule(ctx, w, moduleInfoJSONs, mod, x) + default: + // Not exported to make so no make variables to set. + } } if err != nil { @@ -913,6 +920,7 @@ func translateAndroidModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs * case "*android_sdk.sdkRepoHost": // doesn't go through base_rules case "*apex.apexBundle": // license properties written case "*bpf.bpf": // license properties written (both for module and objs) + case "*libbpf_prog.libbpfProg": // license properties written (both for module and objs) case "*genrule.Module": // writes non-custom before adding .phony case "*java.SystemModules": // doesn't go through base_rules case "*java.systemModulesImport": // doesn't go through base_rules @@ -982,11 +990,11 @@ func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, moduleIn return nil } -func ShouldSkipAndroidMkProcessing(ctx ConfigAndErrorContext, module Module) bool { +func ShouldSkipAndroidMkProcessing(ctx ConfigurableEvaluatorContext, module Module) bool { return shouldSkipAndroidMkProcessing(ctx, module.base()) } -func shouldSkipAndroidMkProcessing(ctx ConfigAndErrorContext, module *ModuleBase) bool { +func shouldSkipAndroidMkProcessing(ctx ConfigurableEvaluatorContext, module *ModuleBase) bool { if !module.commonProperties.NamespaceExportedToMake { // TODO(jeffrygaston) do we want to validate that there are no modules being // exported to Kati that depend on this module? @@ -1062,3 +1070,564 @@ func AndroidMkEmitAssignList(w io.Writer, varName string, lists ...[]string) { } fmt.Fprintln(w) } + +type AndroidMkProviderInfo struct { + PrimaryInfo AndroidMkInfo + ExtraInfo []AndroidMkInfo +} + +type AndroidMkInfo struct { + // Android.mk class string, e.g. EXECUTABLES, JAVA_LIBRARIES, ETC + Class string + // Optional suffix to append to the module name. Useful when a module wants to return multiple + // AndroidMkEntries objects. For example, when a java_library returns an additional entry for + // its hostdex sub-module, this SubName field is set to "-hostdex" so that it can have a + // different name than the parent's. + SubName string + // If set, this value overrides the base module name. SubName is still appended. + OverrideName string + // Dist files to output + DistFiles TaggedDistFiles + // The output file for Kati to process and/or install. If absent, the module is skipped. + OutputFile OptionalPath + // If true, the module is skipped and does not appear on the final Android-<product name>.mk + // file. Useful when a module needs to be skipped conditionally. + Disabled bool + // The postprocessing mk file to include, e.g. $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk + // If not set, $(BUILD_SYSTEM)/prebuilt.mk is used. + Include string + // Required modules that need to be built and included in the final build output when building + // this module. + Required []string + // Required host modules that need to be built and included in the final build output when + // building this module. + Host_required []string + // Required device modules that need to be built and included in the final build output when + // building this module. + Target_required []string + + HeaderStrings []string + FooterStrings []string + + // A map that holds the up-to-date Make variable values. Can be accessed from tests. + EntryMap map[string][]string + // A list of EntryMap keys in insertion order. This serves a few purposes: + // 1. Prevents churns. Golang map doesn't provide consistent iteration order, so without this, + // the outputted Android-*.mk file may change even though there have been no content changes. + // 2. Allows modules to refer to other variables, like LOCAL_BAR_VAR := $(LOCAL_FOO_VAR), + // without worrying about the variables being mixed up in the actual mk file. + // 3. Makes troubleshooting and spotting errors easier. + EntryOrder []string +} + +// TODO: rename it to AndroidMkEntriesProvider after AndroidMkEntriesProvider interface is gone. +var AndroidMkInfoProvider = blueprint.NewProvider[*AndroidMkProviderInfo]() + +func translateAndroidMkEntriesInfoModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON, + mod blueprint.Module, providerInfo *AndroidMkProviderInfo) error { + if shouldSkipAndroidMkProcessing(ctx, mod.(Module).base()) { + return nil + } + + // Deep copy the provider info since we need to modify the info later + info := deepCopyAndroidMkProviderInfo(providerInfo) + + aconfigUpdateAndroidMkInfos(ctx, mod.(Module), &info) + + // Any new or special cases here need review to verify correct propagation of license information. + info.PrimaryInfo.fillInEntries(ctx, mod) + info.PrimaryInfo.write(w) + if len(info.ExtraInfo) > 0 { + for _, ei := range info.ExtraInfo { + ei.fillInEntries(ctx, mod) + ei.write(w) + } + } + + if !info.PrimaryInfo.disabled() { + if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { + *moduleInfoJSONs = append(*moduleInfoJSONs, moduleInfoJSON) + } + } + + return nil +} + +// Utility funcs to manipulate Android.mk variable entries. + +// SetString sets a Make variable with the given name to the given value. +func (a *AndroidMkInfo) SetString(name, value string) { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = []string{value} +} + +// SetPath sets a Make variable with the given name to the given path string. +func (a *AndroidMkInfo) SetPath(name string, path Path) { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = []string{path.String()} +} + +// SetOptionalPath sets a Make variable with the given name to the given path string if it is valid. +// It is a no-op if the given path is invalid. +func (a *AndroidMkInfo) SetOptionalPath(name string, path OptionalPath) { + if path.Valid() { + a.SetPath(name, path.Path()) + } +} + +// AddPath appends the given path string to a Make variable with the given name. +func (a *AndroidMkInfo) AddPath(name string, path Path) { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = append(a.EntryMap[name], path.String()) +} + +// AddOptionalPath appends the given path string to a Make variable with the given name if it is +// valid. It is a no-op if the given path is invalid. +func (a *AndroidMkInfo) AddOptionalPath(name string, path OptionalPath) { + if path.Valid() { + a.AddPath(name, path.Path()) + } +} + +// SetPaths sets a Make variable with the given name to a slice of the given path strings. +func (a *AndroidMkInfo) SetPaths(name string, paths Paths) { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = paths.Strings() +} + +// SetOptionalPaths sets a Make variable with the given name to a slice of the given path strings +// only if there are a non-zero amount of paths. +func (a *AndroidMkInfo) SetOptionalPaths(name string, paths Paths) { + if len(paths) > 0 { + a.SetPaths(name, paths) + } +} + +// AddPaths appends the given path strings to a Make variable with the given name. +func (a *AndroidMkInfo) AddPaths(name string, paths Paths) { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = append(a.EntryMap[name], paths.Strings()...) +} + +// SetBoolIfTrue sets a Make variable with the given name to true if the given flag is true. +// It is a no-op if the given flag is false. +func (a *AndroidMkInfo) SetBoolIfTrue(name string, flag bool) { + if flag { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = []string{"true"} + } +} + +// SetBool sets a Make variable with the given name to if the given bool flag value. +func (a *AndroidMkInfo) SetBool(name string, flag bool) { + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + if flag { + a.EntryMap[name] = []string{"true"} + } else { + a.EntryMap[name] = []string{"false"} + } +} + +// AddStrings appends the given strings to a Make variable with the given name. +func (a *AndroidMkInfo) AddStrings(name string, value ...string) { + if len(value) == 0 { + return + } + if _, ok := a.EntryMap[name]; !ok { + a.EntryOrder = append(a.EntryOrder, name) + } + a.EntryMap[name] = append(a.EntryMap[name], value...) +} + +// AddCompatibilityTestSuites adds the supplied test suites to the EntryMap, with special handling +// for partial MTS and MCTS test suites. +func (a *AndroidMkInfo) AddCompatibilityTestSuites(suites ...string) { + // M(C)TS supports a full test suite and partial per-module MTS test suites, with naming mts-${MODULE}. + // To reduce repetition, if we find a partial M(C)TS test suite without an full M(C)TS test suite, + // we add the full test suite to our list. + if PrefixInList(suites, "mts-") && !InList("mts", suites) { + suites = append(suites, "mts") + } + if PrefixInList(suites, "mcts-") && !InList("mcts", suites) { + suites = append(suites, "mcts") + } + a.AddStrings("LOCAL_COMPATIBILITY_SUITE", suites...) +} + +func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { + helperInfo := AndroidMkInfo{ + EntryMap: make(map[string][]string), + } + + amod := mod.(Module) + base := amod.base() + name := base.BaseModuleName() + if a.OverrideName != "" { + name = a.OverrideName + } + + if a.Include == "" { + a.Include = "$(BUILD_PREBUILT)" + } + a.Required = append(a.Required, amod.RequiredModuleNames(ctx)...) + a.Required = append(a.Required, amod.VintfFragmentModuleNames(ctx)...) + a.Host_required = append(a.Host_required, amod.HostRequiredModuleNames()...) + a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...) + + for _, distString := range a.GetDistForGoals(ctx, mod) { + a.HeaderStrings = append(a.HeaderStrings, distString) + } + + a.HeaderStrings = append(a.HeaderStrings, fmt.Sprintf("\ninclude $(CLEAR_VARS) # type: %s, name: %s, variant: %s\n", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod))) + + // Collect make variable assignment entries. + helperInfo.SetString("LOCAL_PATH", ctx.ModuleDir(mod)) + helperInfo.SetString("LOCAL_MODULE", name+a.SubName) + helperInfo.SetString("LOCAL_MODULE_CLASS", a.Class) + helperInfo.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String()) + helperInfo.AddStrings("LOCAL_REQUIRED_MODULES", a.Required...) + helperInfo.AddStrings("LOCAL_HOST_REQUIRED_MODULES", a.Host_required...) + helperInfo.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...) + helperInfo.AddStrings("LOCAL_SOONG_MODULE_TYPE", ctx.ModuleType(amod)) + + // If the install rule was generated by Soong tell Make about it. + info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) + if len(info.KatiInstalls) > 0 { + // Assume the primary install file is last since it probably needs to depend on any other + // installed files. If that is not the case we can add a method to specify the primary + // installed file. + helperInfo.SetPath("LOCAL_SOONG_INSTALLED_MODULE", info.KatiInstalls[len(info.KatiInstalls)-1].to) + helperInfo.SetString("LOCAL_SOONG_INSTALL_PAIRS", info.KatiInstalls.BuiltInstalled()) + helperInfo.SetPaths("LOCAL_SOONG_INSTALL_SYMLINKS", info.KatiSymlinks.InstallPaths().Paths()) + } else { + // Soong may not have generated the install rule also when `no_full_install: true`. + // Mark this module as uninstallable in order to prevent Make from creating an + // install rule there. + helperInfo.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", proptools.Bool(base.commonProperties.No_full_install)) + } + + if len(info.TestData) > 0 { + helperInfo.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(info.TestData)...) + } + + if am, ok := mod.(ApexModule); ok { + helperInfo.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform()) + } + + archStr := base.Arch().ArchType.String() + host := false + switch base.Os().Class { + case Host: + if base.Target().HostCross { + // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. + if base.Arch().ArchType != Common { + helperInfo.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr) + } + } else { + // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. + if base.Arch().ArchType != Common { + helperInfo.SetString("LOCAL_MODULE_HOST_ARCH", archStr) + } + } + host = true + case Device: + // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. + if base.Arch().ArchType != Common { + if base.Target().NativeBridge { + hostArchStr := base.Target().NativeBridgeHostArchName + if hostArchStr != "" { + helperInfo.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr) + } + } else { + helperInfo.SetString("LOCAL_MODULE_TARGET_ARCH", archStr) + } + } + + if !base.InVendorRamdisk() { + helperInfo.AddPaths("LOCAL_FULL_INIT_RC", info.InitRcPaths) + } + if len(info.VintfFragmentsPaths) > 0 { + helperInfo.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", info.VintfFragmentsPaths) + } + helperInfo.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(base.commonProperties.Proprietary)) + if Bool(base.commonProperties.Vendor) || Bool(base.commonProperties.Soc_specific) { + helperInfo.SetString("LOCAL_VENDOR_MODULE", "true") + } + helperInfo.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(base.commonProperties.Device_specific)) + helperInfo.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(base.commonProperties.Product_specific)) + helperInfo.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(base.commonProperties.System_ext_specific)) + if base.commonProperties.Owner != nil { + helperInfo.SetString("LOCAL_MODULE_OWNER", *base.commonProperties.Owner) + } + } + + if host { + makeOs := base.Os().String() + if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl { + makeOs = "linux" + } + helperInfo.SetString("LOCAL_MODULE_HOST_OS", makeOs) + helperInfo.SetString("LOCAL_IS_HOST_MODULE", "true") + } + + prefix := "" + if base.ArchSpecific() { + switch base.Os().Class { + case Host: + if base.Target().HostCross { + prefix = "HOST_CROSS_" + } else { + prefix = "HOST_" + } + case Device: + prefix = "TARGET_" + + } + + if base.Arch().ArchType != ctx.Config().Targets[base.Os()][0].Arch.ArchType { + prefix = "2ND_" + prefix + } + } + + if licenseMetadata, ok := OtherModuleProvider(ctx, mod, LicenseMetadataProvider); ok { + helperInfo.SetPath("LOCAL_SOONG_LICENSE_METADATA", licenseMetadata.LicenseMetadataPath) + } + + if _, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { + helperInfo.SetBool("LOCAL_SOONG_MODULE_INFO_JSON", true) + } + + a.mergeEntries(&helperInfo) + + // Write to footer. + a.FooterStrings = append([]string{"include " + a.Include}, a.FooterStrings...) +} + +// This method merges the entries to helperInfo, then replaces a's EntryMap and +// EntryOrder with helperInfo's +func (a *AndroidMkInfo) mergeEntries(helperInfo *AndroidMkInfo) { + for _, extraEntry := range a.EntryOrder { + if v, ok := helperInfo.EntryMap[extraEntry]; ok { + v = append(v, a.EntryMap[extraEntry]...) + } else { + helperInfo.EntryMap[extraEntry] = a.EntryMap[extraEntry] + helperInfo.EntryOrder = append(helperInfo.EntryOrder, extraEntry) + } + } + a.EntryOrder = helperInfo.EntryOrder + a.EntryMap = helperInfo.EntryMap +} + +func (a *AndroidMkInfo) disabled() bool { + return a.Disabled || !a.OutputFile.Valid() +} + +// write flushes the AndroidMkEntries's in-struct data populated by AndroidMkEntries into the +// given Writer object. +func (a *AndroidMkInfo) write(w io.Writer) { + if a.disabled() { + return + } + + combinedHeaderString := strings.Join(a.HeaderStrings, "\n") + combinedFooterString := strings.Join(a.FooterStrings, "\n") + w.Write([]byte(combinedHeaderString)) + for _, name := range a.EntryOrder { + AndroidMkEmitAssignList(w, name, a.EntryMap[name]) + } + w.Write([]byte(combinedFooterString)) +} + +// Compute the list of Make strings to declare phony goals and dist-for-goals +// calls from the module's dist and dists properties. +func (a *AndroidMkInfo) GetDistForGoals(ctx fillInEntriesContext, mod blueprint.Module) []string { + distContributions := a.getDistContributions(ctx, mod) + if distContributions == nil { + return nil + } + + return generateDistContributionsForMake(distContributions) +} + +// Compute the contributions that the module makes to the dist. +func (a *AndroidMkInfo) getDistContributions(ctx fillInEntriesContext, mod blueprint.Module) *distContributions { + amod := mod.(Module).base() + name := amod.BaseModuleName() + + // Collate the set of associated tag/paths available for copying to the dist. + // Start with an empty (nil) set. + var availableTaggedDists TaggedDistFiles + + // Then merge in any that are provided explicitly by the module. + if a.DistFiles != nil { + // Merge the DistFiles into the set. + availableTaggedDists = availableTaggedDists.merge(a.DistFiles) + } + + // If no paths have been provided for the DefaultDistTag and the output file is + // valid then add that as the default dist path. + if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() { + availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path()) + } + + info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) + // If the distFiles created by GenerateTaggedDistFiles contains paths for the + // DefaultDistTag then that takes priority so delete any existing paths. + if _, ok := info.DistFiles[DefaultDistTag]; ok { + delete(availableTaggedDists, DefaultDistTag) + } + + // Finally, merge the distFiles created by GenerateTaggedDistFiles. + availableTaggedDists = availableTaggedDists.merge(info.DistFiles) + + if len(availableTaggedDists) == 0 { + // Nothing dist-able for this module. + return nil + } + + // Collate the contributions this module makes to the dist. + distContributions := &distContributions{} + + if !exemptFromRequiredApplicableLicensesProperty(mod.(Module)) { + distContributions.licenseMetadataFile = info.LicenseMetadataFile + } + + // Iterate over this module's dist structs, merged from the dist and dists properties. + for _, dist := range amod.Dists() { + // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore + goals := strings.Join(dist.Targets, " ") + + // Get the tag representing the output files to be dist'd. e.g. ".jar", ".proguard_map" + var tag string + if dist.Tag == nil { + // If the dist struct does not specify a tag, use the default output files tag. + tag = DefaultDistTag + } else { + tag = *dist.Tag + } + + // Get the paths of the output files to be dist'd, represented by the tag. + // Can be an empty list. + tagPaths := availableTaggedDists[tag] + if len(tagPaths) == 0 { + // Nothing to dist for this tag, continue to the next dist. + continue + } + + if len(tagPaths) > 1 && (dist.Dest != nil || dist.Suffix != nil) { + errorMessage := "%s: Cannot apply dest/suffix for more than one dist " + + "file for %q goals tag %q in module %s. The list of dist files, " + + "which should have a single element, is:\n%s" + panic(fmt.Errorf(errorMessage, mod, goals, tag, name, tagPaths)) + } + + copiesForGoals := distContributions.getCopiesForGoals(goals) + + // Iterate over each path adding a copy instruction to copiesForGoals + for _, path := range tagPaths { + // It's possible that the Path is nil from errant modules. Be defensive here. + if path == nil { + tagName := "default" // for error message readability + if dist.Tag != nil { + tagName = *dist.Tag + } + panic(fmt.Errorf("Dist file should not be nil for the %s tag in %s", tagName, name)) + } + + dest := filepath.Base(path.String()) + + if dist.Dest != nil { + var err error + if dest, err = validateSafePath(*dist.Dest); err != nil { + // This was checked in ModuleBase.GenerateBuildActions + panic(err) + } + } + + ext := filepath.Ext(dest) + suffix := "" + if dist.Suffix != nil { + suffix = *dist.Suffix + } + + productString := "" + if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { + productString = fmt.Sprintf("_%s", ctx.Config().DeviceProduct()) + } + + if suffix != "" || productString != "" { + dest = strings.TrimSuffix(dest, ext) + suffix + productString + ext + } + + if dist.Dir != nil { + var err error + if dest, err = validateSafePath(*dist.Dir, dest); err != nil { + // This was checked in ModuleBase.GenerateBuildActions + panic(err) + } + } + + copiesForGoals.addCopyInstruction(path, dest) + } + } + + return distContributions +} + +func deepCopyAndroidMkProviderInfo(providerInfo *AndroidMkProviderInfo) AndroidMkProviderInfo { + info := AndroidMkProviderInfo{ + PrimaryInfo: deepCopyAndroidMkInfo(&providerInfo.PrimaryInfo), + } + if len(providerInfo.ExtraInfo) > 0 { + for _, i := range providerInfo.ExtraInfo { + info.ExtraInfo = append(info.ExtraInfo, deepCopyAndroidMkInfo(&i)) + } + } + return info +} + +func deepCopyAndroidMkInfo(mkinfo *AndroidMkInfo) AndroidMkInfo { + info := AndroidMkInfo{ + Class: mkinfo.Class, + SubName: mkinfo.SubName, + OverrideName: mkinfo.OverrideName, + // There is no modification on DistFiles or OutputFile, so no need to + // make their deep copy. + DistFiles: mkinfo.DistFiles, + OutputFile: mkinfo.OutputFile, + Disabled: mkinfo.Disabled, + Include: mkinfo.Include, + Required: deepCopyStringSlice(mkinfo.Required), + Host_required: deepCopyStringSlice(mkinfo.Host_required), + Target_required: deepCopyStringSlice(mkinfo.Target_required), + HeaderStrings: deepCopyStringSlice(mkinfo.HeaderStrings), + FooterStrings: deepCopyStringSlice(mkinfo.FooterStrings), + EntryOrder: deepCopyStringSlice(mkinfo.EntryOrder), + } + info.EntryMap = make(map[string][]string) + for k, v := range mkinfo.EntryMap { + info.EntryMap[k] = deepCopyStringSlice(v) + } + + return info +} + +func deepCopyStringSlice(original []string) []string { + result := make([]string, len(original)) + copy(result, original) + return result +} diff --git a/android/arch_list.go b/android/arch_list.go index 2937092af..9501c877c 100644 --- a/android/arch_list.go +++ b/android/arch_list.go @@ -26,6 +26,7 @@ var archVariants = map[ArchType][]string{ "armv8-2a", "armv8-2a-dotprod", "armv9-a", + "armv9-2a", }, X86: { "amberlake", diff --git a/android/base_module_context.go b/android/base_module_context.go index 550600052..bb8137720 100644 --- a/android/base_module_context.go +++ b/android/base_module_context.go @@ -220,6 +220,10 @@ type BaseModuleContext interface { // EvaluateConfiguration makes ModuleContext a valid proptools.ConfigurableEvaluator, so this context // can be used to evaluate the final value of Configurable properties. EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue + + // HasMutatorFinished returns true if the given mutator has finished running. + // It will panic if given an invalid mutator name. + HasMutatorFinished(mutatorName string) bool } type baseModuleContext struct { @@ -270,6 +274,10 @@ func (b *baseModuleContext) setProvider(provider blueprint.AnyProviderKey, value b.bp.SetProvider(provider, value) } +func (b *baseModuleContext) HasMutatorFinished(mutatorName string) bool { + return b.bp.HasMutatorFinished(mutatorName) +} + func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module { return b.bp.GetDirectDepWithTag(name, tag) } diff --git a/android/config.go b/android/config.go index b682c2e93..368e57381 100644 --- a/android/config.go +++ b/android/config.go @@ -1663,6 +1663,17 @@ func (c *config) ApexTrimEnabled() bool { return Bool(c.productVariables.TrimmedApex) } +func (c *config) UseSoongSystemImage() bool { + return Bool(c.productVariables.UseSoongSystemImage) +} + +func (c *config) SoongDefinedSystemImage() string { + if c.UseSoongSystemImage() { + return String(c.productVariables.ProductSoongDefinedSystemImage) + } + return "" +} + func (c *config) EnforceSystemCertificate() bool { return Bool(c.productVariables.EnforceSystemCertificate) } diff --git a/android/module.go b/android/module.go index 009b0dfb6..47fdc238b 100644 --- a/android/module.go +++ b/android/module.go @@ -58,7 +58,7 @@ type Module interface { base() *ModuleBase Disable() - Enabled(ctx ConfigAndErrorContext) bool + Enabled(ctx ConfigurableEvaluatorContext) bool Target() Target MultiTargets() []Target @@ -109,12 +109,12 @@ type Module interface { // Get information about the properties that can contain visibility rules. visibilityProperties() []visibilityProperty - RequiredModuleNames(ctx ConfigAndErrorContext) []string + RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string HostRequiredModuleNames() []string TargetRequiredModuleNames() []string - VintfFragmentModuleNames(ctx ConfigAndErrorContext) []string + VintfFragmentModuleNames(ctx ConfigurableEvaluatorContext) []string - ConfigurableEvaluator(ctx ConfigAndErrorContext) proptools.ConfigurableEvaluator + ConfigurableEvaluator(ctx ConfigurableEvaluatorContext) proptools.ConfigurableEvaluator } // Qualified id for a module @@ -1339,7 +1339,7 @@ func (m *ModuleBase) PartitionTag(config DeviceConfig) string { return partition } -func (m *ModuleBase) Enabled(ctx ConfigAndErrorContext) bool { +func (m *ModuleBase) Enabled(ctx ConfigurableEvaluatorContext) bool { if m.commonProperties.ForcedDisabled { return false } @@ -1536,7 +1536,7 @@ func (m *ModuleBase) InRecovery() bool { return m.base().commonProperties.ImageVariation == RecoveryVariation } -func (m *ModuleBase) RequiredModuleNames(ctx ConfigAndErrorContext) []string { +func (m *ModuleBase) RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string { return m.base().commonProperties.Required.GetOrDefault(m.ConfigurableEvaluator(ctx), nil) } @@ -1548,7 +1548,7 @@ func (m *ModuleBase) TargetRequiredModuleNames() []string { return m.base().commonProperties.Target_required } -func (m *ModuleBase) VintfFragmentModuleNames(ctx ConfigAndErrorContext) []string { +func (m *ModuleBase) VintfFragmentModuleNames(ctx ConfigurableEvaluatorContext) []string { return m.base().commonProperties.Vintf_fragment_modules.GetOrDefault(m.ConfigurableEvaluator(ctx), nil) } @@ -2204,17 +2204,17 @@ func (m *ModuleBase) IsNativeBridgeSupported() bool { return proptools.Bool(m.commonProperties.Native_bridge_supported) } -type ConfigAndErrorContext interface { +type ConfigurableEvaluatorContext interface { Config() Config OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) } type configurationEvalutor struct { - ctx ConfigAndErrorContext + ctx ConfigurableEvaluatorContext m Module } -func (m *ModuleBase) ConfigurableEvaluator(ctx ConfigAndErrorContext) proptools.ConfigurableEvaluator { +func (m *ModuleBase) ConfigurableEvaluator(ctx ConfigurableEvaluatorContext) proptools.ConfigurableEvaluator { return configurationEvalutor{ ctx: ctx, m: m.module, diff --git a/android/module_context.go b/android/module_context.go index 3889e40e8..54fe0be17 100644 --- a/android/module_context.go +++ b/android/module_context.go @@ -194,7 +194,7 @@ type ModuleContext interface { InstallInVendor() bool InstallForceOS() (*OsType, *ArchType) - RequiredModuleNames(ctx ConfigAndErrorContext) []string + RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string HostRequiredModuleNames() []string TargetRequiredModuleNames() []string @@ -855,7 +855,7 @@ func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) Optional return OptionalPath{} } -func (m *moduleContext) RequiredModuleNames(ctx ConfigAndErrorContext) []string { +func (m *moduleContext) RequiredModuleNames(ctx ConfigurableEvaluatorContext) []string { return m.module.RequiredModuleNames(ctx) } diff --git a/android/paths.go b/android/paths.go index e45795989..6322f7566 100644 --- a/android/paths.go +++ b/android/paths.go @@ -94,6 +94,7 @@ type ModuleWithDepsPathContext interface { EarlyModulePathContext VisitDirectDepsBlueprint(visit func(blueprint.Module)) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag + HasMutatorFinished(mutatorName string) bool } // ModuleMissingDepsPathContext is a subset of *ModuleContext methods required by diff --git a/android/sdk.go b/android/sdk.go index d3f04a4f9..ab9a91ccb 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -813,8 +813,6 @@ type SdkMemberProperties interface { // SdkMemberContext provides access to information common to a specific member. type SdkMemberContext interface { - ConfigAndErrorContext - // SdkModuleContext returns the module context of the sdk common os variant which is creating the // snapshot. // diff --git a/android/singleton.go b/android/singleton.go index 8542bd9e6..913bf6a56 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -90,6 +90,10 @@ type SingletonContext interface { // OtherModulePropertyErrorf reports an error on the line number of the given property of the given module OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{}) + + // HasMutatorFinished returns true if the given mutator has finished running. + // It will panic if given an invalid mutator name. + HasMutatorFinished(mutatorName string) bool } type singletonAdaptor struct { @@ -286,3 +290,7 @@ func (s *singletonContextAdaptor) otherModuleProvider(module blueprint.Module, p func (s *singletonContextAdaptor) OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{}) { s.blueprintSingletonContext().OtherModulePropertyErrorf(module, property, format, args...) } + +func (s *singletonContextAdaptor) HasMutatorFinished(mutatorName string) bool { + return s.blueprintSingletonContext().HasMutatorFinished(mutatorName) +} diff --git a/android/testing.go b/android/testing.go index 816707d63..1ee6e4cdb 100644 --- a/android/testing.go +++ b/android/testing.go @@ -1326,7 +1326,11 @@ func (ctx *panickingConfigAndErrorContext) Config() Config { return ctx.ctx.Config() } -func PanickingConfigAndErrorContext(ctx *TestContext) ConfigAndErrorContext { +func (ctx *panickingConfigAndErrorContext) HasMutatorFinished(mutatorName string) bool { + return ctx.ctx.HasMutatorFinished(mutatorName) +} + +func PanickingConfigAndErrorContext(ctx *TestContext) ConfigurableEvaluatorContext { return &panickingConfigAndErrorContext{ ctx: ctx, } diff --git a/android/variable.go b/android/variable.go index 8ca75eea7..e0d512d3a 100644 --- a/android/variable.go +++ b/android/variable.go @@ -121,6 +121,7 @@ type variableProperties struct { // are used for dogfooding and performance testing, and should be as similar to user builds // as possible. Debuggable struct { + Apk *string Cflags []string Cppflags []string Init_rc []string @@ -422,6 +423,9 @@ type ProductVariables struct { TargetFSConfigGen []string `json:",omitempty"` + UseSoongSystemImage *bool `json:",omitempty"` + ProductSoongDefinedSystemImage *string `json:",omitempty"` + EnforceProductPartitionInterface *bool `json:",omitempty"` EnforceInterPartitionJavaSdkLibrary *bool `json:",omitempty"` diff --git a/apex/Android.bp b/apex/Android.bp index 17fdfc36a..ef2f75570 100644 --- a/apex/Android.bp +++ b/apex/Android.bp @@ -15,7 +15,6 @@ bootstrap_go_package { "soong-cc", "soong-filesystem", "soong-java", - "soong-multitree", "soong-provenance", "soong-python", "soong-rust", diff --git a/apex/apex.go b/apex/apex.go index 1f4a99b55..c12d1e473 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -32,7 +32,6 @@ import ( prebuilt_etc "android/soong/etc" "android/soong/filesystem" "android/soong/java" - "android/soong/multitree" "android/soong/rust" "android/soong/sh" ) @@ -438,7 +437,6 @@ type apexBundle struct { android.ModuleBase android.DefaultableModuleBase android.OverridableModuleBase - multitree.ExportableModuleBase // Properties properties apexBundleProperties @@ -1406,8 +1404,6 @@ func (a *apexBundle) DepIsInSameApex(_ android.BaseModuleContext, _ android.Modu return true } -var _ multitree.Exportable = (*apexBundle)(nil) - func (a *apexBundle) Exportable() bool { return true } @@ -2540,7 +2536,6 @@ func newApexBundle() *apexBundle { android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitOverridableModule(module, &module.overridableProperties.Overrides) - multitree.InitExportableModule(module) return module } @@ -2797,7 +2792,7 @@ func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) { return false } - if to.AvailableFor(apexName) || baselineApexAvailable(apexName, toName) { + if to.AvailableFor(apexName) { return true } @@ -2857,74 +2852,6 @@ func (a *apexBundle) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeI dpInfo.Deps = append(dpInfo.Deps, a.properties.ResolvedSystemserverclasspathFragments...) } -var ( - apexAvailBaseline = makeApexAvailableBaseline() - inverseApexAvailBaseline = invertApexBaseline(apexAvailBaseline) -) - -func baselineApexAvailable(apex, moduleName string) bool { - key := apex - moduleName = normalizeModuleName(moduleName) - - if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) { - return true - } - - key = android.AvailableToAnyApex - if val, ok := apexAvailBaseline[key]; ok && android.InList(moduleName, val) { - return true - } - - return false -} - -func normalizeModuleName(moduleName string) string { - // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build - // system. Trim the prefix for the check since they are confusing - moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName) - if strings.HasPrefix(moduleName, "libclang_rt.") { - // This module has many arch variants that depend on the product being built. - // We don't want to list them all - moduleName = "libclang_rt" - } - if strings.HasPrefix(moduleName, "androidx.") { - // TODO(b/156996905) Set apex_available/min_sdk_version for androidx support libraries - moduleName = "androidx" - } - return moduleName -} - -// Transform the map of apex -> modules to module -> apexes. -func invertApexBaseline(m map[string][]string) map[string][]string { - r := make(map[string][]string) - for apex, modules := range m { - for _, module := range modules { - r[module] = append(r[module], apex) - } - } - return r -} - -// Retrieve the baseline of apexes to which the supplied module belongs. -func BaselineApexAvailable(moduleName string) []string { - return inverseApexAvailBaseline[normalizeModuleName(moduleName)] -} - -// This is a map from apex to modules, which overrides the apex_available setting for that -// particular module to make it available for the apex regardless of its setting. -// TODO(b/147364041): remove this -func makeApexAvailableBaseline() map[string][]string { - // The "Module separator"s below are employed to minimize merge conflicts. - m := make(map[string][]string) - // - // Module separator - // - m["com.android.runtime"] = []string{ - "libz", - } - return m -} - func init() { android.AddNeverAllowRules(createBcpPermittedPackagesRules(qBcpPackages())...) android.AddNeverAllowRules(createBcpPermittedPackagesRules(rBcpPackages())...) diff --git a/apex/apex_test.go b/apex/apex_test.go index 685cb3743..2b9772821 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -10274,208 +10274,6 @@ func TestUpdatableApexEnforcesAppUpdatability(t *testing.T) { } } -func TestApexBuildsAgainstApiSurfaceStubLibraries(t *testing.T) { - bp := ` - apex { - name: "myapex", - key: "myapex.key", - native_shared_libs: ["libbaz"], - binaries: ["binfoo"], - min_sdk_version: "29", - } - apex_key { - name: "myapex.key", - } - cc_binary { - name: "binfoo", - shared_libs: ["libbar", "libbaz", "libqux",], - apex_available: ["myapex"], - min_sdk_version: "29", - recovery_available: false, - } - cc_library { - name: "libbar", - srcs: ["libbar.cc"], - stubs: { - symbol_file: "libbar.map.txt", - versions: [ - "29", - ], - }, - } - cc_library { - name: "libbaz", - srcs: ["libbaz.cc"], - apex_available: ["myapex"], - min_sdk_version: "29", - stubs: { - symbol_file: "libbaz.map.txt", - versions: [ - "29", - ], - }, - } - cc_api_library { - name: "libbar", - src: "libbar_stub.so", - min_sdk_version: "29", - variants: ["apex.29"], - } - cc_api_variant { - name: "libbar", - variant: "apex", - version: "29", - src: "libbar_apex_29.so", - } - cc_api_library { - name: "libbaz", - src: "libbaz_stub.so", - min_sdk_version: "29", - variants: ["apex.29"], - } - cc_api_variant { - name: "libbaz", - variant: "apex", - version: "29", - src: "libbaz_apex_29.so", - } - cc_api_library { - name: "libqux", - src: "libqux_stub.so", - min_sdk_version: "29", - variants: ["apex.29"], - } - cc_api_variant { - name: "libqux", - variant: "apex", - version: "29", - src: "libqux_apex_29.so", - } - api_imports { - name: "api_imports", - apex_shared_libs: [ - "libbar", - "libbaz", - "libqux", - ], - } - ` - result := testApex(t, bp) - - hasDep := func(m android.Module, wantDep android.Module) bool { - t.Helper() - var found bool - result.VisitDirectDeps(m, func(dep blueprint.Module) { - if dep == wantDep { - found = true - } - }) - return found - } - - // Library defines stubs and cc_api_library should be used with cc_api_library - binfooApexVariant := result.ModuleForTests("binfoo", "android_arm64_armv8-a_apex29").Module() - libbarCoreVariant := result.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() - libbarApiImportCoreVariant := result.ModuleForTests("libbar.apiimport", "android_arm64_armv8-a_shared").Module() - - android.AssertBoolEquals(t, "apex variant should link against API surface stub libraries", true, hasDep(binfooApexVariant, libbarApiImportCoreVariant)) - android.AssertBoolEquals(t, "apex variant should link against original library if exists", true, hasDep(binfooApexVariant, libbarCoreVariant)) - - binFooCFlags := result.ModuleForTests("binfoo", "android_arm64_armv8-a_apex29").Rule("ld").Args["libFlags"] - android.AssertStringDoesContain(t, "binfoo should link against APEX variant", binFooCFlags, "libbar.apex.29.apiimport.so") - android.AssertStringDoesNotContain(t, "binfoo should not link against cc_api_library itself", binFooCFlags, "libbar.apiimport.so") - android.AssertStringDoesNotContain(t, "binfoo should not link against original definition", binFooCFlags, "libbar.so") - - // Library defined in the same APEX should be linked with original definition instead of cc_api_library - libbazApexVariant := result.ModuleForTests("libbaz", "android_arm64_armv8-a_shared_apex29").Module() - libbazApiImportCoreVariant := result.ModuleForTests("libbaz.apiimport", "android_arm64_armv8-a_shared").Module() - android.AssertBoolEquals(t, "apex variant should link against API surface stub libraries even from same APEX", true, hasDep(binfooApexVariant, libbazApiImportCoreVariant)) - android.AssertBoolEquals(t, "apex variant should link against original library if exists", true, hasDep(binfooApexVariant, libbazApexVariant)) - - android.AssertStringDoesContain(t, "binfoo should link against APEX variant", binFooCFlags, "libbaz.so") - android.AssertStringDoesNotContain(t, "binfoo should not link against cc_api_library itself", binFooCFlags, "libbaz.apiimport.so") - android.AssertStringDoesNotContain(t, "binfoo should not link against original definition", binFooCFlags, "libbaz.apex.29.apiimport.so") - - // cc_api_library defined without original library should be linked with cc_api_library - libquxApiImportApexVariant := result.ModuleForTests("libqux.apiimport", "android_arm64_armv8-a_shared").Module() - android.AssertBoolEquals(t, "apex variant should link against API surface stub libraries even original library definition does not exist", true, hasDep(binfooApexVariant, libquxApiImportApexVariant)) - android.AssertStringDoesContain(t, "binfoo should link against APEX variant", binFooCFlags, "libqux.apex.29.apiimport.so") -} - -func TestPlatformBinaryBuildsAgainstApiSurfaceStubLibraries(t *testing.T) { - bp := ` - apex { - name: "myapex", - key: "myapex.key", - native_shared_libs: ["libbar"], - min_sdk_version: "29", - } - apex_key { - name: "myapex.key", - } - cc_binary { - name: "binfoo", - shared_libs: ["libbar"], - recovery_available: false, - } - cc_library { - name: "libbar", - srcs: ["libbar.cc"], - apex_available: ["myapex"], - min_sdk_version: "29", - stubs: { - symbol_file: "libbar.map.txt", - versions: [ - "29", - ], - }, - } - cc_api_library { - name: "libbar", - src: "libbar_stub.so", - variants: ["apex.29"], - } - cc_api_variant { - name: "libbar", - variant: "apex", - version: "29", - src: "libbar_apex_29.so", - } - api_imports { - name: "api_imports", - apex_shared_libs: [ - "libbar", - ], - } - ` - - result := testApex(t, bp) - - hasDep := func(m android.Module, wantDep android.Module) bool { - t.Helper() - var found bool - result.VisitDirectDeps(m, func(dep blueprint.Module) { - if dep == wantDep { - found = true - } - }) - return found - } - - // Library defines stubs and cc_api_library should be used with cc_api_library - binfooApexVariant := result.ModuleForTests("binfoo", "android_arm64_armv8-a").Module() - libbarCoreVariant := result.ModuleForTests("libbar", "android_arm64_armv8-a_shared").Module() - libbarApiImportCoreVariant := result.ModuleForTests("libbar.apiimport", "android_arm64_armv8-a_shared").Module() - - android.AssertBoolEquals(t, "apex variant should link against API surface stub libraries", true, hasDep(binfooApexVariant, libbarApiImportCoreVariant)) - android.AssertBoolEquals(t, "apex variant should link against original library if exists", true, hasDep(binfooApexVariant, libbarCoreVariant)) - - binFooCFlags := result.ModuleForTests("binfoo", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] - android.AssertStringDoesContain(t, "binfoo should link against APEX variant", binFooCFlags, "libbar.apex.29.apiimport.so") - android.AssertStringDoesNotContain(t, "binfoo should not link against cc_api_library itself", binFooCFlags, "libbar.apiimport.so") - android.AssertStringDoesNotContain(t, "binfoo should not link against original definition", binFooCFlags, "libbar.so") -} - func TestTrimmedApex(t *testing.T) { bp := ` apex { @@ -10514,21 +10312,6 @@ func TestTrimmedApex(t *testing.T) { apex_available: ["myapex","mydcla"], min_sdk_version: "29", } - cc_api_library { - name: "libc", - src: "libc.so", - min_sdk_version: "29", - recovery_available: true, - vendor_available: true, - product_available: true, - } - api_imports { - name: "api_imports", - shared_libs: [ - "libc", - ], - header_libs: [], - } ` ctx := testApex(t, bp) module := ctx.ModuleForTests("myapex", "android_common_myapex") diff --git a/bpf/libbpf/Android.bp b/bpf/libbpf/Android.bp new file mode 100644 index 000000000..f0ba90f52 --- /dev/null +++ b/bpf/libbpf/Android.bp @@ -0,0 +1,38 @@ +// +// Copyright (C) 2024 The Android Open Source Project +// +// 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 { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +bootstrap_go_package { + name: "soong-libbpf", + pkgPath: "android/soong/bpf/libbpf", + deps: [ + "blueprint", + "blueprint-proptools", + "soong-android", + "soong-cc", + "soong-cc-config", + ], + srcs: [ + "libbpf_prog.go", + ], + testSrcs: [ + "libbpf_prog_test.go", + ], + pluginFor: ["soong_build"], +} diff --git a/bpf/libbpf/libbpf_prog.go b/bpf/libbpf/libbpf_prog.go new file mode 100644 index 000000000..1fdb3d636 --- /dev/null +++ b/bpf/libbpf/libbpf_prog.go @@ -0,0 +1,278 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// 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 libbpf_prog + +import ( + "fmt" + "io" + "runtime" + "strings" + + "android/soong/android" + "android/soong/cc" + "android/soong/genrule" + + "github.com/google/blueprint" +) + +type libbpfProgDepType struct { + blueprint.BaseDependencyTag +} + +func init() { + registerLibbpfProgBuildComponents(android.InitRegistrationContext) + pctx.Import("android/soong/cc/config") + pctx.StaticVariable("relPwd", cc.PwdPrefix()) +} + +var ( + pctx = android.NewPackageContext("android/soong/bpf/libbpf_prog") + + libbpfProgCcRule = pctx.AndroidStaticRule("libbpfProgCcRule", + blueprint.RuleParams{ + Depfile: "${out}.d", + Deps: blueprint.DepsGCC, + Command: "$relPwd $ccCmd --target=bpf -c $cFlags -MD -MF ${out}.d -o $out $in", + CommandDeps: []string{"$ccCmd"}, + }, + "ccCmd", "cFlags") + + libbpfProgStripRule = pctx.AndroidStaticRule("libbpfProgStripRule", + blueprint.RuleParams{ + Command: `$stripCmd --strip-unneeded --remove-section=.rel.BTF ` + + `--remove-section=.rel.BTF.ext --remove-section=.BTF.ext $in -o $out`, + CommandDeps: []string{"$stripCmd"}, + }, + "stripCmd") + + libbpfProgDepTag = libbpfProgDepType{} +) + +func registerLibbpfProgBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("libbpf_prog", LibbpfProgFactory) +} + +var PrepareForTestWithLibbpfProg = android.GroupFixturePreparers( + android.FixtureRegisterWithContext(registerLibbpfProgBuildComponents), + android.FixtureAddFile("libbpf_headers/Foo.h", nil), + android.FixtureAddFile("libbpf_headers/Android.bp", []byte(` + genrule { + name: "libbpf_headers", + out: ["foo.h",], + } + `)), + genrule.PrepareForTestWithGenRuleBuildComponents, +) + +type LibbpfProgProperties struct { + // source paths to the files. + Srcs []string `android:"path"` + + // additional cflags that should be used to build the libbpf variant of + // the C/C++ module. + Cflags []string `android:"arch_variant"` + + // list of directories relative to the Blueprint file that will + // be added to the include path using -I + Local_include_dirs []string `android:"arch_variant"` + + // optional subdirectory under which this module is installed into. + Relative_install_path string +} + +type libbpfProg struct { + android.ModuleBase + properties LibbpfProgProperties + objs android.Paths +} + +var _ android.ImageInterface = (*libbpfProg)(nil) + +func (libbpf *libbpfProg) ImageMutatorBegin(ctx android.BaseModuleContext) {} + +func (libbpf *libbpfProg) VendorVariantNeeded(ctx android.BaseModuleContext) bool { + return false +} + +func (libbpf *libbpfProg) ProductVariantNeeded(ctx android.BaseModuleContext) bool { + return false +} + +func (libbpf *libbpfProg) CoreVariantNeeded(ctx android.BaseModuleContext) bool { + return true +} + +func (libbpf *libbpfProg) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { + return false +} + +func (libbpf *libbpfProg) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { + return false +} + +func (libbpf *libbpfProg) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { + return false +} + +func (libbpf *libbpfProg) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { + return false +} + +func (libbpf *libbpfProg) ExtraImageVariations(ctx android.BaseModuleContext) []string { + return nil +} + +func (libbpf *libbpfProg) SetImageVariation(ctx android.BaseModuleContext, variation string) { +} + +func (libbpf *libbpfProg) DepsMutator(ctx android.BottomUpMutatorContext) { + ctx.AddDependency(ctx.Module(), libbpfProgDepTag, "libbpf_headers") +} + +func (libbpf *libbpfProg) GenerateAndroidBuildActions(ctx android.ModuleContext) { + var cFlagsDeps android.Paths + cflags := []string{ + "-nostdlibinc", + + // Make paths in deps files relative + "-no-canonical-prefixes", + + "-O2", + "-Wall", + "-Werror", + "-Wextra", + + "-isystem bionic/libc/include", + "-isystem bionic/libc/kernel/uapi", + // The architecture doesn't matter here, but asm/types.h is included by linux/types.h. + "-isystem bionic/libc/kernel/uapi/asm-arm64", + "-isystem bionic/libc/kernel/android/uapi", + "-I " + ctx.ModuleDir(), + "-g", //Libbpf builds require BTF data + } + + if runtime.GOOS != "darwin" { + cflags = append(cflags, "-fdebug-prefix-map=/proc/self/cwd=") + } + + ctx.VisitDirectDeps(func(dep android.Module) { + depTag := ctx.OtherModuleDependencyTag(dep) + if depTag == libbpfProgDepTag { + if genRule, ok := dep.(genrule.SourceFileGenerator); ok { + cFlagsDeps = append(cFlagsDeps, genRule.GeneratedDeps()...) + dirs := genRule.GeneratedHeaderDirs() + for _, dir := range dirs { + cflags = append(cflags, "-I "+dir.String()) + } + } else { + depName := ctx.OtherModuleName(dep) + ctx.ModuleErrorf("module %q is not a genrule", depName) + } + } + }) + + for _, dir := range android.PathsForModuleSrc(ctx, libbpf.properties.Local_include_dirs) { + cflags = append(cflags, "-I "+dir.String()) + } + + cflags = append(cflags, libbpf.properties.Cflags...) + + srcs := android.PathsForModuleSrc(ctx, libbpf.properties.Srcs) + + for _, src := range srcs { + if strings.ContainsRune(src.Base(), '_') { + ctx.ModuleErrorf("invalid character '_' in source name") + } + obj := android.ObjPathWithExt(ctx, "unstripped", src, "o") + + ctx.Build(pctx, android.BuildParams{ + Rule: libbpfProgCcRule, + Input: src, + Implicits: cFlagsDeps, + Output: obj, + Args: map[string]string{ + "cFlags": strings.Join(cflags, " "), + "ccCmd": "${config.ClangBin}/clang", + }, + }) + + objStripped := android.ObjPathWithExt(ctx, "", src, "o") + ctx.Build(pctx, android.BuildParams{ + Rule: libbpfProgStripRule, + Input: obj, + Output: objStripped, + Args: map[string]string{ + "stripCmd": "${config.ClangBin}/llvm-strip", + }, + }) + libbpf.objs = append(libbpf.objs, objStripped.WithoutRel()) + } + + installDir := android.PathForModuleInstall(ctx, "etc", "bpf/libbpf") + if len(libbpf.properties.Relative_install_path) > 0 { + installDir = installDir.Join(ctx, libbpf.properties.Relative_install_path) + } + for _, obj := range libbpf.objs { + ctx.PackageFile(installDir, obj.Base(), obj) + } + + android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcs.Strings()}) + + ctx.SetOutputFiles(libbpf.objs, "") +} + +func (libbpf *libbpfProg) AndroidMk() android.AndroidMkData { + return android.AndroidMkData{ + Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { + var names []string + fmt.Fprintln(w) + fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) + fmt.Fprintln(w) + var localModulePath string + localModulePath = "LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/bpf/libbpf" + if len(libbpf.properties.Relative_install_path) > 0 { + localModulePath += "/" + libbpf.properties.Relative_install_path + } + for _, obj := range libbpf.objs { + objName := name + "_" + obj.Base() + names = append(names, objName) + fmt.Fprintln(w, "include $(CLEAR_VARS)", " # libbpf.libbpf.obj") + fmt.Fprintln(w, "LOCAL_MODULE := ", objName) + fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String()) + fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base()) + fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") + fmt.Fprintln(w, localModulePath) + // AconfigUpdateAndroidMkData may have added elements to Extra. Process them here. + for _, extra := range data.Extra { + extra(w, nil) + } + fmt.Fprintln(w, "include $(BUILD_PREBUILT)") + fmt.Fprintln(w) + } + fmt.Fprintln(w, "include $(CLEAR_VARS)", " # libbpf.libbpf") + fmt.Fprintln(w, "LOCAL_MODULE := ", name) + android.AndroidMkEmitAssignList(w, "LOCAL_REQUIRED_MODULES", names) + fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") + }, + } +} + +func LibbpfProgFactory() android.Module { + module := &libbpfProg{} + + module.AddProperties(&module.properties) + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) + return module +} diff --git a/bpf/libbpf/libbpf_prog_test.go b/bpf/libbpf/libbpf_prog_test.go new file mode 100644 index 000000000..f4f51672f --- /dev/null +++ b/bpf/libbpf/libbpf_prog_test.go @@ -0,0 +1,69 @@ +// Copyright 2024 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 libbpf_prog + +import ( + "os" + "testing" + + "android/soong/android" + "android/soong/cc" +) + +func TestMain(m *testing.M) { + os.Exit(m.Run()) +} + +var prepareForLibbpfProgTest = android.GroupFixturePreparers( + cc.PrepareForTestWithCcDefaultModules, + android.FixtureMergeMockFs( + map[string][]byte{ + "bpf.c": nil, + "bpf_invalid_name.c": nil, + "BpfTest.cpp": nil, + }, + ), + PrepareForTestWithLibbpfProg, +) + +func TestLibbpfProgDataDependency(t *testing.T) { + bp := ` + libbpf_prog { + name: "bpf.o", + srcs: ["bpf.c"], + } + + cc_test { + name: "vts_test_binary_bpf_module", + srcs: ["BpfTest.cpp"], + data: [":bpf.o"], + gtest: false, + } + ` + + prepareForLibbpfProgTest.RunTestWithBp(t, bp) +} + +func TestLibbpfProgSourceName(t *testing.T) { + bp := ` + libbpf_prog { + name: "bpf_invalid_name.o", + srcs: ["bpf_invalid_name.c"], + } + ` + prepareForLibbpfProgTest.ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern( + `invalid character '_' in source name`)). + RunTestWithBp(t, bp) +} diff --git a/cc/Android.bp b/cc/Android.bp index e68e4a398..29526143f 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -16,7 +16,6 @@ bootstrap_go_package { "soong-etc", "soong-fuzz", "soong-genrule", - "soong-multitree", "soong-testing", "soong-tradefed", ], @@ -65,7 +64,6 @@ bootstrap_go_package { "library.go", "library_headers.go", "library_sdk_member.go", - "library_stub.go", "native_bridge_sdk_trait.go", "object.go", "test.go", diff --git a/cc/androidmk.go b/cc/androidmk.go index cecaae23a..6966f7692 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -21,7 +21,6 @@ import ( "strings" "android/soong/android" - "android/soong/multitree" ) var ( @@ -479,34 +478,6 @@ func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *a androidMkWritePrebuiltOptions(p.baseLinker, entries) } -func (a *apiLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { - entries.Class = "SHARED_LIBRARIES" - entries.SubName += multitree.GetApiImportSuffix() - - entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - a.libraryDecorator.androidMkWriteExportedFlags(entries) - src := *a.properties.Src - path, file := filepath.Split(src) - stem, suffix, ext := android.SplitFileExt(file) - entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext) - entries.SetString("LOCAL_MODULE_SUFFIX", suffix) - entries.SetString("LOCAL_MODULE_STEM", stem) - entries.SetString("LOCAL_MODULE_PATH", path) - entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) - entries.SetString("LOCAL_SOONG_TOC", a.toc().String()) - }) -} - -func (a *apiHeadersDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { - entries.Class = "HEADER_LIBRARIES" - entries.SubName += multitree.GetApiImportSuffix() - - entries.ExtraEntries = append(entries.ExtraEntries, func(_ android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - a.libraryDecorator.androidMkWriteExportedFlags(entries) - entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) - }) -} - func androidMkWritePrebuiltOptions(linker *baseLinker, entries *android.AndroidMkEntries) { allow := linker.Properties.Allow_undefined_symbols if allow != nil { diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index 8a7ea8845..4063714ab 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -132,7 +132,7 @@ func (p *nativeBinaryInfoProperties) PopulateFromVariant(ctx android.SdkMemberCo if ccModule.linker != nil { specifiedDeps := specifiedDeps{} - specifiedDeps = ccModule.linker.linkerSpecifiedDeps(ctx, ccModule, specifiedDeps) + specifiedDeps = ccModule.linker.linkerSpecifiedDeps(ctx.SdkModuleContext(), ccModule, specifiedDeps) p.SharedLibs = specifiedDeps.sharedLibs p.SystemSharedLibs = specifiedDeps.systemSharedLibs @@ -34,7 +34,6 @@ import ( "android/soong/cc/config" "android/soong/fuzz" "android/soong/genrule" - "android/soong/multitree" ) func init() { @@ -613,7 +612,7 @@ type linker interface { coverageOutputFilePath() android.OptionalPath // Get the deps that have been explicitly specified in the properties. - linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps + linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) } @@ -970,7 +969,7 @@ func (c *Module) HiddenFromMake() bool { return c.Properties.HideFromMake } -func (c *Module) RequiredModuleNames(ctx android.ConfigAndErrorContext) []string { +func (c *Module) RequiredModuleNames(ctx android.ConfigurableEvaluatorContext) []string { required := android.CopyOf(c.ModuleBase.RequiredModuleNames(ctx)) if c.ImageVariation().Variation == android.CoreVariation { required = append(required, c.Properties.Target.Platform.Required...) @@ -2361,24 +2360,6 @@ func AddSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, mo } } -func GetApiImports(c LinkableInterface, actx android.BottomUpMutatorContext) multitree.ApiImportInfo { - apiImportInfo := multitree.ApiImportInfo{} - - if c.Device() { - var apiImportModule []blueprint.Module - if actx.OtherModuleExists("api_imports") { - apiImportModule = actx.AddDependency(c, nil, "api_imports") - if len(apiImportModule) > 0 && apiImportModule[0] != nil { - apiInfo, _ := android.OtherModuleProvider(actx, apiImportModule[0], multitree.ApiImportsProvider) - apiImportInfo = apiInfo - android.SetProvider(actx, multitree.ApiImportsProvider, apiInfo) - } - } - } - - return apiImportInfo -} - func GetReplaceModuleName(lib string, replaceMap map[string]string) string { if snapshot, ok := replaceMap[lib]; ok { return snapshot @@ -2448,11 +2429,6 @@ func (c *Module) shouldUseApiSurface() bool { // NDK Variant return true } - - if c.isImportedApiLibrary() { - // API Library should depend on API headers - return true - } } return false @@ -2472,19 +2448,10 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { ctx.ctx = ctx deps := c.deps(ctx) - apiImportInfo := GetApiImports(c, actx) apiNdkLibs := []string{} apiLateNdkLibs := []string{} - if c.shouldUseApiSurface() { - deps.SharedLibs, apiNdkLibs = rewriteLibsForApiImports(c, deps.SharedLibs, apiImportInfo.SharedLibs, ctx.Config()) - deps.LateSharedLibs, apiLateNdkLibs = rewriteLibsForApiImports(c, deps.LateSharedLibs, apiImportInfo.SharedLibs, ctx.Config()) - deps.SystemSharedLibs, _ = rewriteLibsForApiImports(c, deps.SystemSharedLibs, apiImportInfo.SharedLibs, ctx.Config()) - deps.ReexportHeaderLibHeaders, _ = rewriteLibsForApiImports(c, deps.ReexportHeaderLibHeaders, apiImportInfo.SharedLibs, ctx.Config()) - deps.ReexportSharedLibHeaders, _ = rewriteLibsForApiImports(c, deps.ReexportSharedLibHeaders, apiImportInfo.SharedLibs, ctx.Config()) - } - c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs variantNdkLibs := []string{} @@ -2501,11 +2468,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { depTag.reexportFlags = true } - // Check header lib replacement from API surface first, and then check again with VSDK - if c.shouldUseApiSurface() { - lib = GetReplaceModuleName(lib, apiImportInfo.HeaderLibs) - } - if c.isNDKStubLibrary() { variationExists := actx.OtherModuleDependencyVariantExists(nil, lib) if variationExists { @@ -2515,7 +2477,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { // any variants. actx.AddFarVariationDependencies([]blueprint.Variation{}, depTag, lib) } - } else if c.IsStubs() && !c.isImportedApiLibrary() { + } else if c.IsStubs() { actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()), depTag, lib) } else { @@ -2591,22 +2553,12 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { } name, version := StubsLibNameAndVersion(lib) - if apiLibraryName, ok := apiImportInfo.SharedLibs[name]; ok && !ctx.OtherModuleExists(name) { - name = apiLibraryName - } sharedLibNames = append(sharedLibNames, name) variations := []blueprint.Variation{ {Mutator: "link", Variation: "shared"}, } - - if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) { - AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, name, version, false) - } - - if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok { - AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, apiLibraryName, version, false) - } + AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, name, version, false) } for _, lib := range deps.LateStaticLibs { @@ -2701,7 +2653,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { ) } - updateImportedLibraryDependency(ctx) } func BeginMutator(ctx android.BottomUpMutatorContext) { @@ -2730,10 +2681,6 @@ func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to Lin return } - // TODO(b/244244438) : Remove this once all variants are implemented - if ccFrom, ok := from.(*Module); ok && ccFrom.isImportedApiLibrary() { - return - } if from.SdkVersion() == "" { // Platform code can link to anything return @@ -2756,10 +2703,6 @@ func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to Lin // the NDK. return } - if c.isImportedApiLibrary() { - // Imported library from the API surface is a stub library built against interface definition. - return - } } if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" { @@ -2935,47 +2878,6 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { skipModuleList := map[string]bool{} - var apiImportInfo multitree.ApiImportInfo - hasApiImportInfo := false - - ctx.VisitDirectDeps(func(dep android.Module) { - if dep.Name() == "api_imports" { - apiImportInfo, _ = android.OtherModuleProvider(ctx, dep, multitree.ApiImportsProvider) - hasApiImportInfo = true - } - }) - - if hasApiImportInfo { - targetStubModuleList := map[string]string{} - targetOrigModuleList := map[string]string{} - - // Search for dependency which both original module and API imported library with APEX stub exists - ctx.VisitDirectDeps(func(dep android.Module) { - depName := ctx.OtherModuleName(dep) - if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok { - targetStubModuleList[apiLibrary] = depName - } - }) - ctx.VisitDirectDeps(func(dep android.Module) { - depName := ctx.OtherModuleName(dep) - if origLibrary, ok := targetStubModuleList[depName]; ok { - targetOrigModuleList[origLibrary] = depName - } - }) - - // Decide which library should be used between original and API imported library - ctx.VisitDirectDeps(func(dep android.Module) { - depName := ctx.OtherModuleName(dep) - if apiLibrary, ok := targetOrigModuleList[depName]; ok { - if ShouldUseStubForApex(ctx, dep) { - skipModuleList[depName] = true - } else { - skipModuleList[apiLibrary] = true - } - } - }) - } - ctx.VisitDirectDeps(func(dep android.Module) { depName := ctx.OtherModuleName(dep) depTag := ctx.OtherModuleDependencyTag(dep) @@ -3404,17 +3306,7 @@ func ShouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool { // bootstrap modules, always link to non-stub variant isNotInPlatform := dep.(android.ApexModule).NotInPlatform() - isApexImportedApiLibrary := false - - if cc, ok := dep.(*Module); ok { - if apiLibrary, ok := cc.linker.(*apiLibraryDecorator); ok { - if apiLibrary.hasApexStubs() { - isApexImportedApiLibrary = true - } - } - } - - useStubs = (isNotInPlatform || isApexImportedApiLibrary) && !bootstrap + useStubs = isNotInPlatform && !bootstrap if useStubs { // Another exception: if this module is a test for an APEX, then @@ -3439,7 +3331,7 @@ func ShouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool { // only partially overlapping apex_available. For that test_for // modules would need to be split into APEX variants and resolved // separately for each APEX they have access to. - if !isApexImportedApiLibrary && android.AvailableToSameApexes(thisModule, dep.(android.ApexModule)) { + if android.AvailableToSameApexes(thisModule, dep.(android.ApexModule)) { useStubs = false } } @@ -4023,11 +3915,6 @@ func (c *Module) IsSdkVariant() bool { return c.Properties.IsSdkVariant } -func (c *Module) isImportedApiLibrary() bool { - _, ok := c.linker.(*apiLibraryDecorator) - return ok -} - func kytheExtractAllFactory() android.Singleton { return &kytheExtractAllSingleton{} } diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index 761afcf18..0dcf2cfd4 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -118,11 +118,9 @@ func init() { pctx.StaticVariable("Arm64Cppflags", strings.Join(arm64Cppflags, " ")) - pctx.StaticVariable("Arm64Armv8ACflags", strings.Join(arm64ArchVariantCflags["armv8-a"], " ")) - pctx.StaticVariable("Arm64Armv8ABranchProtCflags", strings.Join(arm64ArchVariantCflags["armv8-a-branchprot"], " ")) - pctx.StaticVariable("Arm64Armv82ACflags", strings.Join(arm64ArchVariantCflags["armv8-2a"], " ")) - pctx.StaticVariable("Arm64Armv82ADotprodCflags", strings.Join(arm64ArchVariantCflags["armv8-2a-dotprod"], " ")) - pctx.StaticVariable("Arm64Armv9ACflags", strings.Join(arm64ArchVariantCflags["armv9-a"], " ")) + for variant, cflags := range arm64ArchVariantCflags { + pctx.StaticVariable("Arm64"+variant+"VariantCflags", strings.Join(cflags, " ")) + } pctx.StaticVariable("Arm64CortexA53Cflags", strings.Join(arm64CpuVariantCflags["cortex-a53"], " ")) pctx.StaticVariable("Arm64CortexA55Cflags", strings.Join(arm64CpuVariantCflags["cortex-a55"], " ")) @@ -134,14 +132,6 @@ func init() { } var ( - arm64ArchVariantCflagsVar = map[string]string{ - "armv8-a": "${config.Arm64Armv8ACflags}", - "armv8-a-branchprot": "${config.Arm64Armv8ABranchProtCflags}", - "armv8-2a": "${config.Arm64Armv82ACflags}", - "armv8-2a-dotprod": "${config.Arm64Armv82ADotprodCflags}", - "armv9-a": "${config.Arm64Armv9ACflags}", - } - arm64CpuVariantCflagsVar = map[string]string{ "cortex-a53": "${config.Arm64CortexA53Cflags}", "cortex-a55": "${config.Arm64CortexA55Cflags}", @@ -211,18 +201,12 @@ func (toolchainArm64) LibclangRuntimeLibraryArch() string { } func arm64ToolchainFactory(arch android.Arch) Toolchain { - switch arch.ArchVariant { - case "armv8-a": - case "armv8-a-branchprot": - case "armv8-2a": - case "armv8-2a-dotprod": - case "armv9-a": - // Nothing extra for armv8-a/armv8-2a - default: - panic(fmt.Sprintf("Unknown ARM architecture version: %q", arch.ArchVariant)) + // Error now rather than having a confusing Ninja error + if _, ok := arm64ArchVariantCflags[arch.ArchVariant]; !ok { + panic(fmt.Sprintf("Unknown ARM64 architecture version: %q", arch.ArchVariant)) } - toolchainCflags := []string{arm64ArchVariantCflagsVar[arch.ArchVariant]} + toolchainCflags := []string{"${config.Arm64" + arch.ArchVariant + "VariantCflags}"} toolchainCflags = append(toolchainCflags, variantOrDefault(arm64CpuVariantCflagsVar, arch.CpuVariant)) diff --git a/cc/config/arm64_linux_host.go b/cc/config/arm64_linux_host.go index 438e0e6b6..a19b0ed92 100644 --- a/cc/config/arm64_linux_host.go +++ b/cc/config/arm64_linux_host.go @@ -87,8 +87,8 @@ func (toolchainLinuxBionicArm64) CrtBeginSharedBinary() []string { } func linuxBionicArm64ToolchainFactory(arch android.Arch) Toolchain { - archVariant := "armv8-a" // for host, default to armv8-a - toolchainCflags := []string{arm64ArchVariantCflagsVar[archVariant]} + // for host, default to armv8-a + toolchainCflags := []string{"-march=armv8-a"} // We don't specify CPU architecture for host. Conservatively assume // the host CPU needs the fix diff --git a/cc/library.go b/cc/library.go index 03f7174c6..3833b9846 100644 --- a/cc/library.go +++ b/cc/library.go @@ -919,7 +919,7 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { return deps } -func (library *libraryDecorator) linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps { +func (library *libraryDecorator) linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps { specifiedDeps = library.baseLinker.linkerSpecifiedDeps(ctx, module, specifiedDeps) var properties StaticOrSharedProperties if library.static() { @@ -2350,9 +2350,8 @@ func (versionTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, varia if library := moduleLibraryInterface(ctx.Module()); library != nil && canBeVersionVariant(m) { isLLNDK := m.IsLlndk() isVendorPublicLibrary := m.IsVendorPublicLibrary() - isImportedApiLibrary := m.isImportedApiLibrary() - if variation != "" || isLLNDK || isVendorPublicLibrary || isImportedApiLibrary { + if variation != "" || isLLNDK || isVendorPublicLibrary { // A stubs or LLNDK stubs variant. if m.sanitize != nil { m.sanitize.Properties.ForceDisable = true diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index 053c46069..af3658d58 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -543,7 +543,7 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberConte p.ExportedFlags = exportedInfo.Flags if ccModule.linker != nil { specifiedDeps := specifiedDeps{} - specifiedDeps = ccModule.linker.linkerSpecifiedDeps(ctx, ccModule, specifiedDeps) + specifiedDeps = ccModule.linker.linkerSpecifiedDeps(ctx.SdkModuleContext(), ccModule, specifiedDeps) if lib := ccModule.library; lib != nil { if !lib.hasStubsVariants() { diff --git a/cc/library_stub.go b/cc/library_stub.go deleted file mode 100644 index 636782581..000000000 --- a/cc/library_stub.go +++ /dev/null @@ -1,512 +0,0 @@ -// Copyright 2021 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 cc - -import ( - "regexp" - "strings" - - "android/soong/android" - "android/soong/multitree" - - "github.com/google/blueprint/proptools" -) - -var ( - ndkVariantRegex = regexp.MustCompile("ndk\\.([a-zA-Z0-9]+)") - stubVariantRegex = regexp.MustCompile("apex\\.([a-zA-Z0-9]+)") -) - -func init() { - RegisterLibraryStubBuildComponents(android.InitRegistrationContext) -} - -func RegisterLibraryStubBuildComponents(ctx android.RegistrationContext) { - ctx.RegisterModuleType("cc_api_library", CcApiLibraryFactory) - ctx.RegisterModuleType("cc_api_headers", CcApiHeadersFactory) - ctx.RegisterModuleType("cc_api_variant", CcApiVariantFactory) -} - -func updateImportedLibraryDependency(ctx android.BottomUpMutatorContext) { - m, ok := ctx.Module().(*Module) - if !ok { - return - } - - apiLibrary, ok := m.linker.(*apiLibraryDecorator) - if !ok { - return - } - - if m.InVendorOrProduct() && apiLibrary.hasLLNDKStubs() { - // Add LLNDK variant dependency - if inList("llndk", apiLibrary.properties.Variants) { - variantName := BuildApiVariantName(m.BaseModuleName(), "llndk", "") - ctx.AddDependency(m, nil, variantName) - } - } else if m.IsSdkVariant() { - // Add NDK variant dependencies - targetVariant := "ndk." + m.StubsVersion() - if inList(targetVariant, apiLibrary.properties.Variants) { - variantName := BuildApiVariantName(m.BaseModuleName(), targetVariant, "") - ctx.AddDependency(m, nil, variantName) - } - } else if m.IsStubs() { - targetVariant := "apex." + m.StubsVersion() - if inList(targetVariant, apiLibrary.properties.Variants) { - variantName := BuildApiVariantName(m.BaseModuleName(), targetVariant, "") - ctx.AddDependency(m, nil, variantName) - } - } -} - -// 'cc_api_library' is a module type which is from the exported API surface -// with C shared library type. The module will replace original module, and -// offer a link to the module that generates shared library object from the -// map file. -type apiLibraryProperties struct { - Src *string `android:"arch_variant"` - Variants []string -} - -type apiLibraryDecorator struct { - *libraryDecorator - properties apiLibraryProperties -} - -func CcApiLibraryFactory() android.Module { - module, decorator := NewLibrary(android.DeviceSupported) - apiLibraryDecorator := &apiLibraryDecorator{ - libraryDecorator: decorator, - } - apiLibraryDecorator.BuildOnlyShared() - - module.stl = nil - module.sanitize = nil - decorator.disableStripping() - - module.compiler = nil - module.linker = apiLibraryDecorator - module.installer = nil - module.library = apiLibraryDecorator - module.AddProperties(&module.Properties, &apiLibraryDecorator.properties) - - // Prevent default system libs (libc, libm, and libdl) from being linked - if apiLibraryDecorator.baseLinker.Properties.System_shared_libs == nil { - apiLibraryDecorator.baseLinker.Properties.System_shared_libs = []string{} - } - - apiLibraryDecorator.baseLinker.Properties.No_libcrt = BoolPtr(true) - apiLibraryDecorator.baseLinker.Properties.Nocrt = BoolPtr(true) - - module.Init() - - return module -} - -func (d *apiLibraryDecorator) Name(basename string) string { - return basename + multitree.GetApiImportSuffix() -} - -// Export include dirs without checking for existence. -// The directories are not guaranteed to exist during Soong analysis. -func (d *apiLibraryDecorator) exportIncludes(ctx ModuleContext) { - exporterProps := d.flagExporter.Properties - for _, dir := range exporterProps.Export_include_dirs.GetOrDefault(ctx, nil) { - d.dirs = append(d.dirs, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), dir)) - } - // system headers - for _, dir := range exporterProps.Export_system_include_dirs { - d.systemDirs = append(d.systemDirs, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), dir)) - } -} - -func (d *apiLibraryDecorator) linkerInit(ctx BaseModuleContext) { - d.baseLinker.linkerInit(ctx) - - if d.hasNDKStubs() { - // Set SDK version of module as current - ctx.Module().(*Module).Properties.Sdk_version = StringPtr("current") - - // Add NDK stub as NDK known libs - name := ctx.ModuleName() - - ndkKnownLibsLock.Lock() - ndkKnownLibs := getNDKKnownLibs(ctx.Config()) - if !inList(name, *ndkKnownLibs) { - *ndkKnownLibs = append(*ndkKnownLibs, name) - } - ndkKnownLibsLock.Unlock() - } -} - -func (d *apiLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objects Objects) android.Path { - m, _ := ctx.Module().(*Module) - - var in android.Path - - // src might not exist during the beginning of soong analysis in Multi-tree - if src := String(d.properties.Src); src != "" { - in = android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), src) - } - - libName := m.BaseModuleName() + multitree.GetApiImportSuffix() - - load_cc_variant := func(apiVariantModule string) { - var mod android.Module - - ctx.VisitDirectDeps(func(depMod android.Module) { - if depMod.Name() == apiVariantModule { - mod = depMod - libName = apiVariantModule - } - }) - - if mod != nil { - variantMod, ok := mod.(*CcApiVariant) - if ok { - in = variantMod.Src() - - // Copy LLDNK properties to cc_api_library module - exportIncludeDirs := append(d.libraryDecorator.flagExporter.Properties.Export_include_dirs.GetOrDefault(ctx, nil), - variantMod.exportProperties.Export_include_dirs...) - d.libraryDecorator.flagExporter.Properties.Export_include_dirs = proptools.NewConfigurable[[]string]( - nil, - []proptools.ConfigurableCase[[]string]{ - proptools.NewConfigurableCase[[]string](nil, &exportIncludeDirs), - }, - ) - - // Export headers as system include dirs if specified. Mostly for libc - if Bool(variantMod.exportProperties.Export_headers_as_system) { - d.libraryDecorator.flagExporter.Properties.Export_system_include_dirs = append( - d.libraryDecorator.flagExporter.Properties.Export_system_include_dirs, - d.libraryDecorator.flagExporter.Properties.Export_include_dirs.GetOrDefault(ctx, nil)...) - d.libraryDecorator.flagExporter.Properties.Export_include_dirs = proptools.NewConfigurable[[]string](nil, nil) - } - } - } - } - - if m.InVendorOrProduct() && d.hasLLNDKStubs() { - // LLNDK variant - load_cc_variant(BuildApiVariantName(m.BaseModuleName(), "llndk", "")) - } else if m.IsSdkVariant() { - // NDK Variant - load_cc_variant(BuildApiVariantName(m.BaseModuleName(), "ndk", m.StubsVersion())) - } else if m.IsStubs() { - // APEX Variant - load_cc_variant(BuildApiVariantName(m.BaseModuleName(), "apex", m.StubsVersion())) - } - - // Flags reexported from dependencies. (e.g. vndk_prebuilt_shared) - d.exportIncludes(ctx) - d.libraryDecorator.reexportDirs(deps.ReexportedDirs...) - d.libraryDecorator.reexportSystemDirs(deps.ReexportedSystemDirs...) - d.libraryDecorator.reexportFlags(deps.ReexportedFlags...) - d.libraryDecorator.reexportDeps(deps.ReexportedDeps...) - d.libraryDecorator.addExportedGeneratedHeaders(deps.ReexportedGeneratedHeaders...) - - if in == nil { - ctx.PropertyErrorf("src", "Unable to locate source property") - return nil - } - - // Make the _compilation_ of rdeps have an order-only dep on cc_api_library.src (an .so file) - // The .so file itself has an order-only dependency on the headers contributed by this library. - // Creating this dependency ensures that the headers are assembled before compilation of rdeps begins. - d.libraryDecorator.reexportDeps(in) - d.libraryDecorator.flagExporter.setProvider(ctx) - - d.unstrippedOutputFile = in - libName += flags.Toolchain.ShlibSuffix() - - tocFile := android.PathForModuleOut(ctx, libName+".toc") - d.tocFile = android.OptionalPathForPath(tocFile) - TransformSharedObjectToToc(ctx, in, tocFile) - - outputFile := android.PathForModuleOut(ctx, libName) - - // TODO(b/270485584) This copies with a new name, just to avoid conflict with prebuilts. - // We can just use original input if there is any way to avoid name conflict without copy. - ctx.Build(pctx, android.BuildParams{ - Rule: android.Cp, - Description: "API surface imported library", - Input: in, - Output: outputFile, - Args: map[string]string{ - "cpFlags": "-L", - }, - }) - - android.SetProvider(ctx, SharedLibraryInfoProvider, SharedLibraryInfo{ - SharedLibrary: outputFile, - Target: ctx.Target(), - - TableOfContents: d.tocFile, - }) - - d.shareStubs(ctx) - - return outputFile -} - -// Share additional information about stub libraries with provider -func (d *apiLibraryDecorator) shareStubs(ctx ModuleContext) { - stubs := ctx.GetDirectDepsWithTag(stubImplDepTag) - if len(stubs) > 0 { - var stubsInfo []SharedStubLibrary - for _, stub := range stubs { - stubInfo, _ := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider) - flagInfo, _ := android.OtherModuleProvider(ctx, stub, FlagExporterInfoProvider) - stubsInfo = append(stubsInfo, SharedStubLibrary{ - Version: moduleLibraryInterface(stub).stubsVersion(), - SharedLibraryInfo: stubInfo, - FlagExporterInfo: flagInfo, - }) - } - android.SetProvider(ctx, SharedLibraryStubsProvider, SharedLibraryStubsInfo{ - SharedStubLibraries: stubsInfo, - - IsLLNDK: ctx.IsLlndk(), - }) - } -} - -func (d *apiLibraryDecorator) availableFor(what string) bool { - // Stub from API surface should be available for any APEX. - return true -} - -func (d *apiLibraryDecorator) hasApexStubs() bool { - for _, variant := range d.properties.Variants { - if strings.HasPrefix(variant, "apex") { - return true - } - } - return false -} - -func (d *apiLibraryDecorator) hasStubsVariants() bool { - return d.hasApexStubs() -} - -func (d *apiLibraryDecorator) stubsVersions(ctx android.BaseModuleContext) []string { - m, ok := ctx.Module().(*Module) - - if !ok { - return nil - } - - // TODO(b/244244438) Create more version information for NDK and APEX variations - // NDK variants - if m.IsSdkVariant() { - // TODO(b/249193999) Do not check if module has NDK stubs once all NDK cc_api_library contains ndk variant of cc_api_variant. - if d.hasNDKStubs() { - return d.getNdkVersions() - } - } - - if d.hasLLNDKStubs() && m.InVendorOrProduct() { - // LLNDK libraries only need a single stubs variant. - return []string{android.FutureApiLevel.String()} - } - - stubsVersions := d.getStubVersions() - - if len(stubsVersions) != 0 { - return stubsVersions - } - - if m.MinSdkVersion() == "" { - return nil - } - - firstVersion, err := nativeApiLevelFromUser(ctx, - m.MinSdkVersion()) - - if err != nil { - return nil - } - - return ndkLibraryVersions(ctx, firstVersion) -} - -func (d *apiLibraryDecorator) hasLLNDKStubs() bool { - return inList("llndk", d.properties.Variants) -} - -func (d *apiLibraryDecorator) hasNDKStubs() bool { - for _, variant := range d.properties.Variants { - if ndkVariantRegex.MatchString(variant) { - return true - } - } - return false -} - -func (d *apiLibraryDecorator) getNdkVersions() []string { - ndkVersions := []string{} - - for _, variant := range d.properties.Variants { - if match := ndkVariantRegex.FindStringSubmatch(variant); len(match) == 2 { - ndkVersions = append(ndkVersions, match[1]) - } - } - - return ndkVersions -} - -func (d *apiLibraryDecorator) getStubVersions() []string { - stubVersions := []string{} - - for _, variant := range d.properties.Variants { - if match := stubVariantRegex.FindStringSubmatch(variant); len(match) == 2 { - stubVersions = append(stubVersions, match[1]) - } - } - - return stubVersions -} - -// 'cc_api_headers' is similar with 'cc_api_library', but which replaces -// header libraries. The module will replace any dependencies to existing -// original header libraries. -type apiHeadersDecorator struct { - *libraryDecorator -} - -func CcApiHeadersFactory() android.Module { - module, decorator := NewLibrary(android.DeviceSupported) - apiHeadersDecorator := &apiHeadersDecorator{ - libraryDecorator: decorator, - } - apiHeadersDecorator.HeaderOnly() - - module.stl = nil - module.sanitize = nil - decorator.disableStripping() - - module.compiler = nil - module.linker = apiHeadersDecorator - module.installer = nil - - // Prevent default system libs (libc, libm, and libdl) from being linked - if apiHeadersDecorator.baseLinker.Properties.System_shared_libs == nil { - apiHeadersDecorator.baseLinker.Properties.System_shared_libs = []string{} - } - - apiHeadersDecorator.baseLinker.Properties.No_libcrt = BoolPtr(true) - apiHeadersDecorator.baseLinker.Properties.Nocrt = BoolPtr(true) - - module.Init() - - return module -} - -func (d *apiHeadersDecorator) Name(basename string) string { - return basename + multitree.GetApiImportSuffix() -} - -func (d *apiHeadersDecorator) availableFor(what string) bool { - // Stub from API surface should be available for any APEX. - return true -} - -type ccApiexportProperties struct { - Src *string `android:"arch_variant"` - Variant *string - Version *string -} - -type variantExporterProperties struct { - // Header directory to export - Export_include_dirs []string `android:"arch_variant"` - - // Export all headers as system include - Export_headers_as_system *bool -} - -type CcApiVariant struct { - android.ModuleBase - - properties ccApiexportProperties - exportProperties variantExporterProperties - - src android.Path -} - -var _ android.Module = (*CcApiVariant)(nil) -var _ android.ImageInterface = (*CcApiVariant)(nil) - -func CcApiVariantFactory() android.Module { - module := &CcApiVariant{} - - module.AddProperties(&module.properties) - module.AddProperties(&module.exportProperties) - - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) - return module -} - -func (v *CcApiVariant) GenerateAndroidBuildActions(ctx android.ModuleContext) { - // No need to build - - if String(v.properties.Src) == "" { - ctx.PropertyErrorf("src", "src is a required property") - } - - // Skip the existence check of the stub prebuilt file. - // The file is not guaranteed to exist during Soong analysis. - // Build orchestrator will be responsible for creating a connected ninja graph. - v.src = android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), String(v.properties.Src)) -} - -func (v *CcApiVariant) Name() string { - version := String(v.properties.Version) - return BuildApiVariantName(v.BaseModuleName(), *v.properties.Variant, version) -} - -func (v *CcApiVariant) Src() android.Path { - return v.src -} - -func BuildApiVariantName(baseName string, variant string, version string) string { - names := []string{baseName, variant} - if version != "" { - names = append(names, version) - } - - return strings.Join(names[:], ".") + multitree.GetApiImportSuffix() -} - -// Implement ImageInterface to generate image variants -func (v *CcApiVariant) ImageMutatorBegin(ctx android.BaseModuleContext) {} -func (v *CcApiVariant) VendorVariantNeeded(ctx android.BaseModuleContext) bool { - return String(v.properties.Variant) == "llndk" -} -func (v *CcApiVariant) ProductVariantNeeded(ctx android.BaseModuleContext) bool { - return String(v.properties.Variant) == "llndk" -} -func (v *CcApiVariant) CoreVariantNeeded(ctx android.BaseModuleContext) bool { - return inList(String(v.properties.Variant), []string{"ndk", "apex"}) -} -func (v *CcApiVariant) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (v *CcApiVariant) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (v *CcApiVariant) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (v *CcApiVariant) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { return false } -func (v *CcApiVariant) ExtraImageVariations(ctx android.BaseModuleContext) []string { return nil } -func (v *CcApiVariant) SetImageVariation(ctx android.BaseModuleContext, variation string) { -} diff --git a/cc/linker.go b/cc/linker.go index 00568177f..1efacade8 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -645,7 +645,7 @@ func (linker *baseLinker) link(ctx ModuleContext, panic(fmt.Errorf("baseLinker doesn't know how to link")) } -func (linker *baseLinker) linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps { +func (linker *baseLinker) linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps { eval := module.ConfigurableEvaluator(ctx) specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, linker.Properties.Shared_libs.GetOrDefault(eval, nil)...) diff --git a/cc/object.go b/cc/object.go index a4f4c8408..c89520ab7 100644 --- a/cc/object.go +++ b/cc/object.go @@ -203,7 +203,7 @@ func (object *objectLinker) link(ctx ModuleContext, return outputFile } -func (object *objectLinker) linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps { +func (object *objectLinker) linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps { eval := module.ConfigurableEvaluator(ctx) specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, object.Properties.Shared_libs.GetOrDefault(eval, nil)...) @@ -51,13 +51,6 @@ func (sdkTransitionMutator) Split(ctx android.BaseModuleContext) []string { return []string{""} } } - case *CcApiVariant: - ccApiVariant, _ := ctx.Module().(*CcApiVariant) - if String(ccApiVariant.properties.Variant) == "ndk" { - return []string{"sdk"} - } else { - return []string{""} - } } return []string{""} @@ -84,11 +77,6 @@ func (sdkTransitionMutator) IncomingTransition(ctx android.IncomingTransitionCon return incomingVariation } } - case *CcApiVariant: - ccApiVariant, _ := ctx.Module().(*CcApiVariant) - if String(ccApiVariant.properties.Variant) == "ndk" { - return "sdk" - } } if ctx.IsAddingDependency() { diff --git a/cc/testing.go b/cc/testing.go index 159f86c60..14a6b7a6a 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -20,7 +20,6 @@ import ( "android/soong/android" "android/soong/genrule" - "android/soong/multitree" ) func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) { @@ -29,9 +28,6 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) { RegisterBinaryBuildComponents(ctx) RegisterLibraryBuildComponents(ctx) RegisterLibraryHeadersBuildComponents(ctx) - RegisterLibraryStubBuildComponents(ctx) - - multitree.RegisterApiImportsModule(ctx) ctx.RegisterModuleType("prebuilt_build_tool", android.NewPrebuiltBuildTool) ctx.RegisterModuleType("cc_benchmark", BenchmarkFactory) diff --git a/docs/OWNERS b/docs/OWNERS new file mode 100644 index 000000000..776beca32 --- /dev/null +++ b/docs/OWNERS @@ -0,0 +1 @@ +per-file map_files.md = danalbert@google.com diff --git a/docs/map_files.md b/docs/map_files.md index e1ddefc27..8d6af879f 100644 --- a/docs/map_files.md +++ b/docs/map_files.md @@ -88,12 +88,17 @@ but is useful when developing APIs for an unknown future release. ### introduced -Indicates the version in which an API was first introduced. For example, -`introduced=21` specifies that the API was first added (or first made public) in -API level 21. This tag can be applied to either a version definition or an -individual symbol. If applied to a version, all symbols contained in the version -will have the tag applied. An `introduced` tag on a symbol overrides the value -set for the version, if both are defined. +Indicates the version in which an API was first introduced in the NDK. For +example, `introduced=21` specifies that the API was first added (or first made +public) in API level 21. This tag can be applied to either a version definition +or an individual symbol. If applied to a version, all symbols contained in the +version will have the tag applied. An `introduced` tag on a symbol overrides the +value set for the version, if both are defined. + +The `introduced` tag should only be used with NDK APIs. Other API surface tags +(such as `apex`) will override `introduced`. APIs that are in the NDK should +never use tags like `apex`, and APIs that are not in the NDK should never use +`introduced`. Note: The map file alone does not contain all the information needed to determine which API level an API was added in. The `first_version` property of diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index a8f97e3b7..0b390624f 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -136,9 +136,6 @@ type filesystemProperties struct { // Install aconfig_flags.pb file for the modules installed in this partition. Gen_aconfig_flags_pb *bool - // Update the Base_dir of the $PRODUCT_OUT directory with the packaging files. - Update_product_out *bool - Fsverity fsverityProperties } @@ -335,7 +332,7 @@ func (f *filesystem) copyPackagingSpecs(ctx android.ModuleContext, builder *andr } func (f *filesystem) copyFilesToProductOut(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { - if !proptools.Bool(f.properties.Update_product_out) { + if f.Name() != ctx.Config().SoongDefinedSystemImage() { return } installPath := android.PathForModuleInPartitionInstall(ctx, f.partitionName()) diff --git a/filesystem/vbmeta.go b/filesystem/vbmeta.go index 3a9a64daa..1d647965a 100644 --- a/filesystem/vbmeta.go +++ b/filesystem/vbmeta.go @@ -213,6 +213,7 @@ func (v *vbmeta) GenerateAndroidBuildActions(ctx android.ModuleContext) { ctx.InstallFile(v.installDir, v.installFileName(), v.output) ctx.SetOutputFiles([]android.Path{v.output}, "") + android.SetProvider(ctx, android.AndroidMkInfoProvider, v.prepareAndroidMKProviderInfo()) } // Returns the embedded shell command that prints the rollback index @@ -265,20 +266,17 @@ func (v *vbmeta) extractPublicKeys(ctx android.ModuleContext) map[string]android return result } -var _ android.AndroidMkEntriesProvider = (*vbmeta)(nil) - -// Implements android.AndroidMkEntriesProvider -func (v *vbmeta) AndroidMkEntries() []android.AndroidMkEntries { - return []android.AndroidMkEntries{android.AndroidMkEntries{ - Class: "ETC", - OutputFile: android.OptionalPathForPath(v.output), - ExtraEntries: []android.AndroidMkExtraEntriesFunc{ - func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", v.installDir.String()) - entries.SetString("LOCAL_INSTALLED_MODULE_STEM", v.installFileName()) - }, +func (v *vbmeta) prepareAndroidMKProviderInfo() *android.AndroidMkProviderInfo { + providerData := android.AndroidMkProviderInfo{ + PrimaryInfo: android.AndroidMkInfo{ + Class: "ETC", + OutputFile: android.OptionalPathForPath(v.output), + EntryMap: make(map[string][]string), }, - }} + } + providerData.PrimaryInfo.SetString("LOCAL_MODULE_PATH", v.installDir.String()) + providerData.PrimaryInfo.SetString("LOCAL_INSTALLED_MODULE_STEM", v.installFileName()) + return &providerData } var _ Filesystem = (*vbmeta)(nil) diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go index 306d65e29..a0598376b 100644 --- a/fuzz/fuzz_common.go +++ b/fuzz/fuzz_common.go @@ -449,7 +449,7 @@ func IsValidFrameworkForModule(targetFramework Framework, lang Lang, moduleFrame } } -func IsValid(ctx android.ConfigAndErrorContext, fuzzModule FuzzModule) bool { +func IsValid(ctx android.ConfigurableEvaluatorContext, fuzzModule FuzzModule) bool { // Discard ramdisk + vendor_ramdisk + recovery modules, they're duplicates of // fuzz targets we're going to package anyway. if !fuzzModule.Enabled(ctx) || fuzzModule.InRamdisk() || fuzzModule.InVendorRamdisk() || fuzzModule.InRecovery() { diff --git a/java/boot_jars.go b/java/boot_jars.go index 6223dede8..3c3bd550c 100644 --- a/java/boot_jars.go +++ b/java/boot_jars.go @@ -21,7 +21,7 @@ import ( // isActiveModule returns true if the given module should be considered for boot // jars, i.e. if it's enabled and the preferred one in case of source and // prebuilt alternatives. -func isActiveModule(ctx android.ConfigAndErrorContext, module android.Module) bool { +func isActiveModule(ctx android.ConfigurableEvaluatorContext, module android.Module) bool { if !module.Enabled(ctx) { return false } diff --git a/multitree/Android.bp b/multitree/Android.bp deleted file mode 100644 index 78c49627b..000000000 --- a/multitree/Android.bp +++ /dev/null @@ -1,20 +0,0 @@ -package { - default_applicable_licenses: ["Android-Apache-2.0"], -} - -bootstrap_go_package { - name: "soong-multitree", - pkgPath: "android/soong/multitree", - deps: [ - "blueprint", - "soong-android", - ], - srcs: [ - "api_imports.go", - "api_surface.go", - "export.go", - "metadata.go", - "import.go", - ], - pluginFor: ["soong_build"], -} diff --git a/multitree/api_imports.go b/multitree/api_imports.go deleted file mode 100644 index 51b9e07a5..000000000 --- a/multitree/api_imports.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2022 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 multitree - -import ( - "android/soong/android" - "strings" - - "github.com/google/blueprint" -) - -var ( - apiImportNameSuffix = ".apiimport" -) - -func init() { - RegisterApiImportsModule(android.InitRegistrationContext) - android.RegisterMakeVarsProvider(pctx, makeVarsProvider) -} - -func RegisterApiImportsModule(ctx android.RegistrationContext) { - ctx.RegisterModuleType("api_imports", apiImportsFactory) -} - -type ApiImports struct { - android.ModuleBase - properties apiImportsProperties -} - -type apiImportsProperties struct { - Shared_libs []string // List of C shared libraries from API surfaces - Header_libs []string // List of C header libraries from API surfaces - Apex_shared_libs []string // List of C shared libraries with APEX stubs -} - -// 'api_imports' is a module which describes modules available from API surfaces. -// This module is required to get the list of all imported API modules, because -// it is discouraged to loop and fetch all modules from its type information. The -// only module with name 'api_imports' will be used from the build. -func apiImportsFactory() android.Module { - module := &ApiImports{} - module.AddProperties(&module.properties) - android.InitAndroidModule(module) - return module -} - -func (imports *ApiImports) GenerateAndroidBuildActions(ctx android.ModuleContext) { - // ApiImport module does not generate any build actions -} - -type ApiImportInfo struct { - SharedLibs, HeaderLibs, ApexSharedLibs map[string]string -} - -var ApiImportsProvider = blueprint.NewMutatorProvider[ApiImportInfo]("deps") - -// Store module lists into ApiImportInfo and share it over mutator provider. -func (imports *ApiImports) DepsMutator(ctx android.BottomUpMutatorContext) { - generateNameMapWithSuffix := func(names []string) map[string]string { - moduleNameMap := make(map[string]string) - for _, name := range names { - moduleNameMap[name] = name + apiImportNameSuffix - } - - return moduleNameMap - } - - sharedLibs := generateNameMapWithSuffix(imports.properties.Shared_libs) - headerLibs := generateNameMapWithSuffix(imports.properties.Header_libs) - apexSharedLibs := generateNameMapWithSuffix(imports.properties.Apex_shared_libs) - - android.SetProvider(ctx, ApiImportsProvider, ApiImportInfo{ - SharedLibs: sharedLibs, - HeaderLibs: headerLibs, - ApexSharedLibs: apexSharedLibs, - }) -} - -func GetApiImportSuffix() string { - return apiImportNameSuffix -} - -func makeVarsProvider(ctx android.MakeVarsContext) { - ctx.VisitAllModules(func(m android.Module) { - if i, ok := m.(*ApiImports); ok { - ctx.Strict("API_IMPORTED_SHARED_LIBRARIES", strings.Join(i.properties.Shared_libs, " ")) - ctx.Strict("API_IMPORTED_HEADER_LIBRARIES", strings.Join(i.properties.Header_libs, " ")) - } - }) -} diff --git a/multitree/api_surface.go b/multitree/api_surface.go deleted file mode 100644 index 0f605d84a..000000000 --- a/multitree/api_surface.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2021 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 multitree - -import ( - "android/soong/android" - "github.com/google/blueprint" -) - -var ( - pctx = android.NewPackageContext("android/soong/multitree") -) - -func init() { - RegisterApiSurfaceBuildComponents(android.InitRegistrationContext) -} - -var PrepareForTestWithApiSurface = android.FixtureRegisterWithContext(RegisterApiSurfaceBuildComponents) - -func RegisterApiSurfaceBuildComponents(ctx android.RegistrationContext) { - ctx.RegisterModuleType("api_surface", ApiSurfaceFactory) -} - -type ApiSurface struct { - android.ModuleBase - ExportableModuleBase - properties apiSurfaceProperties - - taggedOutputs map[string]android.Paths -} - -type apiSurfaceProperties struct { - Contributions []string -} - -func ApiSurfaceFactory() android.Module { - module := &ApiSurface{} - module.AddProperties(&module.properties) - android.InitAndroidModule(module) - InitExportableModule(module) - return module -} - -func (surface *ApiSurface) DepsMutator(ctx android.BottomUpMutatorContext) { - if surface.properties.Contributions != nil { - ctx.AddVariationDependencies(nil, nil, surface.properties.Contributions...) - } - -} -func (surface *ApiSurface) GenerateAndroidBuildActions(ctx android.ModuleContext) { - contributionFiles := make(map[string]android.Paths) - var allOutputs android.Paths - ctx.WalkDeps(func(child, parent android.Module) bool { - if contribution, ok := child.(ApiContribution); ok { - copied := contribution.CopyFilesWithTag(ctx) - for tag, files := range copied { - contributionFiles[child.Name()+"#"+tag] = files - } - for _, paths := range copied { - allOutputs = append(allOutputs, paths...) - } - return false // no transitive dependencies - } - return false - }) - - // phony target - ctx.Build(pctx, android.BuildParams{ - Rule: blueprint.Phony, - Output: android.PathForPhony(ctx, ctx.ModuleName()), - Inputs: allOutputs, - }) - - surface.taggedOutputs = contributionFiles - - ctx.SetOutputFiles(allOutputs, "") -} - -func (surface *ApiSurface) TaggedOutputs() map[string]android.Paths { - return surface.taggedOutputs -} - -func (surface *ApiSurface) Exportable() bool { - return true -} - -var _ Exportable = (*ApiSurface)(nil) - -type ApiContribution interface { - // copy files necessaryt to construct an API surface - // For C, it will be map.txt and .h files - // For Java, it will be api.txt - CopyFilesWithTag(ctx android.ModuleContext) map[string]android.Paths // output paths - - // Generate Android.bp in out/ to use the exported .txt files - // GenerateBuildFiles(ctx ModuleContext) Paths //output paths -} diff --git a/multitree/export.go b/multitree/export.go deleted file mode 100644 index 8be8f7058..000000000 --- a/multitree/export.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2022 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 multitree - -import ( - "android/soong/android" - - "github.com/google/blueprint/proptools" -) - -type moduleExportProperty struct { - // True if the module is exported to the other components in a multi-tree. - // Any components in the multi-tree can import this module to use. - Export *bool -} - -type ExportableModuleBase struct { - properties moduleExportProperty -} - -type Exportable interface { - // Properties for the exporable module. - exportableModuleProps() *moduleExportProperty - - // Check if this module can be exported. - // If this returns false, the module will not be exported regardless of the 'export' value. - Exportable() bool - - // Returns 'true' if this module has 'export: true' - // This module will not be exported if it returns 'false' to 'Exportable()' interface even if - // it has 'export: true'. - IsExported() bool - - // Map from tags to outputs. - // Each module can tag their outputs for convenience. - TaggedOutputs() map[string]android.Paths -} - -type ExportableModule interface { - android.Module - Exportable -} - -func InitExportableModule(module ExportableModule) { - module.AddProperties(module.exportableModuleProps()) -} - -func (m *ExportableModuleBase) exportableModuleProps() *moduleExportProperty { - return &m.properties -} - -func (m *ExportableModuleBase) IsExported() bool { - return proptools.Bool(m.properties.Export) -} diff --git a/multitree/import.go b/multitree/import.go deleted file mode 100644 index 1e5c421bc..000000000 --- a/multitree/import.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2022 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 multitree - -import ( - "android/soong/android" -) - -var ( - nameSuffix = ".imported" -) - -type MultitreeImportedModuleInterface interface { - GetMultitreeImportedModuleName() string -} - -func init() { - android.RegisterModuleType("imported_filegroup", importedFileGroupFactory) - - android.PreArchMutators(RegisterMultitreePreArchMutators) -} - -type importedFileGroupProperties struct { - // Imported modules from the other components in a multi-tree - Imported []string -} - -type importedFileGroup struct { - android.ModuleBase - - properties importedFileGroupProperties - srcs android.Paths -} - -func (ifg *importedFileGroup) Name() string { - return ifg.BaseModuleName() + nameSuffix -} - -func importedFileGroupFactory() android.Module { - module := &importedFileGroup{} - module.AddProperties(&module.properties) - - android.InitAndroidModule(module) - return module -} - -var _ MultitreeImportedModuleInterface = (*importedFileGroup)(nil) - -func (ifg *importedFileGroup) GetMultitreeImportedModuleName() string { - // The base module name of the imported filegroup is used as the imported module name - return ifg.BaseModuleName() -} - -var _ android.SourceFileProducer = (*importedFileGroup)(nil) - -func (ifg *importedFileGroup) Srcs() android.Paths { - return ifg.srcs -} - -func (ifg *importedFileGroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { - // srcs from this module must not be used. Adding a dot path to avoid the empty - // source failure. Still soong returns error when a module wants to build against - // this source, which is intended. - ifg.srcs = android.PathsForModuleSrc(ctx, []string{"."}) -} - -func RegisterMultitreePreArchMutators(ctx android.RegisterMutatorsContext) { - ctx.BottomUp("multitree_imported_rename", MultitreeImportedRenameMutator).Parallel() -} - -func MultitreeImportedRenameMutator(ctx android.BottomUpMutatorContext) { - if m, ok := ctx.Module().(MultitreeImportedModuleInterface); ok { - name := m.GetMultitreeImportedModuleName() - if !ctx.OtherModuleExists(name) { - // Provide an empty filegroup not to break the build while updating the metadata. - // In other cases, soong will report an error to guide users to run 'm update-meta' - // first. - if !ctx.Config().TargetMultitreeUpdateMeta() { - ctx.ModuleErrorf("\"%s\" filegroup must be imported.\nRun 'm update-meta' first to import the filegroup.", name) - } - ctx.Rename(name) - } - } -} diff --git a/multitree/metadata.go b/multitree/metadata.go deleted file mode 100644 index 0eb0efc95..000000000 --- a/multitree/metadata.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2022 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 multitree - -import ( - "android/soong/android" - "encoding/json" -) - -func init() { - android.RegisterParallelSingletonType("update-meta", UpdateMetaSingleton) -} - -func UpdateMetaSingleton() android.Singleton { - return &updateMetaSingleton{} -} - -type jsonImported struct { - FileGroups map[string][]string `json:",omitempty"` -} - -type metadataJsonFlags struct { - Imported jsonImported `json:",omitempty"` - Exported map[string][]string `json:",omitempty"` -} - -type updateMetaSingleton struct { - importedModules []string - generatedMetadataFile android.OutputPath -} - -func (s *updateMetaSingleton) GenerateBuildActions(ctx android.SingletonContext) { - metadata := metadataJsonFlags{ - Imported: jsonImported{ - FileGroups: make(map[string][]string), - }, - Exported: make(map[string][]string), - } - ctx.VisitAllModules(func(module android.Module) { - if ifg, ok := module.(*importedFileGroup); ok { - metadata.Imported.FileGroups[ifg.BaseModuleName()] = ifg.properties.Imported - } - if e, ok := module.(ExportableModule); ok { - if e.IsExported() && e.Exportable() { - for tag, files := range e.TaggedOutputs() { - // TODO(b/219846705): refactor this to a dictionary - metadata.Exported[e.Name()+":"+tag] = append(metadata.Exported[e.Name()+":"+tag], files.Strings()...) - } - } - } - }) - jsonStr, err := json.Marshal(metadata) - if err != nil { - ctx.Errorf(err.Error()) - } - s.generatedMetadataFile = android.PathForOutput(ctx, "multitree", "metadata.json") - android.WriteFileRule(ctx, s.generatedMetadataFile, string(jsonStr)) -} - -func (s *updateMetaSingleton) MakeVars(ctx android.MakeVarsContext) { - ctx.Strict("MULTITREE_METADATA", s.generatedMetadataFile.String()) -} diff --git a/rust/rust.go b/rust/rust.go index 240c22178..50f822b53 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -29,7 +29,6 @@ import ( "android/soong/cc" cc_config "android/soong/cc/config" "android/soong/fuzz" - "android/soong/multitree" "android/soong/rust/config" ) @@ -1218,47 +1217,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { skipModuleList := map[string]bool{} - var apiImportInfo multitree.ApiImportInfo - hasApiImportInfo := false - - ctx.VisitDirectDeps(func(dep android.Module) { - if dep.Name() == "api_imports" { - apiImportInfo, _ = android.OtherModuleProvider(ctx, dep, multitree.ApiImportsProvider) - hasApiImportInfo = true - } - }) - - if hasApiImportInfo { - targetStubModuleList := map[string]string{} - targetOrigModuleList := map[string]string{} - - // Search for dependency which both original module and API imported library with APEX stub exists - ctx.VisitDirectDeps(func(dep android.Module) { - depName := ctx.OtherModuleName(dep) - if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok { - targetStubModuleList[apiLibrary] = depName - } - }) - ctx.VisitDirectDeps(func(dep android.Module) { - depName := ctx.OtherModuleName(dep) - if origLibrary, ok := targetStubModuleList[depName]; ok { - targetOrigModuleList[origLibrary] = depName - } - }) - - // Decide which library should be used between original and API imported library - ctx.VisitDirectDeps(func(dep android.Module) { - depName := ctx.OtherModuleName(dep) - if apiLibrary, ok := targetOrigModuleList[depName]; ok { - if cc.ShouldUseStubForApex(ctx, dep) { - skipModuleList[depName] = true - } else { - skipModuleList[apiLibrary] = true - } - } - }) - } - var transitiveAndroidMkSharedLibs []*android.DepSet[string] var directAndroidMkSharedLibs []string @@ -1609,13 +1567,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { deps := mod.deps(ctx) var commonDepVariations []blueprint.Variation - apiImportInfo := cc.GetApiImports(mod, actx) - if mod.usePublicApi() || mod.useVendorApi() { - for idx, lib := range deps.SharedLibs { - deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs) - } - } - if ctx.Os() == android.Android { deps.SharedLibs, _ = cc.FilterNdkLibs(mod, ctx.Config(), deps.SharedLibs) } @@ -1708,15 +1659,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { variations := []blueprint.Variation{ {Mutator: "link", Variation: "shared"}, } - // For core variant, add a dep on the implementation (if it exists) and its .apiimport (if it exists) - // GenerateAndroidBuildActions will pick the correct impl/stub based on the api_domain boundary - if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) { - cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) - } - - if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok { - cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, apiLibraryName, version, false) - } + cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) } for _, lib := range deps.WholeStaticLibs { diff --git a/sdk/sdk.go b/sdk/sdk.go index 2fb3a3f30..aa82abbb4 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -84,20 +84,6 @@ type sdkProperties struct { // True if this is a module_exports (or module_exports_snapshot) module type. Module_exports bool `blueprint:"mutated"` - - // The additional visibility to add to the prebuilt modules to allow them to - // reference each other. - // - // This can only be used to widen the visibility of the members: - // - // * Specifying //visibility:public here will make all members visible and - // essentially ignore their own visibility. - // * Specifying //visibility:private here is an error. - // * Specifying any other rule here will add it to the members visibility and - // be output to the member prebuilt in the snapshot. Duplicates will be - // dropped. Adding a rule to members that have //visibility:private will - // cause the //visibility:private to be discarded. - Prebuilt_visibility []string } // sdk defines an SDK which is a logical group of modules (e.g. native libs, headers, java libs, etc.) @@ -130,8 +116,6 @@ func newSdkModule(moduleExports bool) *sdk { s.AddProperties(&s.properties, s.dynamicMemberTypeListProperties, &traitsWrapper) - // Make sure that the prebuilt visibility property is verified for errors. - android.AddVisibilityProperty(s, "prebuilt_visibility", &s.properties.Prebuilt_visibility) android.InitCommonOSAndroidMultiTargetsArchModule(s, android.HostAndDeviceSupported, android.MultilibCommon) android.InitDefaultableModule(s) android.AddLoadHook(s, func(ctx android.LoadHookContext) { diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 416dce62c..2532a2581 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -53,9 +53,6 @@ func TestSnapshotVisibility(t *testing.T) { // generated sdk_snapshot. ":__subpackages__", ], - prebuilt_visibility: [ - "//prebuilts/mysdk", - ], java_header_libs: [ "myjavalib", "mypublicjavalib", @@ -162,18 +159,6 @@ java_import { `)) } -func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) { - testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, ` - sdk { - name: "mysdk", - prebuilt_visibility: [ - "//foo", - "//visibility:private", - ], - } -`) -} - func TestSdkInstall(t *testing.T) { sdk := ` sdk { diff --git a/sdk/update.go b/sdk/update.go index 93bb861e9..7f4f80a34 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -22,7 +22,6 @@ import ( "sort" "strings" - "android/soong/apex" "android/soong/cc" "android/soong/java" @@ -1137,9 +1136,6 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType apexAvailable = []string{android.AvailableToPlatform} } - // Add in any baseline apex available settings. - apexAvailable = append(apexAvailable, apex.BaselineApexAvailable(member.Name())...) - // Remove duplicates and sort. apexAvailable = android.FirstUniqueStrings(apexAvailable) sort.Strings(apexAvailable) @@ -1993,14 +1989,6 @@ func (m *memberContext) IsTargetBuildBeforeTiramisu() bool { return m.builder.targetBuildRelease.EarlierThan(buildReleaseT) } -func (m *memberContext) Config() android.Config { - return m.sdkMemberContext.Config() -} - -func (m *memberContext) OtherModulePropertyErrorf(module android.Module, property string, fmt string, args ...interface{}) { - m.sdkMemberContext.OtherModulePropertyErrorf(module, property, fmt, args) -} - var _ android.SdkMemberContext = (*memberContext)(nil) func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { diff --git a/ui/build/androidmk_denylist.go b/ui/build/androidmk_denylist.go index 2bad5a88f..2ec897273 100644 --- a/ui/build/androidmk_denylist.go +++ b/ui/build/androidmk_denylist.go @@ -25,6 +25,8 @@ var androidmk_denylist []string = []string{ "dalvik/", "developers/", "development/", + "device/common/", + "device/google_car/", "device/sample/", "frameworks/", // Do not block other directories in kernel/, see b/319658303. @@ -41,6 +43,15 @@ var androidmk_denylist []string = []string{ "trusty/", // Add back toolchain/ once defensive Android.mk files are removed //"toolchain/", + "vendor/google_contexthub/", + "vendor/google_data/", + "vendor/google_elmyra/", + "vendor/google_mhl/", + "vendor/google_pdk/", + "vendor/google_testing/", + "vendor/partner_testing/", + "vendor/partner_tools/", + "vendor/pdk/", } func blockAndroidMks(ctx Context, androidMks []string) { diff --git a/ui/build/soong.go b/ui/build/soong.go index 76a3e3536..97bc9971e 100644 --- a/ui/build/soong.go +++ b/ui/build/soong.go @@ -759,7 +759,10 @@ func checkGlobs(ctx Context, finalOutFile string) error { hasNewDep := false for _, dep := range cachedGlob.Deps { info, err := os.Stat(dep) - if err != nil { + if errors.Is(err, fs.ErrNotExist) { + hasNewDep = true + break + } else if err != nil { errorsChan <- err continue } |