diff options
author | 2024-04-23 10:47:00 -0700 | |
---|---|---|
committer | 2024-04-23 10:47:00 -0700 | |
commit | f526863a408d5b020fecd29ce59dbb210f6fd812 (patch) | |
tree | 7d269684af97e6e4bab5dd4c7ccbbedb8484c175 /rust/protobuf.go | |
parent | a17792e2eb2bfaa232f0f791907edee52c3eca2a (diff) |
Shard rust protobuf sources
Shorten the command line for generating rust protobuf sources
by sharding the sources into groups of 50 source files.
Bug: 322564768
Bug: 336323108
Test: builds
Change-Id: Ia8069cdaf49f9a42d14a83139545ba61277418e0
Diffstat (limited to 'rust/protobuf.go')
-rw-r--r-- | rust/protobuf.go | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/rust/protobuf.go b/rust/protobuf.go index 0b26b80fa..fab5259a5 100644 --- a/rust/protobuf.go +++ b/rust/protobuf.go @@ -16,6 +16,7 @@ package rust import ( "fmt" + "strconv" "strings" "android/soong/android" @@ -122,41 +123,65 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) // stemFile must be first here as the first path in BaseSourceProvider.OutputFiles is the library entry-point. var outputs android.WritablePaths - rule := android.NewRuleBuilder(pctx, ctx) + for i, shard := range android.ShardPaths(protoFiles, 50) { + rule := android.NewRuleBuilder(pctx, ctx) - for _, protoFile := range protoFiles { - // Since we're iterating over the protoFiles already, make sure they're not redeclared in grpcFiles - if android.InList(protoFile.String(), grpcFiles.Strings()) { - ctx.PropertyErrorf("protos", - "A proto can only be added once to either grpc_protos or protos. %q is declared in both properties", - protoFile.String()) - } + for _, protoFile := range shard { + // Since we're iterating over the protoFiles already, make sure they're not redeclared in grpcFiles + if android.InList(protoFile.String(), grpcFiles.Strings()) { + ctx.PropertyErrorf("protos", + "A proto can only be added once to either grpc_protos or protos. %q is declared in both properties", + protoFile.String()) + } + + protoName := strings.TrimSuffix(protoFile.Base(), ".proto") + proto.protoNames = append(proto.protoNames, protoName) + + protoOut := android.PathForModuleOut(ctx, protoName+".rs") + depFile := android.PathForModuleOut(ctx, protoName+".d") - protoName := strings.TrimSuffix(protoFile.Base(), ".proto") - proto.protoNames = append(proto.protoNames, protoName) + ruleOutputs := android.WritablePaths{protoOut, depFile} - protoOut := android.PathForModuleOut(ctx, protoName+".rs") - depFile := android.PathForModuleOut(ctx, protoName+".d") + android.ProtoRule(rule, protoFile, protoFlags, protoFlags.Deps, outDir, depFile, ruleOutputs) + outputs = append(outputs, ruleOutputs...) + } - ruleOutputs := android.WritablePaths{protoOut, depFile} + ruleName := "protoc" + ruleDesc := "protoc" + if i > 0 { + ruleName += "_" + strconv.Itoa(i+1) + ruleDesc += " " + strconv.Itoa(i+1) + } - android.ProtoRule(rule, protoFile, protoFlags, protoFlags.Deps, outDir, depFile, ruleOutputs) - outputs = append(outputs, ruleOutputs...) + rule.Build(ruleName, ruleDesc) } - for _, grpcFile := range grpcFiles { - grpcName := strings.TrimSuffix(grpcFile.Base(), ".proto") - proto.grpcNames = append(proto.grpcNames, grpcName) + for i, shard := range android.ShardPaths(grpcFiles, 50) { + rule := android.NewRuleBuilder(pctx, ctx) + + for _, grpcFile := range shard { + grpcName := strings.TrimSuffix(grpcFile.Base(), ".proto") + proto.grpcNames = append(proto.grpcNames, grpcName) - // GRPC protos produce two files, a proto.rs and a proto_grpc.rs - protoOut := android.WritablePath(android.PathForModuleOut(ctx, grpcName+".rs")) - grpcOut := android.WritablePath(android.PathForModuleOut(ctx, grpcName+grpcSuffix+".rs")) - depFile := android.PathForModuleOut(ctx, grpcName+".d") + // GRPC protos produce two files, a proto.rs and a proto_grpc.rs + protoOut := android.WritablePath(android.PathForModuleOut(ctx, grpcName+".rs")) + grpcOut := android.WritablePath(android.PathForModuleOut(ctx, grpcName+grpcSuffix+".rs")) + depFile := android.PathForModuleOut(ctx, grpcName+".d") - ruleOutputs := android.WritablePaths{protoOut, grpcOut, depFile} + ruleOutputs := android.WritablePaths{protoOut, grpcOut, depFile} - android.ProtoRule(rule, grpcFile, grpcProtoFlags, grpcProtoFlags.Deps, outDir, depFile, ruleOutputs) - outputs = append(outputs, ruleOutputs...) + android.ProtoRule(rule, grpcFile, grpcProtoFlags, grpcProtoFlags.Deps, outDir, depFile, ruleOutputs) + outputs = append(outputs, ruleOutputs...) + } + + ruleName := "protoc_grpc" + ruleDesc := "protoc grpc" + if i > 0 { + ruleName += "_" + strconv.Itoa(i+1) + ruleDesc += " " + strconv.Itoa(i+1) + } + + rule.Build(ruleName, ruleDesc) } // Check that all proto base filenames are unique as outputs are written to the same directory. @@ -168,8 +193,6 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) android.WriteFileRule(ctx, stemFile, proto.genModFileContents()) - rule.Build("protoc_"+ctx.ModuleName(), "protoc "+ctx.ModuleName()) - // stemFile must be first here as the first path in BaseSourceProvider.OutputFiles is the library entry-point. proto.BaseSourceProvider.OutputFiles = append(android.Paths{stemFile}, outputs.Paths()...) |