Merge changes I04f2f558,Ie16a6264,I83a3be9f,Icb3eeef3

* changes:
  Rename amod variable in AndroidMkEntries.fillInEntries to base
  Make HostToolPath, HostJNIToolPath and sboxPathForToolRel use pathForInstall
  Add PathForGoBinary
  Remove PathForOutput from InstallPathToOnDevicePath
This commit is contained in:
Colin Cross
2021-10-30 19:19:53 +00:00
committed by Gerrit Code Review
7 changed files with 70 additions and 70 deletions

View File

@@ -478,8 +478,9 @@ type fillInEntriesContext interface {
func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) {
a.EntryMap = make(map[string][]string) a.EntryMap = make(map[string][]string)
amod := mod.(Module).base() amod := mod.(Module)
name := amod.BaseModuleName() base := amod.base()
name := base.BaseModuleName()
if a.OverrideName != "" { if a.OverrideName != "" {
name = a.OverrideName name = a.OverrideName
} }
@@ -487,9 +488,9 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
if a.Include == "" { if a.Include == "" {
a.Include = "$(BUILD_PREBUILT)" a.Include = "$(BUILD_PREBUILT)"
} }
a.Required = append(a.Required, mod.(Module).RequiredModuleNames()...) a.Required = append(a.Required, amod.RequiredModuleNames()...)
a.Host_required = append(a.Host_required, mod.(Module).HostRequiredModuleNames()...) a.Host_required = append(a.Host_required, amod.HostRequiredModuleNames()...)
a.Target_required = append(a.Target_required, mod.(Module).TargetRequiredModuleNames()...) a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...)
for _, distString := range a.GetDistForGoals(mod) { for _, distString := range a.GetDistForGoals(mod) {
fmt.Fprintf(&a.header, distString) fmt.Fprintf(&a.header, distString)
@@ -500,14 +501,14 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
// Collect make variable assignment entries. // Collect make variable assignment entries.
a.SetString("LOCAL_PATH", ctx.ModuleDir(mod)) a.SetString("LOCAL_PATH", ctx.ModuleDir(mod))
a.SetString("LOCAL_MODULE", name+a.SubName) a.SetString("LOCAL_MODULE", name+a.SubName)
a.AddStrings("LOCAL_LICENSE_KINDS", amod.commonProperties.Effective_license_kinds...) a.AddStrings("LOCAL_LICENSE_KINDS", base.commonProperties.Effective_license_kinds...)
a.AddStrings("LOCAL_LICENSE_CONDITIONS", amod.commonProperties.Effective_license_conditions...) a.AddStrings("LOCAL_LICENSE_CONDITIONS", base.commonProperties.Effective_license_conditions...)
a.AddStrings("LOCAL_NOTICE_FILE", amod.commonProperties.Effective_license_text.Strings()...) a.AddStrings("LOCAL_NOTICE_FILE", base.commonProperties.Effective_license_text.Strings()...)
// TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ? // TODO(b/151177513): Does this code need to set LOCAL_MODULE_IS_CONTAINER ?
if amod.commonProperties.Effective_package_name != nil { if base.commonProperties.Effective_package_name != nil {
a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *amod.commonProperties.Effective_package_name) a.SetString("LOCAL_LICENSE_PACKAGE_NAME", *base.commonProperties.Effective_package_name)
} else if len(amod.commonProperties.Effective_licenses) > 0 { } else if len(base.commonProperties.Effective_licenses) > 0 {
a.SetString("LOCAL_LICENSE_PACKAGE_NAME", strings.Join(amod.commonProperties.Effective_licenses, " ")) a.SetString("LOCAL_LICENSE_PACKAGE_NAME", strings.Join(base.commonProperties.Effective_licenses, " "))
} }
a.SetString("LOCAL_MODULE_CLASS", a.Class) a.SetString("LOCAL_MODULE_CLASS", a.Class)
a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String()) a.SetString("LOCAL_PREBUILT_MODULE_FILE", a.OutputFile.String())
@@ -519,27 +520,27 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform()) a.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform())
} }
archStr := amod.Arch().ArchType.String() archStr := base.Arch().ArchType.String()
host := false host := false
switch amod.Os().Class { switch base.Os().Class {
case Host: case Host:
if amod.Target().HostCross { if base.Target().HostCross {
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
if amod.Arch().ArchType != Common { if base.Arch().ArchType != Common {
a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr) a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr)
} }
} else { } else {
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
if amod.Arch().ArchType != Common { if base.Arch().ArchType != Common {
a.SetString("LOCAL_MODULE_HOST_ARCH", archStr) a.SetString("LOCAL_MODULE_HOST_ARCH", archStr)
} }
} }
host = true host = true
case Device: case Device:
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
if amod.Arch().ArchType != Common { if base.Arch().ArchType != Common {
if amod.Target().NativeBridge { if base.Target().NativeBridge {
hostArchStr := amod.Target().NativeBridgeHostArchName hostArchStr := base.Target().NativeBridgeHostArchName
if hostArchStr != "" { if hostArchStr != "" {
a.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr) a.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr)
} }
@@ -548,31 +549,31 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
} }
} }
if !amod.InRamdisk() && !amod.InVendorRamdisk() { if !base.InRamdisk() && !base.InVendorRamdisk() {
a.AddPaths("LOCAL_FULL_INIT_RC", amod.initRcPaths) a.AddPaths("LOCAL_FULL_INIT_RC", base.initRcPaths)
} }
if len(amod.vintfFragmentsPaths) > 0 { if len(base.vintfFragmentsPaths) > 0 {
a.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", amod.vintfFragmentsPaths) a.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", base.vintfFragmentsPaths)
} }
a.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(amod.commonProperties.Proprietary)) a.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(base.commonProperties.Proprietary))
if Bool(amod.commonProperties.Vendor) || Bool(amod.commonProperties.Soc_specific) { if Bool(base.commonProperties.Vendor) || Bool(base.commonProperties.Soc_specific) {
a.SetString("LOCAL_VENDOR_MODULE", "true") a.SetString("LOCAL_VENDOR_MODULE", "true")
} }
a.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(amod.commonProperties.Device_specific)) a.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(base.commonProperties.Device_specific))
a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(amod.commonProperties.Product_specific)) a.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(base.commonProperties.Product_specific))
a.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(amod.commonProperties.System_ext_specific)) a.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(base.commonProperties.System_ext_specific))
if amod.commonProperties.Owner != nil { if base.commonProperties.Owner != nil {
a.SetString("LOCAL_MODULE_OWNER", *amod.commonProperties.Owner) a.SetString("LOCAL_MODULE_OWNER", *base.commonProperties.Owner)
} }
} }
if len(amod.noticeFiles) > 0 { if len(base.noticeFiles) > 0 {
a.SetString("LOCAL_NOTICE_FILE", strings.Join(amod.noticeFiles.Strings(), " ")) a.SetString("LOCAL_NOTICE_FILE", strings.Join(base.noticeFiles.Strings(), " "))
} }
if host { if host {
makeOs := amod.Os().String() makeOs := base.Os().String()
if amod.Os() == Linux || amod.Os() == LinuxBionic || amod.Os() == LinuxMusl { if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl {
makeOs = "linux" makeOs = "linux"
} }
a.SetString("LOCAL_MODULE_HOST_OS", makeOs) a.SetString("LOCAL_MODULE_HOST_OS", makeOs)
@@ -580,10 +581,10 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
} }
prefix := "" prefix := ""
if amod.ArchSpecific() { if base.ArchSpecific() {
switch amod.Os().Class { switch base.Os().Class {
case Host: case Host:
if amod.Target().HostCross { if base.Target().HostCross {
prefix = "HOST_CROSS_" prefix = "HOST_CROSS_"
} else { } else {
prefix = "HOST_" prefix = "HOST_"
@@ -593,7 +594,7 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint
} }
if amod.Arch().ArchType != ctx.Config().Targets[amod.Os()][0].Arch.ArchType { if base.Arch().ArchType != ctx.Config().Targets[base.Os()][0].Arch.ArchType {
prefix = "2ND_" + prefix prefix = "2ND_" + prefix
} }
} }

View File

@@ -355,14 +355,14 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
config.bp2buildModuleTypeConfig = map[string]bool{} config.bp2buildModuleTypeConfig = map[string]bool{}
determineBuildOS(config)
return Config{config} return Config{config}
} }
func modifyTestConfigToSupportArchMutator(testConfig Config) { func modifyTestConfigToSupportArchMutator(testConfig Config) {
config := testConfig.config config := testConfig.config
determineBuildOS(config)
config.Targets = map[OsType][]Target{ config.Targets = map[OsType][]Target{
Android: []Target{ Android: []Target{
{Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false}, {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
@@ -568,15 +568,17 @@ func (c *config) HostToolDir() string {
} }
func (c *config) HostToolPath(ctx PathContext, tool string) Path { func (c *config) HostToolPath(ctx PathContext, tool string) Path {
return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool) path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false, tool)
return path
} }
func (c *config) HostJNIToolPath(ctx PathContext, path string) Path { func (c *config) HostJNIToolPath(ctx PathContext, lib string) Path {
ext := ".so" ext := ".so"
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
ext = ".dylib" ext = ".dylib"
} }
return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext) path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "lib64", false, lib+ext)
return path
} }
func (c *config) HostJavaToolPath(ctx PathContext, path string) Path { func (c *config) HostJavaToolPath(ctx PathContext, path string) Path {

View File

@@ -462,6 +462,13 @@ func (p OutputPaths) Strings() []string {
return ret return ret
} }
// PathForGoBinary returns the path to the installed location of a bootstrap_go_binary module.
func PathForGoBinary(ctx PathContext, goBinary bootstrap.GoBinaryTool) Path {
goBinaryInstallDir := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false)
rel := Rel(ctx, goBinaryInstallDir.String(), goBinary.InstallPath())
return goBinaryInstallDir.Join(ctx, rel)
}
// Expands Paths to a SourceFileProducer or OutputFileProducer module dependency referenced via ":name" or ":name{.tag}" syntax. // Expands Paths to a SourceFileProducer or OutputFileProducer module dependency referenced via ":name" or ":name{.tag}" syntax.
// If the dependency is not found, a missingErrorDependency is returned. // If the dependency is not found, a missingErrorDependency is returned.
// If the module dependency is not a SourceFileProducer or OutputFileProducer, appropriate errors will be returned. // If the module dependency is not a SourceFileProducer or OutputFileProducer, appropriate errors will be returned.
@@ -482,11 +489,8 @@ func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag
} else if tag != "" { } else if tag != "" {
return nil, fmt.Errorf("path dependency %q is not an output file producing module", path) return nil, fmt.Errorf("path dependency %q is not an output file producing module", path)
} else if goBinary, ok := module.(bootstrap.GoBinaryTool); ok { } else if goBinary, ok := module.(bootstrap.GoBinaryTool); ok {
if rel, err := filepath.Rel(PathForOutput(ctx).String(), goBinary.InstallPath()); err == nil { goBinaryPath := PathForGoBinary(ctx, goBinary)
return Paths{PathForOutput(ctx, rel).WithoutRel()}, nil return Paths{goBinaryPath}, nil
} else {
return nil, fmt.Errorf("cannot find output path for %q: %w", goBinary.InstallPath(), err)
}
} else if srcProducer, ok := module.(SourceFileProducer); ok { } else if srcProducer, ok := module.(SourceFileProducer); ok {
return srcProducer.Srcs(), nil return srcProducer.Srcs(), nil
} else { } else {
@@ -1571,6 +1575,8 @@ type InstallPath struct {
// For example, it is host/<os>-<arch> for host modules, and target/product/<device>/<partition> for device modules. // For example, it is host/<os>-<arch> for host modules, and target/product/<device>/<partition> for device modules.
partitionDir string partitionDir string
partition string
// makePath indicates whether this path is for Soong (false) or Make (true). // makePath indicates whether this path is for Soong (false) or Make (true).
makePath bool makePath bool
} }
@@ -1716,6 +1722,7 @@ func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string,
basePath: basePath{partionPath, ""}, basePath: basePath{partionPath, ""},
soongOutDir: ctx.Config().soongOutDir, soongOutDir: ctx.Config().soongOutDir,
partitionDir: partionPath, partitionDir: partionPath,
partition: partition,
makePath: false, makePath: false,
} }
@@ -1741,8 +1748,7 @@ func PathForMainlineSdksInstall(ctx PathContext, paths ...string) InstallPath {
} }
func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string { func InstallPathToOnDevicePath(ctx PathContext, path InstallPath) string {
rel := Rel(ctx, PathForOutput(ctx, "target", "product", ctx.Config().DeviceName()).String(), path.String()) rel := Rel(ctx, strings.TrimSuffix(path.PartitionDir(), path.partition), path.String())
return "/" + rel return "/" + rel
} }

