Switch PackageContext functions to take a ctx
So that the Path and similar functions can be used directly, without
manually adding something like configErrorWrapper (it just uses it all
the time now).
Bug: 76168832
Test: out/soong/build.ninja is identical
Change-Id: I8cb524b09a84d0b8357d7c3501c71270af411e17
Merged-In: I8cb524b09a84d0b8357d7c3501c71270af411e17
(cherry picked from commit 54daaf0371
)
This commit is contained in:
parent
0c1f7bd956
commit
bf4f0a0965
7 changed files with 144 additions and 178 deletions
|
@ -47,6 +47,9 @@ type configErrorWrapper struct {
|
|||
|
||||
var _ PathContext = &configErrorWrapper{}
|
||||
var _ errorfContext = &configErrorWrapper{}
|
||||
var _ PackageVarContext = &configErrorWrapper{}
|
||||
var _ PackagePoolContext = &configErrorWrapper{}
|
||||
var _ PackageRuleContext = &configErrorWrapper{}
|
||||
|
||||
func (e *configErrorWrapper) Config() Config {
|
||||
return e.config
|
||||
|
@ -62,33 +65,56 @@ func (e *configErrorWrapper) Fs() pathtools.FileSystem {
|
|||
return nil
|
||||
}
|
||||
|
||||
type PackageVarContext interface {
|
||||
PathContext
|
||||
errorfContext
|
||||
}
|
||||
|
||||
type PackagePoolContext PackageVarContext
|
||||
type PackageRuleContext PackageVarContext
|
||||
|
||||
// VariableFunc wraps blueprint.PackageContext.VariableFunc, converting the interface{} config
|
||||
// argument to a Config.
|
||||
// argument to a PackageVarContext.
|
||||
func (p PackageContext) VariableFunc(name string,
|
||||
f func(Config) (string, error)) blueprint.Variable {
|
||||
f func(PackageVarContext) string) blueprint.Variable {
|
||||
|
||||
return p.PackageContext.VariableFunc(name, func(config interface{}) (string, error) {
|
||||
return f(config.(Config))
|
||||
ctx := &configErrorWrapper{p, config.(Config), nil}
|
||||
ret := f(ctx)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return ret, nil
|
||||
})
|
||||
}
|
||||
|
||||
// PoolFunc wraps blueprint.PackageContext.PoolFunc, converting the interface{} config
|
||||
// argument to a Config.
|
||||
// argument to a Context that supports Config().
|
||||
func (p PackageContext) PoolFunc(name string,
|
||||
f func(Config) (blueprint.PoolParams, error)) blueprint.Pool {
|
||||
f func(PackagePoolContext) blueprint.PoolParams) blueprint.Pool {
|
||||
|
||||
return p.PackageContext.PoolFunc(name, func(config interface{}) (blueprint.PoolParams, error) {
|
||||
return f(config.(Config))
|
||||
ctx := &configErrorWrapper{p, config.(Config), nil}
|
||||
params := f(ctx)
|
||||
if len(ctx.errors) > 0 {
|
||||
return params, ctx.errors[0]
|
||||
}
|
||||
return params, nil
|
||||
})
|
||||
}
|
||||
|
||||
// RuleFunc wraps blueprint.PackageContext.RuleFunc, converting the interface{} config
|
||||
// argument to a Config.
|
||||
// argument to a Context that supports Config().
|
||||
func (p PackageContext) RuleFunc(name string,
|
||||
f func(Config) (blueprint.RuleParams, error), argNames ...string) blueprint.Rule {
|
||||
f func(PackageRuleContext) blueprint.RuleParams, argNames ...string) blueprint.Rule {
|
||||
|
||||
return p.PackageContext.RuleFunc(name, func(config interface{}) (blueprint.RuleParams, error) {
|
||||
return f(config.(Config))
|
||||
ctx := &configErrorWrapper{p, config.(Config), nil}
|
||||
params := f(ctx)
|
||||
if len(ctx.errors) > 0 {
|
||||
return params, ctx.errors[0]
|
||||
}
|
||||
return params, nil
|
||||
}, argNames...)
|
||||
}
|
||||
|
||||
|
@ -97,13 +123,8 @@ func (p PackageContext) RuleFunc(name string,
|
|||
// initialization - either from the init() function or as part of a
|
||||
// package-scoped variable's initialization.
|
||||
func (p PackageContext) SourcePathVariable(name, path string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
p := safePathForSource(ctx, path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return p.String(), nil
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
return safePathForSource(ctx, path).String()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -112,17 +133,13 @@ func (p PackageContext) SourcePathVariable(name, path string) blueprint.Variable
|
|||
// called during a Go package's initialization - either from the init()
|
||||
// function or as part of a package-scoped variable's initialization.
|
||||
func (p PackageContext) SourcePathsVariable(name, separator string, paths ...string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
var ret []string
|
||||
for _, path := range paths {
|
||||
p := safePathForSource(ctx, path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
ret = append(ret, p.String())
|
||||
}
|
||||
return strings.Join(ret, separator), nil
|
||||
return strings.Join(ret, separator)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -132,13 +149,9 @@ func (p PackageContext) SourcePathsVariable(name, separator string, paths ...str
|
|||
// It may only be called during a Go package's initialization - either from the init() function or
|
||||
// as part of a package-scoped variable's initialization.
|
||||
func (p PackageContext) SourcePathVariableWithEnvOverride(name, path, env string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
p := safePathForSource(ctx, path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return config.GetenvWithDefault(env, p.String()), nil
|
||||
return ctx.Config().GetenvWithDefault(env, p.String())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -147,22 +160,13 @@ func (p PackageContext) SourcePathVariableWithEnvOverride(name, path, env string
|
|||
// package's initialization - either from the init() function or as part of a
|
||||
// package-scoped variable's initialization.
|
||||
func (p PackageContext) HostBinToolVariable(name, path string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
po, err := p.HostBinToolPath(config, path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return po.String(), nil
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
return p.HostBinToolPath(ctx, path).String()
|
||||
})
|
||||
}
|
||||
|
||||
func (p PackageContext) HostBinToolPath(config Config, path string) (Path, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
pa := PathForOutput(ctx, "host", ctx.config.PrebuiltOS(), "bin", path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return nil, ctx.errors[0]
|
||||
}
|
||||
return pa, nil
|
||||
func (p PackageContext) HostBinToolPath(ctx PackageVarContext, path string) Path {
|
||||
return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin", path)
|
||||
}
|
||||
|
||||
// HostJNIToolVariable returns a Variable whose value is the path to a host tool
|
||||
|
@ -170,26 +174,17 @@ func (p PackageContext) HostBinToolPath(config Config, path string) (Path, error
|
|||
// package's initialization - either from the init() function or as part of a
|
||||
// package-scoped variable's initialization.
|
||||
func (p PackageContext) HostJNIToolVariable(name, path string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
po, err := p.HostJNIToolPath(config, path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return po.String(), nil
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
return p.HostJNIToolPath(ctx, path).String()
|
||||
})
|
||||
}
|
||||
|
||||
func (p PackageContext) HostJNIToolPath(config Config, path string) (Path, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
func (p PackageContext) HostJNIToolPath(ctx PackageVarContext, path string) Path {
|
||||
ext := ".so"
|
||||
if runtime.GOOS == "darwin" {
|
||||
ext = ".dylib"
|
||||
}
|
||||
pa := PathForOutput(ctx, "host", ctx.config.PrebuiltOS(), "lib64", path+ext)
|
||||
if len(ctx.errors) > 0 {
|
||||
return nil, ctx.errors[0]
|
||||
}
|
||||
return pa, nil
|
||||
return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "lib64", path+ext)
|
||||
}
|
||||
|
||||
// HostJavaToolVariable returns a Variable whose value is the path to a host
|
||||
|
@ -197,23 +192,13 @@ func (p PackageContext) HostJNIToolPath(config Config, path string) (Path, error
|
|||
// during a Go package's initialization - either from the init() function or as
|
||||
// part of a package-scoped variable's initialization.
|
||||
func (p PackageContext) HostJavaToolVariable(name, path string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
p := PathForOutput(ctx, "host", ctx.config.PrebuiltOS(), "framework", path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return p.String(), nil
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
return p.HostJavaToolPath(ctx, path).String()
|
||||
})
|
||||
}
|
||||
|
||||
func (p PackageContext) HostJavaToolPath(config Config, path string) (Path, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
pa := PathForOutput(ctx, "host", ctx.config.PrebuiltOS(), "framework", path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return nil, ctx.errors[0]
|
||||
}
|
||||
return pa, nil
|
||||
func (p PackageContext) HostJavaToolPath(ctx PackageVarContext, path string) Path {
|
||||
return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", path)
|
||||
}
|
||||
|
||||
// IntermediatesPathVariable returns a Variable whose value is the intermediate
|
||||
|
@ -221,13 +206,8 @@ func (p PackageContext) HostJavaToolPath(config Config, path string) (Path, erro
|
|||
// package's initialization - either from the init() function or as part of a
|
||||
// package-scoped variable's initialization.
|
||||
func (p PackageContext) IntermediatesPathVariable(name, path string) blueprint.Variable {
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
p := PathForIntermediates(ctx, path)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return p.String(), nil
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
return PathForIntermediates(ctx, path).String()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -238,21 +218,17 @@ func (p PackageContext) IntermediatesPathVariable(name, path string) blueprint.V
|
|||
func (p PackageContext) PrefixedExistentPathsForSourcesVariable(
|
||||
name, prefix string, paths []string) blueprint.Variable {
|
||||
|
||||
return p.VariableFunc(name, func(config Config) (string, error) {
|
||||
ctx := &configErrorWrapper{p, config, []error{}}
|
||||
return p.VariableFunc(name, func(ctx PackageVarContext) string {
|
||||
paths := ExistentPathsForSources(ctx, paths)
|
||||
if len(ctx.errors) > 0 {
|
||||
return "", ctx.errors[0]
|
||||
}
|
||||
return JoinWithPrefix(paths.Strings(), prefix), nil
|
||||
return JoinWithPrefix(paths.Strings(), prefix)
|
||||
})
|
||||
}
|
||||
|
||||
// AndroidStaticRule wraps blueprint.StaticRule and provides a default Pool if none is specified
|
||||
func (p PackageContext) AndroidStaticRule(name string, params blueprint.RuleParams,
|
||||
argNames ...string) blueprint.Rule {
|
||||
return p.AndroidRuleFunc(name, func(Config) (blueprint.RuleParams, error) {
|
||||
return params, nil
|
||||
return p.AndroidRuleFunc(name, func(PackageRuleContext) blueprint.RuleParams {
|
||||
return params
|
||||
}, argNames...)
|
||||
}
|
||||
|
||||
|
@ -263,14 +239,14 @@ func (p PackageContext) AndroidGomaStaticRule(name string, params blueprint.Rule
|
|||
}
|
||||
|
||||
func (p PackageContext) AndroidRuleFunc(name string,
|
||||
f func(Config) (blueprint.RuleParams, error), argNames ...string) blueprint.Rule {
|
||||
return p.RuleFunc(name, func(config Config) (blueprint.RuleParams, error) {
|
||||
params, err := f(config)
|
||||
if config.UseGoma() && params.Pool == nil {
|
||||
f func(PackageRuleContext) blueprint.RuleParams, argNames ...string) blueprint.Rule {
|
||||
return p.RuleFunc(name, func(ctx PackageRuleContext) blueprint.RuleParams {
|
||||
params := f(ctx)
|
||||
if ctx.Config().UseGoma() && params.Pool == nil {
|
||||
// When USE_GOMA=true is set and the rule is not supported by goma, restrict jobs to the
|
||||
// local parallelism value
|
||||
params.Pool = localPool
|
||||
}
|
||||
return params, err
|
||||
return params
|
||||
}, argNames...)
|
||||
}
|
||||
|
|
|
@ -196,10 +196,10 @@ var (
|
|||
_ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-diff")
|
||||
|
||||
sAbiDiff = pctx.AndroidRuleFunc("sAbiDiff",
|
||||
func(config android.Config) (blueprint.RuleParams, error) {
|
||||
func(ctx android.PackageRuleContext) blueprint.RuleParams {
|
||||
|
||||
commandStr := "($sAbiDiffer $allowFlags -lib $libName -arch $arch -check-all-apis -o ${out} -new $in -old $referenceDump)"
|
||||
distDir := config.ProductVariables.DistDir
|
||||
distDir := ctx.Config().ProductVariables.DistDir
|
||||
commandStr += " || (echo ' ---- Please update abi references by running platform/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l ${libName} ----'"
|
||||
if distDir != nil && *distDir != "" {
|
||||
distAbiDiffDir := *distDir + "/abidiffs/"
|
||||
|
@ -209,7 +209,7 @@ var (
|
|||
return blueprint.RuleParams{
|
||||
Command: commandStr,
|
||||
CommandDeps: []string{"$sAbiDiffer"},
|
||||
}, nil
|
||||
}
|
||||
},
|
||||
"allowFlags", "referenceDump", "libName", "arch")
|
||||
|
||||
|
|
|
@ -180,26 +180,26 @@ func init() {
|
|||
[]string{"libnativehelper/include_jni"})
|
||||
|
||||
pctx.SourcePathVariable("ClangDefaultBase", ClangDefaultBase)
|
||||
pctx.VariableFunc("ClangBase", func(config android.Config) (string, error) {
|
||||
if override := config.Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
||||
return override, nil
|
||||
pctx.VariableFunc("ClangBase", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("LLVM_PREBUILTS_BASE"); override != "" {
|
||||
return override
|
||||
}
|
||||
return "${ClangDefaultBase}", nil
|
||||
return "${ClangDefaultBase}"
|
||||
})
|
||||
pctx.VariableFunc("ClangVersion", func(config android.Config) (string, error) {
|
||||
if override := config.Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
||||
return override, nil
|
||||
pctx.VariableFunc("ClangVersion", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("LLVM_PREBUILTS_VERSION"); override != "" {
|
||||
return override
|
||||
}
|
||||
return ClangDefaultVersion, nil
|
||||
return ClangDefaultVersion
|
||||
})
|
||||
pctx.StaticVariable("ClangPath", "${ClangBase}/${HostPrebuiltTag}/${ClangVersion}")
|
||||
pctx.StaticVariable("ClangBin", "${ClangPath}/bin")
|
||||
|
||||
pctx.VariableFunc("ClangShortVersion", func(config android.Config) (string, error) {
|
||||
if override := config.Getenv("LLVM_RELEASE_VERSION"); override != "" {
|
||||
return override, nil
|
||||
pctx.VariableFunc("ClangShortVersion", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("LLVM_RELEASE_VERSION"); override != "" {
|
||||
return override
|
||||
}
|
||||
return ClangDefaultShortVersion, nil
|
||||
return ClangDefaultShortVersion
|
||||
})
|
||||
pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
|
||||
if runtime.GOOS == "darwin" {
|
||||
|
@ -222,11 +222,11 @@ func init() {
|
|||
"frameworks/rs/script_api/include",
|
||||
})
|
||||
|
||||
pctx.VariableFunc("CcWrapper", func(config android.Config) (string, error) {
|
||||
if override := config.Getenv("CC_WRAPPER"); override != "" {
|
||||
return override + " ", nil
|
||||
pctx.VariableFunc("CcWrapper", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("CC_WRAPPER"); override != "" {
|
||||
return override + " "
|
||||
}
|
||||
return "", nil
|
||||
return ""
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,8 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -25,9 +24,9 @@ func init() {
|
|||
// Global tidy checks include only google*, performance*,
|
||||
// and misc-macro-parentheses, but not google-readability*
|
||||
// or google-runtime-references.
|
||||
pctx.VariableFunc("TidyDefaultGlobalChecks", func(config android.Config) (string, error) {
|
||||
if override := config.Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
|
||||
return override, nil
|
||||
pctx.VariableFunc("TidyDefaultGlobalChecks", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
|
||||
return override
|
||||
}
|
||||
return strings.Join([]string{
|
||||
"-*",
|
||||
|
@ -36,14 +35,14 @@ func init() {
|
|||
"performance*",
|
||||
"-google-readability*",
|
||||
"-google-runtime-references",
|
||||
}, ","), nil
|
||||
}, ",")
|
||||
})
|
||||
|
||||
// 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 android.Config) (string, error) {
|
||||
if override := config.Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
|
||||
return override, nil
|
||||
pctx.VariableFunc("TidyExternalVendorChecks", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
|
||||
return override
|
||||
}
|
||||
return strings.Join([]string{
|
||||
"-*",
|
||||
|
@ -54,7 +53,7 @@ func init() {
|
|||
"-google-readability*",
|
||||
"-google-runtime-int",
|
||||
"-google-runtime-references",
|
||||
}, ","), nil
|
||||
}, ",")
|
||||
})
|
||||
|
||||
// Give warnings to header files only in selected directories.
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -107,26 +106,28 @@ const (
|
|||
)
|
||||
|
||||
func init() {
|
||||
pctx.VariableFunc("macSdkPath", func(config android.Config) (string, error) {
|
||||
xcodeselect := config.HostSystemTool("xcode-select")
|
||||
pctx.VariableFunc("macSdkPath", func(ctx android.PackageVarContext) string {
|
||||
xcodeselect := ctx.Config().HostSystemTool("xcode-select")
|
||||
bytes, err := exec.Command(xcodeselect, "--print-path").Output()
|
||||
return strings.TrimSpace(string(bytes)), err
|
||||
if err != nil {
|
||||
ctx.Errorf("xcode-select failed with: %q", err.Error())
|
||||
}
|
||||
return strings.TrimSpace(string(bytes))
|
||||
})
|
||||
pctx.VariableFunc("macSdkRoot", func(config android.Config) (string, error) {
|
||||
return xcrunSdk(config, "--show-sdk-path")
|
||||
pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string {
|
||||
return xcrunSdk(ctx, "--show-sdk-path")
|
||||
})
|
||||
pctx.StaticVariable("macMinVersion", "10.8")
|
||||
pctx.VariableFunc("MacArPath", func(config android.Config) (string, error) {
|
||||
return xcrun(config, "--find", "ar")
|
||||
pctx.VariableFunc("MacArPath", func(ctx android.PackageVarContext) string {
|
||||
return xcrun(ctx, "--find", "ar")
|
||||
})
|
||||
|
||||
pctx.VariableFunc("MacStripPath", func(config android.Config) (string, error) {
|
||||
return xcrun(config, "--find", "strip")
|
||||
pctx.VariableFunc("MacStripPath", func(ctx android.PackageVarContext) string {
|
||||
return xcrun(ctx, "--find", "strip")
|
||||
})
|
||||
|
||||
pctx.VariableFunc("MacToolPath", func(config android.Config) (string, error) {
|
||||
path, err := xcrun(config, "--find", "ld")
|
||||
return filepath.Dir(path), err
|
||||
pctx.VariableFunc("MacToolPath", func(ctx android.PackageVarContext) string {
|
||||
return filepath.Dir(xcrun(ctx, "--find", "ld"))
|
||||
})
|
||||
|
||||
pctx.StaticVariable("DarwinGccVersion", darwinGccVersion)
|
||||
|
@ -156,33 +157,38 @@ func init() {
|
|||
pctx.StaticVariable("DarwinX8664YasmFlags", "-f macho -m amd64")
|
||||
}
|
||||
|
||||
func xcrun(config android.Config, args ...string) (string, error) {
|
||||
xcrun := config.HostSystemTool("xcrun")
|
||||
func xcrun(ctx android.PackageVarContext, args ...string) string {
|
||||
xcrun := ctx.Config().HostSystemTool("xcrun")
|
||||
bytes, err := exec.Command(xcrun, args...).Output()
|
||||
return strings.TrimSpace(string(bytes)), err
|
||||
if err != nil {
|
||||
ctx.Errorf("xcrun failed with: %q", err.Error())
|
||||
}
|
||||
return strings.TrimSpace(string(bytes))
|
||||
}
|
||||
|
||||
func xcrunSdk(config android.Config, arg string) (string, error) {
|
||||
xcrun := config.HostSystemTool("xcrun")
|
||||
if selected := config.Getenv("MAC_SDK_VERSION"); selected != "" {
|
||||
func xcrunSdk(ctx android.PackageVarContext, arg string) string {
|
||||
xcrun := ctx.Config().HostSystemTool("xcrun")
|
||||
if selected := ctx.Config().Getenv("MAC_SDK_VERSION"); selected != "" {
|
||||
if !inList(selected, darwinSupportedSdkVersions) {
|
||||
return "", fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
|
||||
ctx.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
|
||||
return ""
|
||||
}
|
||||
|
||||
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+selected, arg).Output()
|
||||
if err == nil {
|
||||
return strings.TrimSpace(string(bytes)), err
|
||||
if err != nil {
|
||||
ctx.Errorf("MAC_SDK_VERSION %s is not installed", selected)
|
||||
}
|
||||
return "", fmt.Errorf("MAC_SDK_VERSION %s is not installed", selected)
|
||||
return strings.TrimSpace(string(bytes))
|
||||
}
|
||||
|
||||
for _, sdk := range darwinSupportedSdkVersions {
|
||||
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+sdk, arg).Output()
|
||||
if err == nil {
|
||||
return strings.TrimSpace(string(bytes)), err
|
||||
return strings.TrimSpace(string(bytes))
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
|
||||
ctx.Errorf("Could not find a supported mac sdk: %q", darwinSupportedSdkVersions)
|
||||
return ""
|
||||
}
|
||||
|
||||
type toolchainDarwin struct {
|
||||
|
|
|
@ -68,9 +68,9 @@ func init() {
|
|||
|
||||
pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
|
||||
|
||||
pctx.VariableFunc("JavaHome", func(config android.Config) (string, error) {
|
||||
pctx.VariableFunc("JavaHome", func(ctx android.PackageVarContext) string {
|
||||
// This is set up and guaranteed by soong_ui
|
||||
return config.Getenv("ANDROID_JAVA_HOME"), nil
|
||||
return ctx.Config().Getenv("ANDROID_JAVA_HOME")
|
||||
})
|
||||
|
||||
pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
|
||||
|
@ -91,38 +91,27 @@ func init() {
|
|||
pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
|
||||
pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
|
||||
pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
|
||||
pctx.VariableFunc("DxCmd", func(config android.Config) (string, error) {
|
||||
pctx.VariableFunc("DxCmd", func(ctx android.PackageVarContext) string {
|
||||
config := ctx.Config()
|
||||
if config.IsEnvFalse("USE_D8") {
|
||||
if config.UnbundledBuild() || config.IsPdkBuild() {
|
||||
return "prebuilts/build-tools/common/bin/dx", nil
|
||||
return "prebuilts/build-tools/common/bin/dx"
|
||||
} else {
|
||||
path, err := pctx.HostBinToolPath(config, "dx")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path.String(), nil
|
||||
return pctx.HostBinToolPath(ctx, "dx").String()
|
||||
}
|
||||
} else {
|
||||
path, err := pctx.HostBinToolPath(config, "d8-compat-dx")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path.String(), nil
|
||||
return pctx.HostBinToolPath(ctx, "d8-compat-dx").String()
|
||||
}
|
||||
})
|
||||
pctx.HostBinToolVariable("D8Cmd", "d8")
|
||||
pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
|
||||
|
||||
pctx.VariableFunc("TurbineJar", func(config android.Config) (string, error) {
|
||||
pctx.VariableFunc("TurbineJar", func(ctx android.PackageVarContext) string {
|
||||
turbine := "turbine.jar"
|
||||
if config.UnbundledBuild() {
|
||||
return "prebuilts/build-tools/common/framework/" + turbine, nil
|
||||
if ctx.Config().UnbundledBuild() {
|
||||
return "prebuilts/build-tools/common/framework/" + turbine
|
||||
} else {
|
||||
path, err := pctx.HostJavaToolPath(config, turbine)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path.String(), nil
|
||||
return pctx.HostJavaToolPath(ctx, turbine).String()
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -133,25 +122,21 @@ func init() {
|
|||
|
||||
pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
|
||||
|
||||
pctx.VariableFunc("JavacWrapper", func(config android.Config) (string, error) {
|
||||
if override := config.Getenv("JAVAC_WRAPPER"); override != "" {
|
||||
return override + " ", nil
|
||||
pctx.VariableFunc("JavacWrapper", func(ctx android.PackageVarContext) string {
|
||||
if override := ctx.Config().Getenv("JAVAC_WRAPPER"); override != "" {
|
||||
return override + " "
|
||||
}
|
||||
return "", nil
|
||||
return ""
|
||||
})
|
||||
|
||||
pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar")
|
||||
|
||||
hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
|
||||
pctx.VariableFunc(name, func(config android.Config) (string, error) {
|
||||
if config.UnbundledBuild() || config.IsPdkBuild() {
|
||||
return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool), nil
|
||||
pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
|
||||
if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
|
||||
return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
|
||||
} else {
|
||||
if path, err := pctx.HostBinToolPath(config, tool); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return path.String(), nil
|
||||
}
|
||||
return pctx.HostBinToolPath(ctx, tool).String()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ var (
|
|||
|
||||
// Wrapper that grabs value of val late so it can be initialized by a later module's init function
|
||||
func errorProneVar(name string, val *string) {
|
||||
pctx.VariableFunc(name, func(config android.Config) (string, error) {
|
||||
return *val, nil
|
||||
pctx.VariableFunc(name, func(android.PackageVarContext) string {
|
||||
return *val
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue