Clean up installing

Use the config to get paths to install to, allow installing
a file to a different file name than the intermediate file,
and allow dependencies between installed files.

Change-Id: I37ac32d2fa1458150b6d54f6ec9cdac70a0259e8
This commit is contained in:
Colin Cross
2015-04-02 14:37:16 -07:00
parent 3e8ec07787
commit 35cec12a11
2 changed files with 46 additions and 7 deletions

View File

@@ -25,6 +25,8 @@ type Config interface {
SrcDir() string SrcDir() string
Getenv(string) string Getenv(string) string
EnvDeps() map[string]string EnvDeps() map[string]string
DeviceOut() string
HostOut() string
} }
var ( var (
@@ -52,7 +54,8 @@ type AndroidModuleContext interface {
blueprint.ModuleContext blueprint.ModuleContext
androidBaseContext androidBaseContext
InstallFile(installPath, srcPath string) InstallFile(installPath, srcPath string, deps ...string) string
InstallFileName(installPath, name, srcPath string, deps ...string) string
CheckbuildFile(srcPath string) CheckbuildFile(srcPath string)
} }
@@ -377,25 +380,34 @@ func (a *androidBaseContextImpl) Debug() bool {
return a.debug return a.debug
} }
func (a *androidModuleContext) InstallFile(installPath, srcPath string) { func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string,
deps ...string) string {
config := a.Config().(Config)
var fullInstallPath string var fullInstallPath string
if a.arch.HostOrDevice.Device() { if a.arch.HostOrDevice.Device() {
// TODO: replace unset with a device name once we have device targeting // TODO: replace unset with a device name once we have device targeting
fullInstallPath = filepath.Join("out/target/product/unset/system", installPath, fullInstallPath = filepath.Join(config.DeviceOut(), "system",
filepath.Base(srcPath)) installPath, name)
} else { } else {
// TODO: replace unset with a host name fullInstallPath = filepath.Join(config.HostOut(), installPath, name)
fullInstallPath = filepath.Join("out/host/unset/", installPath, filepath.Base(srcPath))
} }
deps = append(deps, a.installDeps...)
a.ModuleContext.Build(pctx, blueprint.BuildParams{ a.ModuleContext.Build(pctx, blueprint.BuildParams{
Rule: Cp, Rule: Cp,
Outputs: []string{fullInstallPath}, Outputs: []string{fullInstallPath},
Inputs: []string{srcPath}, Inputs: []string{srcPath},
OrderOnly: a.installDeps, OrderOnly: deps,
}) })
a.installFiles = append(a.installFiles, fullInstallPath) a.installFiles = append(a.installFiles, fullInstallPath)
return fullInstallPath
}
func (a *androidModuleContext) InstallFile(installPath, srcPath string, deps ...string) string {
return a.InstallFileName(installPath, filepath.Base(srcPath), srcPath, deps...)
} }
func (a *androidModuleContext) CheckbuildFile(srcPath string) { func (a *androidModuleContext) CheckbuildFile(srcPath string) {

View File

@@ -19,6 +19,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath"
"runtime" "runtime"
) )
@@ -168,3 +169,29 @@ func (c *Config) Getenv(key string) string {
func (c *Config) EnvDeps() map[string]string { func (c *Config) EnvDeps() map[string]string {
return c.envDeps return c.envDeps
} }
// DeviceName returns the name of the current device target
// TODO: take an AndroidModuleContext to select the device name for multi-device builds
func (c *Config) DeviceName() string {
return "unset"
}
// DeviceOut returns the path to out directory for device targets
func (c *Config) DeviceOut() string {
return filepath.Join("target/product", c.DeviceName())
}
// HostOut returns the path to out directory for host targets
func (c *Config) HostOut() string {
return filepath.Join("host", c.PrebuiltOS())
}
// HostBin returns the path to bin directory for host targets
func (c *Config) HostBin() string {
return filepath.Join(c.HostOut(), "bin")
}
// HostBinTool returns the path to a host tool in the bin directory for host targets
func (c *Config) HostBinTool(tool string) (string, error) {
return filepath.Join(c.HostBin(), tool), nil
}