diff --git a/android/paths.go b/android/paths.go index 56f36ea08..69ab5f75c 100644 --- a/android/paths.go +++ b/android/paths.go @@ -462,6 +462,13 @@ func (p OutputPaths) Strings() []string { return ret } +// PathForGoBinary returns the path to the installed location of a bootstrap_go_binary module. +func PathForGoBinary(ctx PathContext, goBinary bootstrap.GoBinaryTool) Path { + goBinaryInstallDir := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false) + rel := Rel(ctx, goBinaryInstallDir.String(), goBinary.InstallPath()) + return goBinaryInstallDir.Join(ctx, rel) +} + // Expands Paths to a SourceFileProducer or OutputFileProducer module dependency referenced via ":name" or ":name{.tag}" syntax. // If the dependency is not found, a missingErrorDependency is returned. // If the module dependency is not a SourceFileProducer or OutputFileProducer, appropriate errors will be returned. @@ -482,11 +489,8 @@ func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag } else if tag != "" { return nil, fmt.Errorf("path dependency %q is not an output file producing module", path) } else if goBinary, ok := module.(bootstrap.GoBinaryTool); ok { - if rel, err := filepath.Rel(PathForOutput(ctx).String(), goBinary.InstallPath()); err == nil { - return Paths{PathForOutput(ctx, rel).WithoutRel()}, nil - } else { - return nil, fmt.Errorf("cannot find output path for %q: %w", goBinary.InstallPath(), err) - } + goBinaryPath := PathForGoBinary(ctx, goBinary) + return Paths{goBinaryPath}, nil } else if srcProducer, ok := module.(SourceFileProducer); ok { return srcProducer.Srcs(), nil } else { diff --git a/apex/apex.go b/apex/apex.go index 1f0618750..a36a022f6 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1454,12 +1454,7 @@ func apexFileForPyBinary(ctx android.BaseModuleContext, py *python.Module) apexF func apexFileForGoBinary(ctx android.BaseModuleContext, depName string, gb bootstrap.GoBinaryTool) apexFile { dirInApex := "bin" - s, err := filepath.Rel(android.PathForOutput(ctx).String(), gb.InstallPath()) - if err != nil { - ctx.ModuleErrorf("Unable to use compiled binary at %s", gb.InstallPath()) - return apexFile{} - } - fileToCopy := android.PathForOutput(ctx, s) + fileToCopy := android.PathForGoBinary(ctx, gb) // NB: Since go binaries are static we don't need the module for anything here, which is // good since the go tool is a blueprint.Module not an android.Module like we would // normally use. diff --git a/genrule/genrule.go b/genrule/genrule.go index b9c2b109d..c9bf958a3 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -336,14 +336,9 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) { } case bootstrap.GoBinaryTool: // A GoBinaryTool provides the install path to a tool, which will be copied. - if s, err := filepath.Rel(android.PathForOutput(ctx).String(), t.InstallPath()); err == nil { - toolPath := android.PathForOutput(ctx, s) - tools = append(tools, toolPath) - addLocationLabel(tag.label, toolLocation{android.Paths{toolPath}}) - } else { - ctx.ModuleErrorf("cannot find path for %q: %v", tool, err) - return - } + p := android.PathForGoBinary(ctx, t) + tools = append(tools, p) + addLocationLabel(tag.label, toolLocation{android.Paths{p}}) default: ctx.ModuleErrorf("%q is not a host tool provider", tool) return