Support mixed building for cc_prebuilt_binary
Enable cc_prebuilt_binary to also take part in mixed builds. Bug: 241415823 Test: TestPrebuiltBinaryWithBazel Test: mixed_droid yields stats-log-api-gen under bazel-out/ Change-Id: I18b2906c91ea90370ab851a1287c2890546d633f
This commit is contained in:
parent
b12ff59f0b
commit
256e3b4597
@@ -674,9 +674,15 @@ func PrebuiltBinaryFactory() android.Module {
|
|||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type prebuiltBinaryBazelHandler struct {
|
||||||
|
module *Module
|
||||||
|
decorator *binaryDecorator
|
||||||
|
}
|
||||||
|
|
||||||
func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
||||||
module, binary := newBinary(hod, false)
|
module, binary := newBinary(hod, true)
|
||||||
module.compiler = nil
|
module.compiler = nil
|
||||||
|
module.bazelHandler = &prebuiltBinaryBazelHandler{module, binary}
|
||||||
|
|
||||||
prebuilt := &prebuiltBinaryLinker{
|
prebuilt := &prebuiltBinaryLinker{
|
||||||
binaryDecorator: binary,
|
binaryDecorator: binary,
|
||||||
@@ -690,6 +696,29 @@ func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecor
|
|||||||
return module, binary
|
return module, binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ BazelHandler = (*prebuiltBinaryBazelHandler)(nil)
|
||||||
|
|
||||||
|
func (h *prebuiltBinaryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||||
|
bazelCtx := ctx.Config().BazelContext
|
||||||
|
bazelCtx.QueueBazelRequest(label, cquery.GetOutputFiles, android.GetConfigKey(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *prebuiltBinaryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||||
|
bazelCtx := ctx.Config().BazelContext
|
||||||
|
outputs, err := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
|
||||||
|
if err != nil {
|
||||||
|
ctx.ModuleErrorf(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(outputs) != 1 {
|
||||||
|
ctx.ModuleErrorf("Expected a single output for `%s`, but got:\n%v", label, outputs)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out := android.PathForBazelOut(ctx, outputs[0])
|
||||||
|
h.module.outputFile = android.OptionalPathForPath(out)
|
||||||
|
h.module.maybeUnhideFromMake()
|
||||||
|
}
|
||||||
|
|
||||||
type bazelPrebuiltBinaryAttributes struct {
|
type bazelPrebuiltBinaryAttributes struct {
|
||||||
Src bazel.LabelAttribute
|
Src bazel.LabelAttribute
|
||||||
Strip stripAttributes
|
Strip stripAttributes
|
||||||
|
@@ -683,3 +683,27 @@ cc_prebuilt_binary {
|
|||||||
}`
|
}`
|
||||||
testCcError(t, `Android.bp:4:6: module "bintest" variant "android_arm64_armv8-a": srcs: multiple prebuilt source files`, bp)
|
testCcError(t, `Android.bp:4:6: module "bintest" variant "android_arm64_armv8-a": srcs: multiple prebuilt source files`, bp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltBinaryWithBazel(t *testing.T) {
|
||||||
|
const bp = `
|
||||||
|
cc_prebuilt_binary {
|
||||||
|
name: "bintest",
|
||||||
|
srcs: ["bin"],
|
||||||
|
bazel_module: { label: "//bin/foo:foo" },
|
||||||
|
}`
|
||||||
|
const outBaseDir = "outputbase"
|
||||||
|
const expectedOut = outBaseDir + "/execroot/__main__/bin"
|
||||||
|
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||||
|
config.BazelContext = android.MockBazelContext{
|
||||||
|
OutputBaseDir: outBaseDir,
|
||||||
|
LabelToOutputFiles: map[string][]string{"//bin/foo:foo": []string{"bin"}},
|
||||||
|
}
|
||||||
|
ctx := testCcWithConfig(t, config)
|
||||||
|
bin := ctx.ModuleForTests("bintest", "android_arm64_armv8-a").Module().(*Module)
|
||||||
|
out := bin.OutputFile()
|
||||||
|
if !out.Valid() {
|
||||||
|
t.Error("Invalid output file")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
android.AssertStringEquals(t, "output file", expectedOut, out.String())
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user