Add libc_musl as a dependency of RuleBuilderCommand.BuiltTool

Assume calls to RuleBuilderCommand.BuiltTool may refer to a tool
that was built against musl libc, and add it as a dependency
so that it is copied into the sandbox.  This emulates the
behavior of compiling against glibc, which is available from the
host sysroot when running in the sandbox.

Bug: 190084016
Test: m USE_HOST_MUSL=true sdk-repo-build-tools
Change-Id: Ieafdcceb818f9c31595487aab3ffbafba1412b3a
This commit is contained in:
Colin Cross
2021-12-22 09:55:32 -08:00
parent c2cdd8ab73
commit 9b698b68c9
2 changed files with 20 additions and 2 deletions

View File

@@ -470,7 +470,7 @@ var _ BuilderContext = SingletonContext(nil)
func (r *RuleBuilder) depFileMergerCmd(depFiles WritablePaths) *RuleBuilderCommand {
return r.Command().
BuiltTool("dep_fixer").
builtToolWithoutDeps("dep_fixer").
Inputs(depFiles.Paths())
}
@@ -638,7 +638,7 @@ func (r *RuleBuilder) Build(name string, desc string) {
}
sboxCmd.Text("rm -rf").Output(r.outDir)
sboxCmd.Text("&&")
sboxCmd.BuiltTool("sbox").
sboxCmd.builtToolWithoutDeps("sbox").
Flag("--sandbox-path").Text(shared.TempDirForOutDir(PathForOutput(r.ctx).String())).
Flag("--manifest").Input(r.sboxManifestPath)
@@ -1040,6 +1040,19 @@ func (c *RuleBuilderCommand) ImplicitTools(paths Paths) *RuleBuilderCommand {
// It is equivalent to:
// cmd.Tool(ctx.Config().HostToolPath(ctx, tool))
func (c *RuleBuilderCommand) BuiltTool(tool string) *RuleBuilderCommand {
if c.rule.ctx.Config().UseHostMusl() {
// If the host is using musl, assume that the tool was built against musl libc and include
// libc_musl.so in the sandbox.
// TODO(ccross): if we supported adding new dependencies during GenerateAndroidBuildActions
// this could be a dependency + TransitivePackagingSpecs.
c.ImplicitTool(c.rule.ctx.Config().HostJNIToolPath(c.rule.ctx, "libc_musl"))
}
return c.builtToolWithoutDeps(tool)
}
// builtToolWithoutDeps is similar to BuiltTool, but doesn't add any dependencies. It is used
// internally by RuleBuilder for helper tools that are known to be compiled statically.
func (c *RuleBuilderCommand) builtToolWithoutDeps(tool string) *RuleBuilderCommand {
return c.Tool(c.rule.ctx.Config().HostToolPath(c.rule.ctx, tool))
}