From 4158950c4048b2677cf37c12f8bb5f3bd412fa74 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 1 Dec 2020 14:00:21 -0800 Subject: [PATCH] Add PackageFile and use it for prebuilt build tools Add PackageFile that creates a PackageSpec like InstallFile, but doesn't create the install rule. Also improve the documentation on InstallFile and friends, and on HostToolProvider. Bug: 124313442 Test: m checkbuild Change-Id: I30f44a2b3833e48d0bb71bf7c45955f88fb00bc8 --- android/module.go | 68 +++++++++++++++++++++++++++++++--- android/prebuilt_build_tool.go | 8 +++- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/android/module.go b/android/module.go index bbdeb2733..0bd64ede6 100644 --- a/android/module.go +++ b/android/module.go @@ -338,10 +338,51 @@ type ModuleContext interface { ExpandSource(srcFile, prop string) Path ExpandOptionalSource(srcFile *string, prop string) OptionalPath + // 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. InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) 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. InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) 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. 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. InstallAbsoluteSymlink(installPath InstallPath, name string, absPath string) InstallPath + + // 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. + PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec + CheckbuildFile(srcPath Path) InstallInData() bool @@ -2428,6 +2469,22 @@ func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, return m.installFile(installPath, name, srcPath, deps, true) } +func (m *moduleContext) PackageFile(installPath InstallPath, name string, srcPath Path) PackagingSpec { + fullInstallPath := installPath.Join(m, name) + return m.packageFile(fullInstallPath, srcPath, false) +} + +func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, executable bool) PackagingSpec { + spec := PackagingSpec{ + relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), + srcPath: srcPath, + symlinkTarget: "", + executable: executable, + } + m.packagingSpecs = append(m.packagingSpecs, spec) + return spec +} + func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, executable bool) InstallPath { fullInstallPath := installPath.Join(m, name) @@ -2464,12 +2521,7 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat m.installFiles = append(m.installFiles, fullInstallPath) } - m.packagingSpecs = append(m.packagingSpecs, PackagingSpec{ - relPathInPackage: Rel(m, fullInstallPath.PartitionDir(), fullInstallPath.String()), - srcPath: srcPath, - symlinkTarget: "", - executable: executable, - }) + m.packageFile(fullInstallPath, srcPath, executable) m.checkbuildFiles = append(m.checkbuildFiles, srcPath) return fullInstallPath @@ -2677,7 +2729,11 @@ func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) } } +// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to +// specify that they can be used as a tool by a genrule module. type HostToolProvider interface { + // HostToolPath returns the path to the host tool for the module if it is one, or an invalid + // OptionalPath. HostToolPath() OptionalPath } diff --git a/android/prebuilt_build_tool.go b/android/prebuilt_build_tool.go index e2555e4c3..b00dc2f2e 100644 --- a/android/prebuilt_build_tool.go +++ b/android/prebuilt_build_tool.go @@ -57,7 +57,7 @@ func (t *prebuiltBuildTool) DepsMutator(ctx BottomUpMutatorContext) { func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) { sourcePath := t.prebuilt.SingleSourcePath(ctx) - installedPath := PathForModuleOut(ctx, t.ModuleBase.Name()) + installedPath := PathForModuleOut(ctx, t.BaseModuleName()) deps := PathsForModuleSrc(ctx, t.properties.Deps) var fromPath = sourcePath.String() @@ -75,6 +75,12 @@ func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) { }, }) + packagingDir := PathForModuleInstall(ctx, t.BaseModuleName()) + ctx.PackageFile(packagingDir, sourcePath.String(), sourcePath) + for _, dep := range deps { + ctx.PackageFile(packagingDir, dep.String(), dep) + } + t.toolPath = OptionalPathForPath(installedPath) }