diff --git a/common/module.go b/common/module.go index ab90adecb..a83438450 100644 --- a/common/module.go +++ b/common/module.go @@ -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) { diff --git a/config/config.go b/config/config.go index 6cb61e4be..4e9cbf1d4 100644 --- a/config/config.go +++ b/config/config.go @@ -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 +}