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