View File

@@ -833,10 +833,11 @@ func (c *RuleBuilderCommand) PathForOutput(path WritablePath) string {
func sboxPathForToolRel(ctx BuilderContext, path Path) string { func sboxPathForToolRel(ctx BuilderContext, path Path) string {
// Errors will be handled in RuleBuilder.Build where we have a context to report them // Errors will be handled in RuleBuilder.Build where we have a context to report them
relOut, isRelOut, _ := maybeRelErr(PathForOutput(ctx, "host", ctx.Config().PrebuiltOS()).String(), path.String()) toolDir := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "", false)
if isRelOut { relOutSoong, isRelOutSoong, _ := maybeRelErr(toolDir.String(), path.String())
// The tool is in the output directory, it will be copied to __SBOX_OUT_DIR__/tools/out if isRelOutSoong {
return filepath.Join(sboxToolsSubDir, "out", relOut) // The tool is in the Soong output directory, it will be copied to __SBOX_OUT_DIR__/tools/out
return filepath.Join(sboxToolsSubDir, "out", relOutSoong)
} }
// The tool is in the source directory, it will be copied to __SBOX_OUT_DIR__/tools/src // The tool is in the source directory, it will be copied to __SBOX_OUT_DIR__/tools/src
return filepath.Join(sboxToolsSubDir, "src", path.String()) return filepath.Join(sboxToolsSubDir, "src", path.String())

View File

@@ -1458,12 +1458,7 @@ func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexF
func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile { func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile {
dirInApex := "bin" dirInApex := "bin"
s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) fileToCopy := android.PathForGoBinary(ctx, gb)
if err != nil {
ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath())
return apexFile{}
}
fileToCopy := android.PathForOutput(ctx, s)
// NB: Since go binaries are static we don't need the module for anything here, which is // NB: Since go binaries are static we don't need the module for anything here, which is
// good since the go tool is a blueprint.Module not an android.Module like we would // good since the go tool is a blueprint.Module not an android.Module like we would
// normally use. // normally use.

View File

@@ -524,7 +524,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) {
} }
unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned") unsignedOutputFile := android.PathForModuleOut(ctx, a.Name()+suffix+".unsigned")
outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() outHostBinDir := ctx.Config().HostToolPath(ctx, "").String()
prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
// Figure out if need to compress apex. // Figure out if need to compress apex.

View File

@@ -336,14 +336,9 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} }
case bootstrap.GoBinaryTool: case bootstrap.GoBinaryTool:
// A GoBinaryTool provides the install path to a tool, which will be copied. // A GoBinaryTool provides the install path to a tool, which will be copied.
if s, err := filepath.Rel(android.PathForOutput(ctx).String(), t.InstallPath()); err == nil { p := android.PathForGoBinary(ctx, t)
toolPath := android.PathForOutput(ctx, s) tools = append(tools, p)
tools = append(tools, toolPath) addLocationLabel(tag.label, toolLocation{android.Paths{p}})
addLocationLabel(tag.label, toolLocation{android.Paths{toolPath}})
} else {
ctx.ModuleErrorf("cannot find path for %q: %v", tool, err)
return
}
default: default:
ctx.ModuleErrorf("%q is not a host tool provider", tool) ctx.ModuleErrorf("%q is not a host tool provider", tool)
return return