From 7260d066ea2d624e91d73c31062dd9ca795ecb4b Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Mon, 9 Dec 2019 21:47:14 +0000 Subject: [PATCH] Move/dedupe some host path functions in package_ctx.go. These functions don't need a PackageContext object. Test: m Bug: 145934348 Change-Id: Ia1da2c76cbad292f9ca79617199b2b5b6b265568 --- android/config.go | 12 ++++++++++++ android/package_ctx.go | 23 +++-------------------- apex/builder.go | 2 +- cc/rs.go | 2 +- java/config/config.go | 10 +++++----- java/hiddenapi_singleton.go | 2 +- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/android/config.go b/android/config.go index 1e5a24de9..271a54a07 100644 --- a/android/config.go +++ b/android/config.go @@ -418,6 +418,18 @@ func (c *config) HostToolPath(ctx PathContext, tool string) Path { return PathForOutput(ctx, "host", c.PrebuiltOS(), "bin", tool) } +func (c *config) HostJNIToolPath(ctx PathContext, path string) Path { + ext := ".so" + if runtime.GOOS == "darwin" { + ext = ".dylib" + } + return PathForOutput(ctx, "host", c.PrebuiltOS(), "lib64", path+ext) +} + +func (c *config) HostJavaToolPath(ctx PathContext, path string) Path { + return PathForOutput(ctx, "host", c.PrebuiltOS(), "framework", path) +} + // HostSystemTool looks for non-hermetic tools from the system we're running on. // Generally shouldn't be used, but useful to find the XCode SDK, etc. func (c *config) HostSystemTool(name string) string { diff --git a/android/package_ctx.go b/android/package_ctx.go index cf8facef4..d3527fa20 100644 --- a/android/package_ctx.go +++ b/android/package_ctx.go @@ -16,7 +16,6 @@ package android import ( "fmt" - "runtime" "strings" "github.com/google/blueprint" @@ -177,46 +176,30 @@ func (p PackageContext) SourcePathVariableWithEnvOverride(name, path, env string // package-scoped variable's initialization. func (p PackageContext) HostBinToolVariable(name, path string) blueprint.Variable { return p.VariableFunc(name, func(ctx PackageVarContext) string { - return p.HostBinToolPath(ctx, path).String() + return ctx.Config().HostToolPath(ctx, path).String() }) } -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 // in the lib directory for host targets. 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) HostJNIToolVariable(name, path string) blueprint.Variable { return p.VariableFunc(name, func(ctx PackageVarContext) string { - return p.HostJNIToolPath(ctx, path).String() + return ctx.Config().HostJNIToolPath(ctx, path).String() }) } -func (p PackageContext) HostJNIToolPath(ctx PackageVarContext, path string) Path { - ext := ".so" - if runtime.GOOS == "darwin" { - ext = ".dylib" - } - return PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "lib64", path+ext) -} - // HostJavaToolVariable returns a Variable whose value is the path to a host // tool in the frameworks directory for host targets. 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) HostJavaToolVariable(name, path string) blueprint.Variable { return p.VariableFunc(name, func(ctx PackageVarContext) string { - return p.HostJavaToolPath(ctx, path).String() + return ctx.Config().HostJavaToolPath(ctx, path).String() }) } -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 // directory appended with the supplied path. It may only be called during a Go // package's initialization - either from the init() function or as part of a diff --git a/apex/builder.go b/apex/builder.go index f199bd4be..db57a9c5e 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -43,7 +43,7 @@ func init() { if !ctx.Config().FrameworksBaseDirExists(ctx) { return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool) } else { - return pctx.HostBinToolPath(ctx, tool).String() + return ctx.Config().HostToolPath(ctx, tool).String() } }) } diff --git a/cc/rs.go b/cc/rs.go index 61fd1a84a..9149e1767 100644 --- a/cc/rs.go +++ b/cc/rs.go @@ -29,7 +29,7 @@ func init() { // Use RenderScript prebuilts for unbundled builds but not PDK builds return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin/llvm-rs-cc") } else { - return pctx.HostBinToolPath(ctx, "llvm-rs-cc").String() + return ctx.Config().HostToolPath(ctx, "llvm-rs-cc").String() } }) } diff --git a/java/config/config.go b/java/config/config.go index 333de32d6..fee6341c3 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -124,7 +124,7 @@ func init() { if ctx.Config().UnbundledBuild() { return "prebuilts/build-tools/common/framework/" + turbine } else { - return pctx.HostJavaToolPath(ctx, turbine).String() + return ctx.Config().HostJavaToolPath(ctx, turbine).String() } }) @@ -170,7 +170,7 @@ func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) { if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() { return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin", tool) } else { - return pctx.HostBinToolPath(ctx, tool).String() + return ctx.Config().HostToolPath(ctx, tool).String() } }) } @@ -180,7 +180,7 @@ func hostJavaToolVariableWithSdkToolsPrebuilt(name, tool string) { if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() { return filepath.Join("prebuilts/sdk/tools/lib", tool+".jar") } else { - return pctx.HostJavaToolPath(ctx, tool+".jar").String() + return ctx.Config().HostJavaToolPath(ctx, tool+".jar").String() } }) } @@ -194,7 +194,7 @@ func hostJNIToolVariableWithSdkToolsPrebuilt(name, tool string) { } return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "lib64", tool+ext) } else { - return pctx.HostJNIToolPath(ctx, tool).String() + return ctx.Config().HostJNIToolPath(ctx, tool).String() } }) } @@ -204,7 +204,7 @@ func hostBinToolVariableWithBuildToolsPrebuilt(name, tool string) { if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() { return filepath.Join("prebuilts/build-tools", ctx.Config().PrebuiltOS(), "bin", tool) } else { - return pctx.HostBinToolPath(ctx, tool).String() + return ctx.Config().HostToolPath(ctx, tool).String() } }) } diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go index c0ef444fc..ad84cdea2 100644 --- a/java/hiddenapi_singleton.go +++ b/java/hiddenapi_singleton.go @@ -190,7 +190,7 @@ func stubFlagsRule(ctx android.SingletonContext) { rule.MissingDeps(missingDeps) rule.Command(). - Tool(pctx.HostBinToolPath(ctx, "hiddenapi")). + Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). Text("list"). FlagForEachInput("--boot-dex=", bootDexJars). FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":").