Move config into common and provide helper

Using ctx.Config().(Config) everywhere is a mouthful, and it is
inefficient to do the type assertion.  Put the Config interface into
the context, and provide an AConfig() to return the Config already
converted to the right type.

Change-Id: I301a1fd7d2a005580aabca7866a37c5d42ad8c69
This commit is contained in:
Colin Cross 2015-04-07 17:11:30 -07:00
parent 8df14ac3f0
commit 1332b0035c
11 changed files with 86 additions and 143 deletions

View File

@ -18,7 +18,6 @@ bootstrap_go_binary {
"soong-art",
"soong-cc",
"soong-common",
"soong-config",
"soong-env",
"soong-genrule",
"soong-java",
@ -81,6 +80,7 @@ bootstrap_go_package {
srcs: [
"common/arch.go",
"common/checkbuild.go",
"common/config.go",
"common/defs.go",
"common/env.go",
"common/glob.go",
@ -89,19 +89,6 @@ bootstrap_go_package {
],
}
bootstrap_go_package {
name: "soong-config",
pkgPath: "android/soong/config",
deps: [
"blueprint",
"blueprint-bootstrap",
"soong-common",
],
srcs: [
"config/config.go",
],
}
bootstrap_go_package {
name: "soong-cc",
pkgPath: "android/soong/cc",
@ -109,7 +96,6 @@ bootstrap_go_package {
"blueprint",
"blueprint-pathtools",
"soong-common",
"soong-config",
"soong-genrule",
],
srcs: [
@ -134,7 +120,6 @@ bootstrap_go_package {
"blueprint",
"blueprint-pathtools",
"soong-common",
"soong-config",
],
srcs: [
"genrule/genrule.go",
@ -155,7 +140,6 @@ bootstrap_go_package {
"blueprint",
"blueprint-pathtools",
"soong-common",
"soong-config",
],
srcs: [
"java/builder.go",

View File

@ -53,7 +53,7 @@ rule g.bootstrap.link
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Blueprints:171:1
# Defined: build/soong/Blueprints:155:1
build .bootstrap/androidmk/obj/androidmk.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/android.go $
@ -79,7 +79,7 @@ default .bootstrap/bin/androidmk
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:184:1
# Defined: build/soong/Blueprints:168:1
build .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a: $
g.bootstrap.gc $
@ -298,10 +298,9 @@ build .bootstrap/soong-art/pkg/android/soong/art.a: g.bootstrap.gc $
.bootstrap/soong-env/pkg/android/soong/env.a $
.bootstrap/soong-glob/pkg/android/soong/glob.a $
.bootstrap/soong-common/pkg/android/soong/common.a $
.bootstrap/soong-config/pkg/android/soong/config.a $
.bootstrap/soong-genrule/pkg/android/soong/genrule.a $
.bootstrap/soong-cc/pkg/android/soong/cc.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-config/pkg -I .bootstrap/soong-genrule/pkg -I .bootstrap/soong-cc/pkg
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg -I .bootstrap/soong-cc/pkg
pkgPath = android/soong/art
default .bootstrap/soong-art/pkg/android/soong/art.a
@ -310,7 +309,7 @@ default .bootstrap/soong-art/pkg/android/soong/art.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:105:1
# Defined: build/soong/Blueprints:92:1
build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cc/builder.go $
@ -332,9 +331,8 @@ build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
.bootstrap/soong-env/pkg/android/soong/env.a $
.bootstrap/soong-glob/pkg/android/soong/glob.a $
.bootstrap/soong-common/pkg/android/soong/common.a $
.bootstrap/soong-config/pkg/android/soong/config.a $
.bootstrap/soong-genrule/pkg/android/soong/genrule.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-config/pkg -I .bootstrap/soong-genrule/pkg
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg
pkgPath = android/soong/cc
default .bootstrap/soong-cc/pkg/android/soong/cc.a
@ -343,11 +341,12 @@ default .bootstrap/soong-cc/pkg/android/soong/cc.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:72:1
# Defined: build/soong/Blueprints:71:1
build .bootstrap/soong-common/pkg/android/soong/common.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/common/arch.go $
${g.bootstrap.srcDir}/build/soong/common/checkbuild.go $
${g.bootstrap.srcDir}/build/soong/common/config.go $
${g.bootstrap.srcDir}/build/soong/common/defs.go $
${g.bootstrap.srcDir}/build/soong/common/env.go $
${g.bootstrap.srcDir}/build/soong/common/glob.go $
@ -366,35 +365,12 @@ build .bootstrap/soong-common/pkg/android/soong/common.a: g.bootstrap.gc $
pkgPath = android/soong/common
default .bootstrap/soong-common/pkg/android/soong/common.a
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: soong-config
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:92:1
build .bootstrap/soong-config/pkg/android/soong/config.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/config/config.go | $
${g.bootstrap.gcCmd} $
.bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
.bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
.bootstrap/blueprint/pkg/github.com/google/blueprint.a $
.bootstrap/blueprint-deptools/pkg/github.com/google/blueprint/deptools.a $
.bootstrap/blueprint-pathtools/pkg/github.com/google/blueprint/pathtools.a $
.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
.bootstrap/soong-env/pkg/android/soong/env.a $
.bootstrap/soong-glob/pkg/android/soong/glob.a $
.bootstrap/soong-common/pkg/android/soong/common.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg
pkgPath = android/soong/config
default .bootstrap/soong-config/pkg/android/soong/config.a
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Module: soong-env
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:42:1
# Defined: build/soong/Blueprints:41:1
build .bootstrap/soong-env/pkg/android/soong/env.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/env/env.go | ${g.bootstrap.gcCmd}
@ -406,7 +382,7 @@ default .bootstrap/soong-env/pkg/android/soong/env.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:130:1
# Defined: build/soong/Blueprints:116:1
build .bootstrap/soong-genrule/pkg/android/soong/genrule.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/genrule/genrule.go | $
@ -419,9 +395,8 @@ build .bootstrap/soong-genrule/pkg/android/soong/genrule.a: g.bootstrap.gc $
.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
.bootstrap/soong-env/pkg/android/soong/env.a $
.bootstrap/soong-glob/pkg/android/soong/glob.a $
.bootstrap/soong-common/pkg/android/soong/common.a $
.bootstrap/soong-config/pkg/android/soong/config.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-config/pkg
.bootstrap/soong-common/pkg/android/soong/common.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg
pkgPath = android/soong/genrule
default .bootstrap/soong-genrule/pkg/android/soong/genrule.a
@ -430,7 +405,7 @@ default .bootstrap/soong-genrule/pkg/android/soong/genrule.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:61:1
# Defined: build/soong/Blueprints:60:1
build .bootstrap/soong-glob/pkg/android/soong/glob.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/glob/glob.go | ${g.bootstrap.gcCmd} $
@ -444,7 +419,7 @@ default .bootstrap/soong-glob/pkg/android/soong/glob.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:151:1
# Defined: build/soong/Blueprints:136:1
build .bootstrap/soong-java/pkg/android/soong/java.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/java/builder.go $
@ -459,9 +434,8 @@ build .bootstrap/soong-java/pkg/android/soong/java.a: g.bootstrap.gc $
.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
.bootstrap/soong-env/pkg/android/soong/env.a $
.bootstrap/soong-glob/pkg/android/soong/glob.a $
.bootstrap/soong-common/pkg/android/soong/common.a $
.bootstrap/soong-config/pkg/android/soong/config.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-config/pkg
.bootstrap/soong-common/pkg/android/soong/common.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg
pkgPath = android/soong/java
default .bootstrap/soong-java/pkg/android/soong/java.a
@ -484,18 +458,17 @@ build .bootstrap/soong_build/obj/soong_build.a: g.bootstrap.gc $
.bootstrap/soong-env/pkg/android/soong/env.a $
.bootstrap/soong-glob/pkg/android/soong/glob.a $
.bootstrap/soong-common/pkg/android/soong/common.a $
.bootstrap/soong-config/pkg/android/soong/config.a $
.bootstrap/soong-genrule/pkg/android/soong/genrule.a $
.bootstrap/soong-cc/pkg/android/soong/cc.a $
.bootstrap/soong-art/pkg/android/soong/art.a $
.bootstrap/soong-java/pkg/android/soong/java.a
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-config/pkg -I .bootstrap/soong-genrule/pkg -I .bootstrap/soong-cc/pkg -I .bootstrap/soong-art/pkg -I .bootstrap/soong-java/pkg
incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint-proptools/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-deptools/pkg -I .bootstrap/blueprint-pathtools/pkg -I .bootstrap/blueprint-bootstrap/pkg -I .bootstrap/soong-env/pkg -I .bootstrap/soong-glob/pkg -I .bootstrap/soong-common/pkg -I .bootstrap/soong-genrule/pkg -I .bootstrap/soong-cc/pkg -I .bootstrap/soong-art/pkg -I .bootstrap/soong-java/pkg
pkgPath = soong_build
default .bootstrap/soong_build/obj/soong_build.a
build .bootstrap/soong_build/obj/a.out: g.bootstrap.link $
.bootstrap/soong_build/obj/soong_build.a | ${g.bootstrap.linkCmd}
libDirFlags = -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-bootstrap/pkg -L .bootstrap/soong-env/pkg -L .bootstrap/soong-glob/pkg -L .bootstrap/soong-common/pkg -L .bootstrap/soong-config/pkg -L .bootstrap/soong-genrule/pkg -L .bootstrap/soong-cc/pkg -L .bootstrap/soong-art/pkg -L .bootstrap/soong-java/pkg
libDirFlags = -L .bootstrap/blueprint-parser/pkg -L .bootstrap/blueprint-proptools/pkg -L .bootstrap/blueprint/pkg -L .bootstrap/blueprint-deptools/pkg -L .bootstrap/blueprint-pathtools/pkg -L .bootstrap/blueprint-bootstrap/pkg -L .bootstrap/soong-env/pkg -L .bootstrap/soong-glob/pkg -L .bootstrap/soong-common/pkg -L .bootstrap/soong-genrule/pkg -L .bootstrap/soong-cc/pkg -L .bootstrap/soong-art/pkg -L .bootstrap/soong-java/pkg
default .bootstrap/soong_build/obj/a.out
build .bootstrap/bin/soong_build: g.bootstrap.cp $
@ -507,7 +480,7 @@ default .bootstrap/bin/soong_build
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Blueprints:32:1
# Defined: build/soong/Blueprints:31:1
build .bootstrap/soong_env/obj/soong_env.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cmd/soong_env/soong_env.go | $
@ -529,7 +502,7 @@ default .bootstrap/bin/soong_env
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Blueprints:51:1
# Defined: build/soong/Blueprints:50:1
build .bootstrap/soong_glob/obj/soong_glob.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cmd/soong_glob/soong_glob.go | $
@ -554,7 +527,7 @@ default .bootstrap/bin/soong_glob
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Blueprints:144:1
# Defined: build/soong/Blueprints:129:1
build .bootstrap/soong_jar/obj/soong_jar.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cmd/soong_jar/soong_jar.go | $

View File

@ -109,8 +109,8 @@ type builderFlags struct {
func TransformSourceToObj(ctx common.AndroidModuleContext, subdir string, srcFiles []string,
flags builderFlags, deps []string) (objFiles []string) {
srcRoot := ctx.Config().(Config).SrcDir()
intermediatesRoot := ctx.Config().(Config).IntermediatesDir()
srcRoot := ctx.AConfig().SrcDir()
intermediatesRoot := ctx.AConfig().IntermediatesDir()
objFiles = make([]string, len(srcFiles))
objDir := common.ModuleObjDir(ctx)

View File

@ -30,15 +30,9 @@ import (
"android/soong/genrule"
)
type Config interface {
SrcDir() string
IntermediatesDir() string
PrebuiltOS() string
}
var (
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", Config.PrebuiltOS)
SrcDir = pctx.VariableConfigMethod("SrcDir", Config.SrcDir)
HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", common.Config.PrebuiltOS)
SrcDir = pctx.VariableConfigMethod("SrcDir", common.Config.SrcDir)
LibcRoot = pctx.StaticVariable("LibcRoot", "${SrcDir}/bionic/libc")
LibmRoot = pctx.StaticVariable("LibmRoot", "${SrcDir}/bionic/libm")
@ -443,7 +437,7 @@ func (c *ccBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolcha
}
}
flags.IncludeDirs = pathtools.PrefixPaths(c.properties.Include_dirs, ctx.Config().(Config).SrcDir())
flags.IncludeDirs = pathtools.PrefixPaths(c.properties.Include_dirs, ctx.AConfig().SrcDir())
localIncludeDirs := pathtools.PrefixPaths(c.properties.Local_include_dirs, common.ModuleSrcDir(ctx))
flags.IncludeDirs = append(flags.IncludeDirs, localIncludeDirs...)
@ -769,7 +763,7 @@ func (c *ccLinked) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags
flags.IncludeDirs = append(flags.IncludeDirs, "${SrcDir}/bionic/libstdc++/include")
}
case "ndk_system":
ndkSrcRoot := ctx.Config().(Config).SrcDir() + "/prebuilts/ndk/current/sources/"
ndkSrcRoot := ctx.AConfig().SrcDir() + "/prebuilts/ndk/current/sources/"
flags.IncludeDirs = append(flags.IncludeDirs, ndkSrcRoot+"cxx-stl/system/include")
case "ndk_libc++_shared", "ndk_libc++_static":
// TODO(danalbert): This really shouldn't be here...
@ -1311,7 +1305,7 @@ func (c *ccTest) Flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags {
// TODO(danalbert): Make gtest export its dependencies.
flags.IncludeDirs = append(flags.IncludeDirs,
filepath.Join(ctx.Config().(Config).SrcDir(), "external/gtest/include"))
filepath.Join(ctx.AConfig().SrcDir(), "external/gtest/include"))
return flags
}
@ -1468,7 +1462,7 @@ func (c *toolchainLibrary) installModule(ctx common.AndroidModuleContext, flags
func getNdkLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, version string) string {
return fmt.Sprintf("%s/prebuilts/ndk/current/platforms/android-%s/arch-%s/usr/lib",
ctx.Config().(Config).SrcDir(), version, toolchain.Name())
ctx.AConfig().SrcDir(), version, toolchain.Name())
}
type ndkPrebuiltLibrary struct {
@ -1555,7 +1549,7 @@ func getNdkStlLibDir(ctx common.AndroidModuleContext, toolchain Toolchain, stl s
}
if libDir != "" {
ndkSrcRoot := ctx.Config().(Config).SrcDir() + "/prebuilts/ndk/current/sources"
ndkSrcRoot := ctx.AConfig().SrcDir() + "/prebuilts/ndk/current/sources"
return fmt.Sprintf("%s/%s/%s", ndkSrcRoot, libDir, ctx.Arch().Abi)
}

View File

@ -26,7 +26,6 @@ import (
"android/soong/art"
"android/soong/cc"
"android/soong/common"
"android/soong/config"
"android/soong/genrule"
"android/soong/java"
)
@ -78,7 +77,7 @@ func main() {
ctx.RegisterSingletonType("checkbuild", common.CheckbuildSingleton)
ctx.RegisterSingletonType("env", common.EnvSingleton)
configuration, err := config.New(srcDir)
configuration, err := common.NewConfig(srcDir)
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
@ -87,5 +86,5 @@ func main() {
// Temporary hack
//ctx.SetIgnoreUnknownModuleTypes(true)
bootstrap.Main(ctx, configuration, config.ConfigFileName)
bootstrap.Main(ctx, configuration, common.ConfigFileName)
}

View File

@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package config
package common
import (
"android/soong/common"
"encoding/json"
"fmt"
"os"
@ -23,7 +22,18 @@ import (
"runtime"
)
var _ common.Config = (*Config)(nil)
type Config interface {
CpPreserveSymlinksFlags() string
SrcDir() string
IntermediatesDir() string
Getenv(string) string
EnvDeps() map[string]string
DeviceOut() string
HostOut() string
PrebuiltOS() string
HostBinTool(string) (string, error)
HostJavaTool(string) (string, error)
}
// The configuration file name
const ConfigFileName = "soong.config"
@ -39,7 +49,7 @@ func NewFileConfigurableOptions() FileConfigurableOptions {
}
// A Config object represents the entire build configuration for Blue.
type Config struct {
type config struct {
FileConfigurableOptions
srcDir string // the path of the root source directory
@ -47,7 +57,7 @@ type Config struct {
}
// loads configuration options from a JSON file in the cwd.
func loadFromConfigFile(config *Config) error {
func loadFromConfigFile(config *config) error {
// Make a proxy config
var configProxy FileConfigurableOptions
@ -103,9 +113,9 @@ func saveToConfigFile(config FileConfigurableOptions) error {
// New creates a new Config object. The srcDir argument specifies the path to
// the root source directory. It also loads the config file, if found.
func New(srcDir string) (*Config, error) {
func NewConfig(srcDir string) (Config, error) {
// Make a config with default options
config := &Config{
config := &config{
srcDir: srcDir,
envDeps: make(map[string]string),
}
@ -119,21 +129,21 @@ func New(srcDir string) (*Config, error) {
return config, nil
}
func (c *Config) SrcDir() string {
func (c *config) SrcDir() string {
return c.srcDir
}
func (c *Config) IntermediatesDir() string {
func (c *config) IntermediatesDir() string {
return ".intermediates"
}
// HostGoOS returns the OS of the system that the Go toolchain is being run on.
func (c *Config) HostGoOS() string {
func (c *config) HostGoOS() string {
return runtime.GOOS
}
// PrebuiltOS returns the name of the host OS used in prebuilts directories
func (c *Config) PrebuiltOS() string {
func (c *config) PrebuiltOS() string {
switch runtime.GOOS {
case "linux":
return "linux-x86"
@ -145,11 +155,11 @@ func (c *Config) PrebuiltOS() string {
}
// GoRoot returns the path to the root directory of the Go toolchain.
func (c *Config) GoRoot() string {
func (c *config) GoRoot() string {
return fmt.Sprintf("%s/prebuilts/go/%s", c.srcDir, c.PrebuiltOS())
}
func (c *Config) CpPreserveSymlinksFlags() string {
func (c *config) CpPreserveSymlinksFlags() string {
switch c.HostGoOS() {
case "darwin":
return "-R"
@ -160,7 +170,7 @@ func (c *Config) CpPreserveSymlinksFlags() string {
}
}
func (c *Config) Getenv(key string) string {
func (c *config) Getenv(key string) string {
var val string
var exists bool
if val, exists = c.envDeps[key]; !exists {
@ -170,42 +180,42 @@ func (c *Config) Getenv(key string) string {
return val
}
func (c *Config) EnvDeps() map[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 {
func (c *config) DeviceName() string {
return "unset"
}
// DeviceOut returns the path to out directory for device targets
func (c *Config) DeviceOut() string {
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 {
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 {
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) {
func (c *config) HostBinTool(tool string) (string, error) {
return filepath.Join(c.HostBin(), tool), nil
}
// HostJavaDir returns the path to framework directory for host targets
func (c *Config) HostJavaDir() string {
func (c *config) HostJavaDir() string {
return filepath.Join(c.HostOut(), "framework")
}
// HostJavaTool returns the path to a host tool in the frameworks directory for host targets
func (c *Config) HostJavaTool(tool string) (string, error) {
func (c *config) HostJavaTool(tool string) (string, error) {
return filepath.Join(c.HostJavaDir(), tool), nil
}

View File

@ -20,16 +20,6 @@ import (
"github.com/google/blueprint"
)
type Config interface {
CpPreserveSymlinksFlags() string
SrcDir() string
IntermediatesDir() string
Getenv(string) string
EnvDeps() map[string]string
DeviceOut() string
HostOut() string
}
var (
DeviceSharedLibrary = "shared_library"
DeviceStaticLibrary = "static_library"
@ -44,6 +34,7 @@ type androidBaseContext interface {
Host() bool
Device() bool
Debug() bool
AConfig() Config
}
type AndroidBaseContext interface {
@ -300,6 +291,7 @@ func (a *AndroidModuleBase) DynamicDependencies(ctx blueprint.DynamicDependerMod
DynamicDependerModuleContext: ctx,
androidBaseContextImpl: androidBaseContextImpl{
arch: a.commonProperties.CompileArch,
config: ctx.Config().(Config),
},
}
@ -315,6 +307,7 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
ModuleContext: ctx,
androidBaseContextImpl: androidBaseContextImpl{
arch: a.commonProperties.CompileArch,
config: ctx.Config().(Config),
},
installDeps: a.computeInstallDeps(ctx),
installFiles: a.installFiles,
@ -342,6 +335,7 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
type androidBaseContextImpl struct {
arch Arch
debug bool
config Config
}
type androidModuleContext struct {
@ -382,10 +376,14 @@ func (a *androidBaseContextImpl) Debug() bool {
return a.debug
}
func (a *androidBaseContextImpl) AConfig() Config {
return a.config
}
func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string,
deps ...string) string {
config := a.Config().(Config)
config := a.AConfig()
var fullInstallPath string
if a.arch.HostOrDevice.Device() {
// TODO: replace unset with a device name once we have device targeting

View File

@ -16,21 +16,18 @@ package common
import (
"path/filepath"
"github.com/google/blueprint"
)
// ModuleOutDir returns the path to the module-specific output directory.
func ModuleOutDir(ctx AndroidModuleContext) string {
config := ctx.Config().(Config)
return filepath.Join(config.IntermediatesDir(), ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
return filepath.Join(ctx.AConfig().IntermediatesDir(),
ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
}
// ModuleSrcDir returns the path of the directory that all source file paths are
// specified relative to.
func ModuleSrcDir(ctx blueprint.ModuleContext) string {
config := ctx.Config().(Config)
return filepath.Join(config.SrcDir(), ctx.ModuleDir())
func ModuleSrcDir(ctx AndroidModuleContext) string {
return filepath.Join(ctx.AConfig().SrcDir(), ctx.ModuleDir())
}
// ModuleBinDir returns the path to the module- and architecture-specific binary

View File

@ -23,16 +23,12 @@ import (
"android/soong/common"
)
type Config interface {
SrcDir() string
}
var (
pctx = blueprint.NewPackageContext("android/soong/genrule")
)
func init() {
pctx.VariableConfigMethod("srcDir", Config.SrcDir)
pctx.VariableConfigMethod("srcDir", common.Config.SrcDir)
}
type SourceFileGenerator interface {

View File

@ -85,10 +85,10 @@ func init() {
pctx.StaticVariable("javacCmd", "javac -J-Xmx1024M $commonJdkFlags")
pctx.StaticVariable("jarCmd", filepath.Join(bootstrap.BinDir, "soong_jar"))
pctx.VariableFunc("dxCmd", func(c interface{}) (string, error) {
return c.(Config).HostBinTool("dx")
return c.(common.Config).HostBinTool("dx")
})
pctx.VariableFunc("jarjarCmd", func(c interface{}) (string, error) {
return c.(Config).HostJavaTool("jarjar.jar")
return c.(common.Config).HostJavaTool("jarjar.jar")
})
}

View File

@ -29,14 +29,6 @@ import (
"android/soong/common"
)
type Config interface {
SrcDir() string
PrebuiltOS() string
HostBinTool(string) (string, error)
HostJavaTool(string) (string, error)
Getenv(string) string
}
// TODO:
// Autogenerated files:
// AIDL
@ -266,11 +258,11 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
dxFlags = append(dxFlags, "--no-locals")
}
if ctx.Config().(Config).Getenv("NO_OPTIMIZE_DX") != "" {
if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
dxFlags = append(dxFlags, "--no-optimize")
}
if ctx.Config().(Config).Getenv("GENERATE_DEX_DEBUG") != "" {
if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
dxFlags = append(dxFlags,
"--debug",
"--verbose",