From bad1eef6d8945883ecb2fa076ca505146a5895de Mon Sep 17 00:00:00 2001 From: Yu Liu Date: Wed, 21 Aug 2024 22:37:35 +0000 Subject: [PATCH] Remove installFilesDepSet, packagingSpecsDepSet and licenseInstallMap from ModuleBase. The old packagingSpecsDepSet field is kept temporarily to bypass an auto-merge issue, and will be removed in next change. Bug: 358425833 Test: CI Change-Id: I28b4933459c33224f756cc306cabc8088f9be862 --- android/license_metadata.go | 2 +- android/module.go | 48 ++++++++++++------------- android/module_context.go | 70 ++++++++++++++++++++++--------------- android/packaging.go | 3 +- apex/builder.go | 2 +- genrule/genrule.go | 3 +- 6 files changed, 70 insertions(+), 58 deletions(-) diff --git a/android/license_metadata.go b/android/license_metadata.go index cd697495f..0ac975fa2 100644 --- a/android/license_metadata.go +++ b/android/license_metadata.go @@ -152,7 +152,7 @@ func buildLicenseMetadata(ctx *moduleContext, licenseMetadataFile WritablePath) // Install map args = append(args, - JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.licenseInstallMap), "-m ")) + JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(ctx.licenseInstallMap), "-m ")) // Built files if len(outputFiles) > 0 { diff --git a/android/module.go b/android/module.go index e74af838e..9e882ec06 100644 --- a/android/module.go +++ b/android/module.go @@ -836,7 +836,6 @@ type ModuleBase struct { primaryLicensesProperty applicableLicensesProperty noAddressSanitizer bool - installFilesDepSet *DepSet[InstallPath] packagingSpecsDepSet *DepSet[PackagingSpec] // katiInitRcInstalls and katiVintfInstalls track the install rules created by Soong that are // allowed to have duplicates across modules and variants. @@ -864,10 +863,6 @@ type ModuleBase struct { // Merged Aconfig files for all transitive deps. aconfigFilePaths Paths - // set of dependency module:location mappings used to populate the license metadata for - // apex containers. - licenseInstallMap []string - // The path to the generated license metadata file for the module. licenseMetadataFile WritablePath @@ -1454,12 +1449,13 @@ func (m *ModuleBase) computeInstallDeps(ctx ModuleContext) ([]*DepSet[InstallPat if isInstallDepNeeded(dep, ctx.OtherModuleDependencyTag(dep)) { // Installation is still handled by Make, so anything hidden from Make is not // installable. + info := OtherModuleProviderOrDefault(ctx, dep, InstallFilesProvider) if !dep.IsHideFromMake() && !dep.IsSkipInstall() { - installDeps = append(installDeps, dep.base().installFilesDepSet) + installDeps = append(installDeps, info.TransitiveInstallFiles) } // Add packaging deps even when the dependency is not installed so that uninstallable // modules can still be packaged. Often the package will be installed instead. - packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet) + packagingSpecs = append(packagingSpecs, info.TransitivePackagingSpecs) } }) @@ -1606,12 +1602,6 @@ func (m *ModuleBase) CompileMultilib() *string { return m.base().commonProperties.Compile_multilib } -// SetLicenseInstallMap stores the set of dependency module:location mappings for files in an -// apex container for use when generation the license metadata file. -func (m *ModuleBase) SetLicenseInstallMap(installMap []string) { - m.licenseInstallMap = append(m.licenseInstallMap, installMap...) -} - func (m *ModuleBase) generateModuleTarget(ctx *moduleContext) { var allInstalledFiles InstallPaths var allCheckbuildFiles Paths @@ -1781,9 +1771,12 @@ type InstallFilesInfo struct { KatiInstalls katiInstalls KatiSymlinks katiInstalls TestData []DataPath + // This was private before, make it private again once we have better solution. + TransitiveInstallFiles *DepSet[InstallPath] + TransitivePackagingSpecs *DepSet[PackagingSpec] } -var FinalModuleBuildTargetsProvider = blueprint.NewProvider[FinalModuleBuildTargetsInfo]() +var InstallFilesProvider = blueprint.NewProvider[InstallFilesInfo]() type FinalModuleBuildTargetsInfo struct { // Used by buildTargetSingleton to create checkbuild and per-directory build targets @@ -1793,7 +1786,7 @@ type FinalModuleBuildTargetsInfo struct { BlueprintDir string } -var InstallFilesProvider = blueprint.NewProvider[InstallFilesInfo]() +var FinalModuleBuildTargetsProvider = blueprint.NewProvider[FinalModuleBuildTargetsInfo]() func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) { ctx := &moduleContext{ @@ -1809,10 +1802,10 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) m.licenseMetadataFile = PathForModuleOut(ctx, "meta_lic") dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx) - // set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies + // set the TransitiveInstallFiles to only the transitive dependencies to be used as the dependencies // of installed files of this module. It will be replaced by a depset including the installed // files of this module at the end for use by modules that depend on this one. - m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, nil, dependencyInstallFiles) + ctx.TransitiveInstallFiles = NewDepSet[InstallPath](TOPOLOGICAL, nil, dependencyInstallFiles) // Temporarily continue to call blueprintCtx.GetMissingDependencies() to maintain the previous behavior of never // reporting missing dependency errors in Blueprint when AllowMissingDependencies == true. @@ -1856,6 +1849,8 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i]) } + var installFiles InstallFilesInfo + if m.Enabled(ctx) { // ensure all direct android.Module deps are enabled ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) { @@ -1977,14 +1972,12 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) return } - SetProvider(ctx, InstallFilesProvider, InstallFilesInfo{ - InstallFiles: ctx.installFiles, - CheckbuildFiles: ctx.checkbuildFiles, - PackagingSpecs: ctx.packagingSpecs, - KatiInstalls: ctx.katiInstalls, - KatiSymlinks: ctx.katiSymlinks, - TestData: ctx.testData, - }) + installFiles.InstallFiles = ctx.installFiles + installFiles.CheckbuildFiles = ctx.checkbuildFiles + installFiles.PackagingSpecs = ctx.packagingSpecs + installFiles.KatiInstalls = ctx.katiInstalls + installFiles.KatiSymlinks = ctx.katiSymlinks + installFiles.TestData = ctx.testData } else if ctx.Config().AllowMissingDependencies() { // If the module is not enabled it will not create any build rules, nothing will call // ctx.GetMissingDependencies(), and blueprint will consider the missing dependencies to be unhandled @@ -2000,9 +1993,12 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } } - m.installFilesDepSet = NewDepSet[InstallPath](TOPOLOGICAL, ctx.installFiles, dependencyInstallFiles) + ctx.TransitiveInstallFiles = NewDepSet[InstallPath](TOPOLOGICAL, ctx.installFiles, dependencyInstallFiles) + installFiles.TransitiveInstallFiles = ctx.TransitiveInstallFiles m.packagingSpecsDepSet = NewDepSet[PackagingSpec](TOPOLOGICAL, ctx.packagingSpecs, dependencyPackagingSpecs) + installFiles.TransitivePackagingSpecs = m.packagingSpecsDepSet + SetProvider(ctx, InstallFilesProvider, installFiles) buildLicenseMetadata(ctx, m.licenseMetadataFile) if m.moduleInfoJSON != nil { diff --git a/android/module_context.go b/android/module_context.go index e9fbb8c36..632fc961c 100644 --- a/android/module_context.go +++ b/android/module_context.go @@ -107,65 +107,65 @@ type ModuleContext interface { // InstallExecutable creates a rule to copy srcPath to name in the installPath directory, // with the given additional dependencies. The file is marked executable after copying. // - // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the - // installed file will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec + // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath // InstallFile creates a rule to copy srcPath to name in the installPath directory, // with the given additional dependencies. // - // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the - // installed file will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec + // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. InstallFile(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath // InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath // directory, and also unzip a zip file containing extra files to install into the same // directory. // - // The installed file will be returned by FilesToInstall(), and the PackagingSpec for the - // installed file will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The installed file can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec + // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...InstallPath) InstallPath // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath // directory. // - // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the - // installed file will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The installed symlink can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec + // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. InstallSymlink(installPath InstallPath, name string, srcPath InstallPath) InstallPath // InstallAbsoluteSymlink creates a rule to create an absolute symlink from src srcPath to name // in the installPath directory. // - // The installed symlink will be returned by FilesToInstall(), and the PackagingSpec for the - // installed file will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The installed symlink can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec + // for the installed file can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath // InstallTestData creates rules to install test data (e.g. data files used during a test) into // the installPath directory. // - // The installed files will be returned by FilesToInstall(), and the PackagingSpec for the - // installed files will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The installed files can be accessed by InstallFilesInfo.InstallFiles, and the PackagingSpec + // for the installed files can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. InstallTestData(installPath InstallPath, data []DataPath) InstallPaths // PackageFile creates a PackagingSpec as if InstallFile was called, but without creating // the rule to copy the file. This is useful to define how a module would be packaged // without installing it into the global installation directories. // - // The created PackagingSpec for the will be returned by PackagingSpecs() on this module or by - // TransitivePackagingSpecs() on modules that depend on this module through dependency tags - // for which IsInstallDepNeeded returns true. + // The created PackagingSpec can be accessed by InstallFilesInfo.PackagingSpecs on this module + // or by InstallFilesInfo.TransitivePackagingSpecs on modules that depend on this module through + // dependency tags for which IsInstallDepNeeded returns true. PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec CheckbuildFile(srcPath Path) @@ -218,6 +218,10 @@ type ModuleContext interface { GetOutputFiles() OutputFilesInfo + // SetLicenseInstallMap stores the set of dependency module:location mappings for files in an + // apex container for use when generation the license metadata file. + SetLicenseInstallMap(installMap []string) + // ComplianceMetadataInfo returns a ComplianceMetadataInfo instance for different module types to dump metadata, // which usually happens in GenerateAndroidBuildActions() of a module type. // See android.ModuleBase.complianceMetadataInfo @@ -236,6 +240,12 @@ type moduleContext struct { // the OutputFilesProvider in GenerateBuildActions outputFiles OutputFilesInfo + TransitiveInstallFiles *DepSet[InstallPath] + + // set of dependency module:location mappings used to populate the license metadata for + // apex containers. + licenseInstallMap []string + katiInstalls katiInstalls katiSymlinks katiInstalls @@ -521,7 +531,7 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat } if m.requiresFullInstall() { - deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList())...) + deps = append(deps, InstallPaths(m.TransitiveInstallFiles.ToList())...) deps = append(deps, m.module.base().installedInitRcPaths...) deps = append(deps, m.module.base().installedVintfFragmentsPaths...) @@ -738,6 +748,10 @@ func (m *moduleContext) GetOutputFiles() OutputFilesInfo { return m.outputFiles } +func (m *moduleContext) SetLicenseInstallMap(installMap []string) { + m.licenseInstallMap = append(m.licenseInstallMap, installMap...) +} + func (m *moduleContext) ComplianceMetadataInfo() *ComplianceMetadataInfo { if complianceMetadataInfo := m.module.base().complianceMetadataInfo; complianceMetadataInfo != nil { return complianceMetadataInfo diff --git a/android/packaging.go b/android/packaging.go index c247ed2a4..42009d5af 100644 --- a/android/packaging.go +++ b/android/packaging.go @@ -346,7 +346,8 @@ func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter if pi, ok := ctx.OtherModuleDependencyTag(child).(PackagingItem); !ok || !pi.IsPackagingItem() { return } - for _, ps := range child.TransitivePackagingSpecs() { + for _, ps := range OtherModuleProviderOrDefault( + ctx, child, InstallFilesProvider).TransitivePackagingSpecs.ToList() { if !filterArch(ps) { continue } diff --git a/apex/builder.go b/apex/builder.go index bfe16922d..0d084834d 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -595,7 +595,7 @@ func (a *apexBundle) buildApex(ctx android.ModuleContext) { if len(installMapSet) > 0 { var installs []string installs = append(installs, android.SortedKeys(installMapSet)...) - a.SetLicenseInstallMap(installs) + ctx.SetLicenseInstallMap(installs) } //////////////////////////////////////////////////////////////////////////////////////////// diff --git a/genrule/genrule.go b/genrule/genrule.go index 919564399..b8b996820 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -320,7 +320,8 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { ctx.ModuleErrorf("host tool %q missing output file", tool) return } - if specs := t.TransitivePackagingSpecs(); specs != nil { + if specs := android.OtherModuleProviderOrDefault( + ctx, t, android.InstallFilesProvider).TransitivePackagingSpecs.ToList(); specs != nil { // If the HostToolProvider has PackgingSpecs, which are definitions of the // required relative locations of the tool and its dependencies, use those // instead. They will be copied to those relative locations in the sbox