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

View File

@@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
)
@@ -168,3 +169,29 @@ func (c *Config) Getenv(key string) string {
func (c *Config) EnvDeps() map[string]string {
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
}