From c49649c059ffa80433f7789250363728ce1f1608 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 1 Oct 2020 21:25:05 -0700 Subject: Use protobuf-codegen default and add mod_stem.rs * Upgrade to new protobuf-codegen; use its standard default output without local change. * Allow a sourceProvider to have multiple output files. For a stem.proto file, output stem.rs and mod_stem.rs. * New protobuf-codegen option gen_mod_rs always generates output file named "mod.rs". To generate multiple .proto files into the same output directory, we need to rename mod.rs to mod_.rs. * Instead of using the gen_mod_rs option and renaming mod.rs to mod_.rs, we generate the same mod_.rs directly with a simple printf command. Bug: 170256643 Test: atest -c --host --include-subdirs external/crosvm Change-Id: Ia09e41029099a6de4d35c96dbabd9ba5514c9019 --- rust/protobuf.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'rust/protobuf.go') diff --git a/rust/protobuf.go b/rust/protobuf.go index 897300f19..ebb1c3cb6 100644 --- a/rust/protobuf.go +++ b/rust/protobuf.go @@ -61,15 +61,22 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) } outDir := android.PathForModuleOut(ctx) - depFile := android.PathForModuleOut(ctx, proto.BaseSourceProvider.getStem(ctx)+".d") - outputs := android.WritablePaths{android.PathForModuleOut(ctx, proto.BaseSourceProvider.getStem(ctx)+".rs")} + stem := proto.BaseSourceProvider.getStem(ctx) + // rust protobuf-codegen output .rs + stemFile := android.PathForModuleOut(ctx, stem+".rs") + // add mod_.rs to import .rs + modFile := android.PathForModuleOut(ctx, "mod_"+stem+".rs") + // mod_.rs is the main/first output file to be included/compiled + outputs := android.WritablePaths{modFile, stemFile} + depFile := android.PathForModuleOut(ctx, "mod_"+stem+".d") rule := android.NewRuleBuilder() android.ProtoRule(ctx, rule, protoFile.Path(), protoFlags, protoFlags.Deps, outDir, depFile, outputs) + rule.Command().Text("printf '// @generated\\npub mod %s;\\n' '" + stem + "' >").Output(modFile) rule.Build(pctx, ctx, "protoc_"+protoFile.Path().Rel(), "protoc "+protoFile.Path().Rel()) - proto.BaseSourceProvider.OutputFile = outputs[0] - return outputs[0] + proto.BaseSourceProvider.OutputFiles = android.Paths{modFile, stemFile} + return modFile } func (proto *protobufDecorator) SourceProviderProps() []interface{} { -- cgit v1.2.3-59-g8ed1b