proto.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2017 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package python
  15. import (
  16. "android/soong/android"
  17. )
  18. func genProto(ctx android.ModuleContext, protoFile android.Path, flags android.ProtoFlags) android.Path {
  19. srcsZipFile := android.PathForModuleGen(ctx, protoFile.Base()+".srcszip")
  20. outDir := srcsZipFile.ReplaceExtension(ctx, "tmp")
  21. depFile := srcsZipFile.ReplaceExtension(ctx, "srcszip.d")
  22. rule := android.NewRuleBuilder(pctx, ctx)
  23. rule.Command().Text("rm -rf").Flag(outDir.String())
  24. rule.Command().Text("mkdir -p").Flag(outDir.String())
  25. android.ProtoRule(rule, protoFile, flags, flags.Deps, outDir, depFile, nil)
  26. // Proto generated python files have an unknown package name in the path, so package the entire output directory
  27. // into a srcszip.
  28. zipCmd := rule.Command().
  29. BuiltTool("soong_zip").
  30. FlagWithOutput("-o ", srcsZipFile)
  31. zipCmd.FlagWithArg("-C ", outDir.String()).
  32. FlagWithArg("-D ", outDir.String())
  33. rule.Command().Text("rm -rf").Flag(outDir.String())
  34. rule.Build("protoc_"+protoFile.Rel(), "protoc "+protoFile.Rel())
  35. return srcsZipFile
  36. }