Wrap PackageContext and SingletonContext
Wrap blueprint.PackageContext so that the *Func methods can provide
an android.Config instead of an interface{}. The modified signatures
means that every method in ModuleContext and SingletonContext
that takes a blueprint.PackageContext now needs to be wrapped to
take an android.PackageContext.
SingletonContext wasn't previously wrapped at all, but as long
as it is, wrap everything like ModuleContext does. This requires
updating every Singleton to use the android-specific methods.
Test: builds, all Soong tests pass
Change-Id: I4f22085ebca7def6c5cde49e8210b59d994ba625
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 065d0aa..44e977f 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -318,7 +318,7 @@
ret.Class = "SHARED_LIBRARIES"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
- path, file := filepath.Split(c.installPath)
+ path, file := filepath.Split(c.installPath.String())
stem := strings.TrimSuffix(file, filepath.Ext(file))
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
diff --git a/cc/cmakelists.go b/cc/cmakelists.go
index 13a2e8e..9b32182 100644
--- a/cc/cmakelists.go
+++ b/cc/cmakelists.go
@@ -23,8 +23,6 @@
"path"
"path/filepath"
"strings"
-
- "github.com/google/blueprint"
)
// This singleton generates CMakeLists.txt files. It does so for each blueprint Android.bp resulting in a cc.Module
@@ -35,7 +33,7 @@
android.RegisterSingletonType("cmakelists_generator", cMakeListsGeneratorSingleton)
}
-func cMakeListsGeneratorSingleton() blueprint.Singleton {
+func cMakeListsGeneratorSingleton() android.Singleton {
return &cmakelistsGeneratorSingleton{}
}
@@ -57,14 +55,14 @@
// This is done to ease investigating bug reports.
var outputDebugInfo = false
-func (c *cmakelistsGeneratorSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
+func (c *cmakelistsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonContext) {
if getEnvVariable(envVariableGenerateCMakeLists, ctx) != envVariableTrue {
return
}
outputDebugInfo = (getEnvVariable(envVariableGenerateDebugInfo, ctx) == envVariableTrue)
- ctx.VisitAllModules(func(module blueprint.Module) {
+ ctx.VisitAllModules(func(module android.Module) {
if ccModule, ok := module.(*Module); ok {
if compiledModule, ok := ccModule.compiler.(CompiledInterface); ok {
generateCLionProject(compiledModule, ctx, ccModule)
@@ -81,7 +79,7 @@
return
}
-func getEnvVariable(name string, ctx blueprint.SingletonContext) string {
+func getEnvVariable(name string, ctx android.SingletonContext) string {
// Using android.Config.Getenv instead of os.getEnv to guarantee soong will
// re-run in case this environment variable changes.
return ctx.Config().(android.Config).Getenv(name)
@@ -116,7 +114,7 @@
return nil
}
-func generateCLionProject(compiledModule CompiledInterface, ctx blueprint.SingletonContext, ccModule *Module) {
+func generateCLionProject(compiledModule CompiledInterface, ctx android.SingletonContext, ccModule *Module) {
srcs := compiledModule.Srcs()
if len(srcs) == 0 {
return
@@ -287,7 +285,7 @@
return flag
}
-func parseCompilerParameters(params []string, ctx blueprint.SingletonContext, f *os.File) compilerParameters {
+func parseCompilerParameters(params []string, ctx android.SingletonContext, f *os.File) compilerParameters {
var compilerParameters = makeCompilerParameters()
for i, str := range params {
@@ -388,7 +386,7 @@
c1.flags = append(c1.flags, c2.flags...)
}
-func evalVariable(ctx blueprint.SingletonContext, str string) (string, error) {
+func evalVariable(ctx android.SingletonContext, str string) (string, error) {
evaluated, err := ctx.Eval(pctx, str)
if err == nil {
return evaluated, nil
@@ -396,7 +394,7 @@
return "", err
}
-func getCMakeListsForModule(module *Module, ctx blueprint.SingletonContext) string {
+func getCMakeListsForModule(module *Module, ctx android.SingletonContext) string {
return filepath.Join(getAndroidSrcRootDirectory(ctx),
cLionOutputProjectsDirectory,
path.Dir(ctx.BlueprintFile(module)),
@@ -406,7 +404,7 @@
cMakeListsFilename)
}
-func getAndroidSrcRootDirectory(ctx blueprint.SingletonContext) string {
+func getAndroidSrcRootDirectory(ctx android.SingletonContext) string {
srcPath, _ := filepath.Abs(android.PathForSource(ctx).String())
return srcPath
}
diff --git a/cc/config/global.go b/cc/config/global.go
index 4322436..8881b4b 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -216,14 +216,14 @@
[]string{"libnativehelper/include_deprecated"})
pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
- pctx.VariableFunc("ClangBase", func(config interface{}) (string, error) {
- if override := config.(android.Config).Getenv("LLVM_PREBUILTS_BASE"); override != "" {
+ pctx.VariableFunc("ClangBase", func(config android.Config) (string, error) {
+ if override := config.Getenv("LLVM_PREBUILTS_BASE"); override != "" {
return override, nil
}
return "${ClangDefaultBase}", nil
})
- pctx.VariableFunc("ClangVersion", func(config interface{}) (string, error) {
- if override := config.(android.Config).Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
+ pctx.VariableFunc("ClangVersion", func(config android.Config) (string, error) {
+ if override := config.Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
return override, nil
}
return ClangDefaultVersion, nil
@@ -231,8 +231,8 @@
pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
- pctx.VariableFunc("ClangShortVersion", func(config interface{}) (string, error) {
- if override := config.(android.Config).Getenv("LLVM_RELEASE_VERSION"); override != "" {
+ pctx.VariableFunc("ClangShortVersion", func(config android.Config) (string, error) {
+ if override := config.Getenv("LLVM_RELEASE_VERSION"); override != "" {
return override, nil
}
return ClangDefaultShortVersion, nil
@@ -258,8 +258,8 @@
"frameworks/rs/script_api/include",
})
- pctx.VariableFunc("CcWrapper", func(config interface{}) (string, error) {
- if override := config.(android.Config).Getenv("CC_WRAPPER"); override != "" {
+ pctx.VariableFunc("CcWrapper", func(config android.Config) (string, error) {
+ if override := config.Getenv("CC_WRAPPER"); override != "" {
return override + " ", nil
}
return "", nil
diff --git a/cc/config/tidy.go b/cc/config/tidy.go
index a2fa5a2..76a5f9e 100644
--- a/cc/config/tidy.go
+++ b/cc/config/tidy.go
@@ -25,8 +25,8 @@
// Global tidy checks include only google*, performance*,
// and misc-macro-parentheses, but not google-readability*
// or google-runtime-references.
- pctx.VariableFunc("TidyDefaultGlobalChecks", func(config interface{}) (string, error) {
- if override := config.(android.Config).Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
+ pctx.VariableFunc("TidyDefaultGlobalChecks", func(config android.Config) (string, error) {
+ if override := config.Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
return override, nil
}
return strings.Join([]string{
@@ -41,8 +41,8 @@
// There are too many clang-tidy warnings in external and vendor projects.
// Enable only some google checks for these projects.
- pctx.VariableFunc("TidyExternalVendorChecks", func(config interface{}) (string, error) {
- if override := config.(android.Config).Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
+ pctx.VariableFunc("TidyExternalVendorChecks", func(config android.Config) (string, error) {
+ if override := config.Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
return override, nil
}
return strings.Join([]string{
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index 8d805c9..dbaa6fa 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -107,25 +107,25 @@
)
func init() {
- pctx.VariableFunc("macSdkPath", func(config interface{}) (string, error) {
- xcodeselect := config.(android.Config).HostSystemTool("xcode-select")
+ pctx.VariableFunc("macSdkPath", func(config android.Config) (string, error) {
+ xcodeselect := config.HostSystemTool("xcode-select")
bytes, err := exec.Command(xcodeselect, "--print-path").Output()
return strings.TrimSpace(string(bytes)), err
})
- pctx.VariableFunc("macSdkRoot", func(config interface{}) (string, error) {
- return xcrunSdk(config.(android.Config), "--show-sdk-path")
+ pctx.VariableFunc("macSdkRoot", func(config android.Config) (string, error) {
+ return xcrunSdk(config, "--show-sdk-path")
})
pctx.StaticVariable("macMinVersion", "10.8")
- pctx.VariableFunc("MacArPath", func(config interface{}) (string, error) {
- return xcrun(config.(android.Config), "--find", "ar")
+ pctx.VariableFunc("MacArPath", func(config android.Config) (string, error) {
+ return xcrun(config, "--find", "ar")
})
- pctx.VariableFunc("MacStripPath", func(config interface{}) (string, error) {
- return xcrun(config.(android.Config), "--find", "strip")
+ pctx.VariableFunc("MacStripPath", func(config android.Config) (string, error) {
+ return xcrun(config, "--find", "strip")
})
- pctx.VariableFunc("MacToolPath", func(config interface{}) (string, error) {
- path, err := xcrun(config.(android.Config), "--find", "ld")
+ pctx.VariableFunc("MacToolPath", func(config android.Config) (string, error) {
+ path, err := xcrun(config, "--find", "ld")
return filepath.Dir(path), err
})
diff --git a/cc/library.go b/cc/library.go
index 192496a..cf10617 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -85,9 +85,6 @@
VariantIsShared bool `blueprint:"mutated"`
// This variant is static
VariantIsStatic bool `blueprint:"mutated"`
- // Location of the static library in the sysroot. Empty if the library is
- // not included in the NDK.
- NdkSysrootPath string `blueprint:"mutated"`
}
type FlagExporterProperties struct {
@@ -246,6 +243,10 @@
// Source Abi Diff
sAbiDiff android.OptionalPath
+ // Location of the static library in the sysroot. Empty if the library is
+ // not included in the NDK.
+ ndkSysrootPath android.Path
+
// Decorated interafaces
*baseCompiler
*baseLinker
@@ -742,7 +743,7 @@
Input: file,
})
- library.MutatedProperties.NdkSysrootPath = installPath.String()
+ library.ndkSysrootPath = installPath
}
}
diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go
index bfbf0f5..d7c2a06 100644
--- a/cc/ndk_headers.go
+++ b/cc/ndk_headers.go
@@ -74,7 +74,7 @@
properties headerProperies
- installPaths []string
+ installPaths android.Paths
licensePath android.ModuleSrcPath
}
@@ -139,7 +139,7 @@
"expected header install path (%q) not equal to actual install path %q",
installPath, installedPath))
}
- m.installPaths = append(m.installPaths, installPath.String())
+ m.installPaths = append(m.installPaths, installPath)
}
if len(m.installPaths) == 0 {
@@ -186,7 +186,7 @@
properties preprocessedHeaderProperies
- installPaths []string
+ installPaths android.Paths
licensePath android.ModuleSrcPath
}
@@ -208,7 +208,7 @@
installDir := getHeaderInstallDir(ctx, header, String(m.properties.From), String(m.properties.To))
installPath := installDir.Join(ctx, header.Base())
installPaths = append(installPaths, installPath)
- m.installPaths = append(m.installPaths, installPath.String())
+ m.installPaths = append(m.installPaths, installPath)
}
if len(m.installPaths) == 0 {
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 96a90fb..e69128c 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -98,7 +98,7 @@
properties libraryProperties
versionScriptPath android.ModuleGenPath
- installPath string
+ installPath android.Path
}
// OMG GO
@@ -344,7 +344,7 @@
installDir := getNdkInstallBase(ctx).Join(ctx, fmt.Sprintf(
"platforms/android-%s/arch-%s/usr/%s", apiLevel, arch, libDir))
- stub.installPath = ctx.InstallFile(installDir, path.Base(), path).String()
+ stub.installPath = ctx.InstallFile(installDir, path.Base(), path)
}
func newStubLibrary() *Module {
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index e213965..4324458 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -53,8 +53,6 @@
// TODO(danalbert): Write `ndk_static_library` rule.
import (
- "github.com/google/blueprint"
-
"android/soong/android"
)
@@ -76,32 +74,32 @@
return getNdkInstallBase(ctx).Join(ctx, "sysroot")
}
-func getNdkSysrootTimestampFile(ctx android.PathContext) android.Path {
+func getNdkSysrootTimestampFile(ctx android.PathContext) android.WritablePath {
return android.PathForOutput(ctx, "ndk.timestamp")
}
-func NdkSingleton() blueprint.Singleton {
+func NdkSingleton() android.Singleton {
return &ndkSingleton{}
}
type ndkSingleton struct{}
-func (n *ndkSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
- installPaths := []string{}
- licensePaths := []string{}
- ctx.VisitAllModules(func(module blueprint.Module) {
+func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
+ var installPaths android.Paths
+ var licensePaths android.Paths
+ ctx.VisitAllModules(func(module android.Module) {
if m, ok := module.(android.Module); ok && !m.Enabled() {
return
}
if m, ok := module.(*headerModule); ok {
installPaths = append(installPaths, m.installPaths...)
- licensePaths = append(licensePaths, m.licensePath.String())
+ licensePaths = append(licensePaths, m.licensePath)
}
if m, ok := module.(*preprocessedHeaderModule); ok {
installPaths = append(installPaths, m.installPaths...)
- licensePaths = append(licensePaths, m.licensePath.String())
+ licensePaths = append(licensePaths, m.licensePath)
}
if m, ok := module.(*Module); ok {
@@ -110,30 +108,28 @@
}
if library, ok := m.linker.(*libraryDecorator); ok {
- if library.MutatedProperties.NdkSysrootPath != "" {
- installPaths = append(installPaths, library.MutatedProperties.NdkSysrootPath)
+ if library.ndkSysrootPath != nil {
+ installPaths = append(installPaths, library.ndkSysrootPath)
}
}
}
})
combinedLicense := getNdkInstallBase(ctx).Join(ctx, "NOTICE")
- ctx.Build(pctx, blueprint.BuildParams{
+ ctx.Build(pctx, android.BuildParams{
Rule: android.Cat,
Description: "combine licenses",
- Outputs: []string{combinedLicense.String()},
+ Output: combinedLicense,
Inputs: licensePaths,
- Optional: true,
})
- depPaths := append(installPaths, combinedLicense.String())
+ depPaths := append(installPaths, combinedLicense)
// There's a dummy "ndk" rule defined in ndk/Android.mk that depends on
// this. `m ndk` will build the sysroots.
- ctx.Build(pctx, blueprint.BuildParams{
+ ctx.Build(pctx, android.BuildParams{
Rule: android.Touch,
- Outputs: []string{getNdkSysrootTimestampFile(ctx).String()},
+ Output: getNdkSysrootTimestampFile(ctx),
Implicits: depPaths,
- Optional: true,
})
}