Add DeviceConfig and OncePer objects

Add DeviceConfig to store per-device configuration information.  Put a
OncePer object inside Config and DeviceConfig, which computes a value
once per key per object to allow build logic to store arbitrary
per-build or per-device computed values.

Change-Id: I1a38b426f29d223ef5e803e0d4d9604500de2fd2
This commit is contained in:
Colin Cross
2016-08-17 15:24:12 -07:00
parent 389d2bb145
commit 9272ade7a8
5 changed files with 123 additions and 12 deletions

View File

@@ -43,11 +43,18 @@ func (f *FileConfigurableOptions) SetDefaultConfig() {
*f = FileConfigurableOptions{}
}
// A Config object represents the entire build configuration for Android.
type Config struct {
*config
}
// A config object represents the entire build configuration for Android.
// A DeviceConfig object represents the configuration for a particular device being built. For
// now there will only be one of these, but in the future there may be multiple devices being
// built
type DeviceConfig struct {
*deviceConfig
}
type config struct {
FileConfigurableOptions
ProductVariables productVariables
@@ -58,6 +65,8 @@ type config struct {
Targets map[OsClass][]Target
BuildOsVariant string
deviceConfig *deviceConfig
srcDir string // the path of the root source directory
buildDir string // the path of the build output directory
@@ -66,6 +75,13 @@ type config struct {
envFrozen bool
inMake bool
OncePer
}
type deviceConfig struct {
config *config
targets []Arch
OncePer
}
type jsonConfigurable interface {
@@ -138,17 +154,23 @@ func saveToConfigFile(config jsonConfigurable, filename string) error {
// the root source directory. It also loads the config file, if found.
func NewConfig(srcDir, buildDir string) (Config, error) {
// Make a config with default options
config := Config{
config: &config{
ConfigFileName: filepath.Join(buildDir, configFileName),
ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
config := &config{
ConfigFileName: filepath.Join(buildDir, configFileName),
ProductVariablesFileName: filepath.Join(buildDir, productVariablesFileName),
srcDir: srcDir,
buildDir: buildDir,
envDeps: make(map[string]string),
},
srcDir: srcDir,
buildDir: buildDir,
envDeps: make(map[string]string),
deviceConfig: &deviceConfig{},
}
deviceConfig := &deviceConfig{
config: config,
}
config.deviceConfig = deviceConfig
// Sanity check the build and source directories. This won't catch strange
// configurations with symlinks, but at least checks the obvious cases.
absBuildDir, err := filepath.Abs(buildDir)
@@ -166,7 +188,7 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
}
// Load any configurable options from the configuration file
err = loadConfig(config.config)
err = loadConfig(config)
if err != nil {
return Config{}, err
}
@@ -192,7 +214,7 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
config.Targets = targets
config.BuildOsVariant = targets[Host][0].String()
return config, nil
return Config{config}, nil
}
func (c *config) RemoveAbandonedFiles() bool {
@@ -337,3 +359,11 @@ func (c *config) Android64() bool {
return false
}
func (c *deviceConfig) Arches() []Arch {
var arches []Arch
for _, target := range c.config.Targets[Device] {
arches = append(arches, target.Arch)
}
return arches
}