postprocessing.bzl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. Defines the postprocessing build rule for the Google Maps APIs.
  3. """
  4. def maps_assembly_pkg(name, srcs, language, visibility = None):
  5. """Target to build a post-processed ads-specific GAPIC assembly package.
  6. Explodes a GAPIC assembly package, runs language-specific post-processing, and repackages.
  7. This macro assumes srcs contains in a single input, namely a {{language}}_assembly_pkg target
  8. produced by a gapic-generator build target.
  9. There must be a corresponding postprocessing_{language}.sh script to invoke.
  10. Args:
  11. name: defines the name of the main target
  12. srcs: collection containing exactly 1 build target, namely a
  13. {{language}}_assembly_pkg target produced by gapic-generator
  14. language: the programming language to post-process
  15. (e.g., "java", "csharp", "php", etc.); there must be a matching
  16. post-processin script of the form `postprocessing_{language}.sh
  17. in this package
  18. visibility (optional): marco visibility setting;
  19. (see https://docs.bazel.build/versions/master/skylark/macros.html)
  20. """
  21. cmd = """
  22. set -eu
  23. tar xzf $(SRCS);
  24. $(location //google/maps:postprocessing_%s) %s;
  25. tar czf $@ %s
  26. """
  27. dir_name = _extract_path(srcs)
  28. native.genrule(
  29. name = name,
  30. srcs = srcs,
  31. outs = ["%s.tar.gz" % name],
  32. cmd = cmd % (language, dir_name, dir_name),
  33. tools = ["//google/maps:postprocessing_%s" % language],
  34. visibility = visibility,
  35. )
  36. def _extract_path(srcs):
  37. """Takes the first label in srcs and returns its target name.
  38. Args:
  39. srcs: a collection of build labels of the form "//package/name:target"
  40. Returns:
  41. The first element's target (i.e.- the part after the ":"), else None if empty.
  42. """
  43. for s in srcs:
  44. toks = s.split(":")
  45. if len(toks) == 2:
  46. return toks[1]
  47. return None