diff options
author | 2020-10-01 21:25:05 -0700 | |
---|---|---|
committer | 2020-10-09 13:38:37 -0700 | |
commit | c49649c059ffa80433f7789250363728ce1f1608 (patch) | |
tree | 341708b4379e07d8ee09396127a3e18ccee05f44 | |
parent | 6682ef42a497e5fdf48d0ade03efd23dbf8379dd (diff) |
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_<stem>.rs.
* Instead of using the gen_mod_rs option and renaming mod.rs
to mod_<stem>.rs, we generate the same mod_<stem>.rs
directly with a simple printf command.
Bug: 170256643
Test: atest -c --host --include-subdirs external/crosvm
Change-Id: Ia09e41029099a6de4d35c96dbabd9ba5514c9019
-rw-r--r-- | rust/androidmk.go | 2 | ||||
-rw-r--r-- | rust/bindgen.go | 2 | ||||
-rw-r--r-- | rust/protobuf.go | 15 | ||||
-rw-r--r-- | rust/rust.go | 2 | ||||
-rw-r--r-- | rust/source_provider.go | 10 |
5 files changed, 19 insertions, 12 deletions
diff --git a/rust/androidmk.go b/rust/androidmk.go index 5a33f77fa..29e4bd75b 100644 --- a/rust/androidmk.go +++ b/rust/androidmk.go @@ -156,7 +156,7 @@ func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *androi } func (sourceProvider *BaseSourceProvider) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { - outFile := sourceProvider.OutputFile + outFile := sourceProvider.OutputFiles[0] ret.Class = "ETC" ret.OutputFile = android.OptionalPathForPath(outFile) ret.SubName += sourceProvider.subName diff --git a/rust/bindgen.go b/rust/bindgen.go index ac33ff7ef..68f219e45 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -202,7 +202,7 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr }, }) - b.BaseSourceProvider.OutputFile = outputFile + b.BaseSourceProvider.OutputFiles = android.Paths{outputFile} return outputFile } 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 <stem>.rs + stemFile := android.PathForModuleOut(ctx, stem+".rs") + // add mod_<stem>.rs to import <stem>.rs + modFile := android.PathForModuleOut(ctx, "mod_"+stem+".rs") + // mod_<stem>.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{} { diff --git a/rust/rust.go b/rust/rust.go index ba8673c94..3f0f6e27d 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -709,7 +709,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { } else { sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) - mod.sourceProvider.setOutputFile(sourceLib.sourceProvider.Srcs()[0]) + mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) } } diff --git a/rust/source_provider.go b/rust/source_provider.go index 03adf9e6f..436518c70 100644 --- a/rust/source_provider.go +++ b/rust/source_provider.go @@ -30,7 +30,7 @@ type SourceProviderProperties struct { type BaseSourceProvider struct { Properties SourceProviderProperties - OutputFile android.Path + OutputFiles android.Paths subAndroidMkOnce map[SubAndroidMkProvider]bool subName string } @@ -43,11 +43,11 @@ type SourceProvider interface { SourceProviderProps() []interface{} SourceProviderDeps(ctx DepsContext, deps Deps) Deps setSubName(subName string) - setOutputFile(outputFile android.Path) + setOutputFiles(outputFiles android.Paths) } func (sp *BaseSourceProvider) Srcs() android.Paths { - return android.Paths{sp.OutputFile} + return sp.OutputFiles } func (sp *BaseSourceProvider) GenerateSource(ctx ModuleContext, deps PathDeps) android.Path { @@ -97,6 +97,6 @@ func (sp *BaseSourceProvider) setSubName(subName string) { sp.subName = subName } -func (sp *BaseSourceProvider) setOutputFile(outputFile android.Path) { - sp.OutputFile = outputFile +func (sp *BaseSourceProvider) setOutputFiles(outputFiles android.Paths) { + sp.OutputFiles = outputFiles } |