1# Copyright (C) 2022 The Android Open Source Project 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 15# A collection of utilities for extracting build rule information from GN 16# projects. 17 18import copy 19import json 20import logging as log 21import os 22import re 23import collections 24 25LINKER_UNIT_TYPES = ('executable', 'shared_library', 'static_library', 'source_set') 26# This is a list of java files that should not be collected 27# as they don't exist right now downstream (eg: apihelpers, cronetEngineBuilderTest). 28# This is temporary solution until they are up-streamed. 29JAVA_FILES_TO_IGNORE = ( 30 "//components/cronet/android/api/src/org/chromium/net/apihelpers/ByteArrayCronetCallback.java", 31 "//components/cronet/android/api/src/org/chromium/net/apihelpers/ContentTypeParametersParser.java", 32 "//components/cronet/android/api/src/org/chromium/net/apihelpers/CronetRequestCompletionListener.java", 33 "//components/cronet/android/api/src/org/chromium/net/apihelpers/CronetResponse.java", 34 "//components/cronet/android/api/src/org/chromium/net/apihelpers/ImplicitFlowControlCallback.java", 35 "//components/cronet/android/api/src/org/chromium/net/apihelpers/InMemoryTransformCronetCallback.java", 36 "//components/cronet/android/api/src/org/chromium/net/apihelpers/JsonCronetCallback.java", 37 "//components/cronet/android/api/src/org/chromium/net/apihelpers/RedirectHandler.java", 38 "//components/cronet/android/api/src/org/chromium/net/apihelpers/RedirectHandlers.java", 39 "//components/cronet/android/api/src/org/chromium/net/apihelpers/StringCronetCallback.java", 40 "//components/cronet/android/api/src/org/chromium/net/apihelpers/UrlRequestCallbacks.java", 41 "//components/cronet/android/test/javatests/src/org/chromium/net/CronetEngineBuilderTest.java", 42 # Api helpers does not exist downstream, hence the tests shouldn't be collected. 43 "//components/cronet/android/test/javatests/src/org/chromium/net/apihelpers/ContentTypeParametersParserTest.java", 44 # androidx-multidex is disabled on unbundled branches. 45 "//base/test/android/java/src/org/chromium/base/multidex/ChromiumMultiDexInstaller.java", 46 # This file is not used in aosp and depends on newer accessibility_test_framework. 47 "//base/test/android/javatests/src/org/chromium/base/test/BaseActivityTestRule.java", 48) 49RESPONSE_FILE = '{{response_file_name}}' 50TESTING_SUFFIX = "__testing" 51AIDL_INCLUDE_DIRS_REGEX = r'--includes=\[(.*)\]' 52AIDL_IMPORT_DIRS_REGEX = r'--imports=\[(.*)\]' 53PROTO_IMPORT_DIRS_REGEX = r'--import-dir=(.*)' 54 55def repo_root(): 56 """Returns an absolute path to the repository root.""" 57 return os.path.join( 58 os.path.realpath(os.path.dirname(__file__)), os.path.pardir) 59 60def _get_build_path_from_label(target_name: str) -> str: 61 """Returns the path to the BUILD file for which this target was declared.""" 62 return target_name[2:].split(":")[0] 63 64def _clean_string(str): 65 return str.replace('\\', '').replace('../../', '').replace('"', '').strip() 66 67def _clean_aidl_import(orig_str): 68 str = _clean_string(orig_str) 69 src_idx = str.find("src/") 70 if src_idx == -1: 71 raise ValueError(f"Unable to clean aidl import {orig_str}") 72 return str[:src_idx + len("src")] 73 74def _extract_includes_from_aidl_args(args): 75 ret = [] 76 for arg in args: 77 is_match = re.match(AIDL_INCLUDE_DIRS_REGEX, arg) 78 if is_match: 79 local_includes = is_match.group(1).split(",") 80 ret += [_clean_string(local_include) for local_include in local_includes] 81 # Treat imports like include for aidl by removing the package suffix. 82 is_match = re.match(AIDL_IMPORT_DIRS_REGEX, arg) 83 if is_match: 84 local_imports = is_match.group(1).split(",") 85 # Skip "third_party/android_sdk/public/platforms/android-34/framework.aidl" because Soong 86 # already links against the AIDL framework implicitly. 87 ret += [_clean_aidl_import(local_import) for local_import in local_imports 88 if "framework.aidl" not in local_import] 89 return ret 90 91def contains_aidl(sources): 92 return any([src.endswith(".aidl") for src in sources]) 93 94def _get_jni_registration_deps(gn_target_name, gn_desc): 95 # the dependencies are stored within another target with the same name 96 # and a __java_sources suffix, see 97 # https://source.chromium.org/chromium/chromium/src/+/main:third_party/jni_zero/jni_zero.gni;l=117;drc=78e8e27142ed3fddf04fbcd122507517a87cb9ad 98 # for the auto-generated target name. 99 jni_registration_java_target = f'{gn_target_name}__java_sources' 100 if jni_registration_java_target in gn_desc.keys(): 101 return gn_desc[jni_registration_java_target]["deps"] 102 return set() 103 104def label_to_path(label): 105 """Turn a GN output label (e.g., //some_dir/file.cc) into a path.""" 106 assert label.startswith('//') 107 return label[2:] or "" 108 109def label_without_toolchain(label): 110 """Strips the toolchain from a GN label. 111 112 Return a GN label (e.g //buildtools:protobuf(//gn/standalone/toolchain: 113 gcc_like_host) without the parenthesised toolchain part. 114 """ 115 return label.split('(')[0] 116 117 118def _is_java_source(src): 119 return os.path.splitext(src)[1] == '.java' and not src.startswith("//out/") 120 121 122class GnParser(object): 123 """A parser with some cleverness for GN json desc files 124 125 The main goals of this parser are: 126 1) Deal with the fact that other build systems don't have an equivalent 127 notion to GN's source_set. Conversely to Bazel's and Soong's filegroups, 128 GN source_sets expect that dependencies, cflags and other source_set 129 properties propagate up to the linker unit (static_library, executable or 130 shared_library). This parser simulates the same behavior: when a 131 source_set is encountered, some of its variables (cflags and such) are 132 copied up to the dependent targets. This is to allow gen_xxx to create 133 one filegroup for each source_set and then squash all the other flags 134 onto the linker unit. 135 2) Detect and special-case protobuf targets, figuring out the protoc-plugin 136 being used. 137 """ 138 139 class Target(object): 140 """Reperesents A GN target. 141 142 Maked properties are propagated up the dependency chain when a 143 source_set dependency is encountered. 144 """ 145 class Arch(): 146 """Architecture-dependent properties 147 """ 148 def __init__(self): 149 self.sources = set() 150 self.cflags = set() 151 self.defines = set() 152 self.include_dirs = set() 153 self.deps = set() 154 self.transitive_static_libs_deps = set() 155 self.ldflags = set() 156 157 # These are valid only for type == 'action' 158 self.inputs = set() 159 self.outputs = set() 160 self.args = [] 161 self.response_file_contents = '' 162 self.rust_flags = list() 163 164 def __init__(self, name, type): 165 self.name = name # e.g. //src/ipc:ipc 166 167 VALID_TYPES = ('static_library', 'shared_library', 'executable', 'group', 168 'action', 'source_set', 'proto_library', 'copy', 169 'action_foreach', 'generated_file', "rust_library", "rust_proc_macro") 170 assert (type in VALID_TYPES), f"Unable to parse target {name} with type {type}." 171 self.type = type 172 self.testonly = False 173 self.toolchain = None 174 175 # These are valid only for type == proto_library. 176 # This is typically: 'proto', 'protozero', 'ipc'. 177 self.proto_plugin = None 178 self.proto_paths = set() 179 self.proto_exports = set() 180 self.proto_in_dir = "" 181 182 # TODO(primiano): consider whether the public section should be part of 183 # bubbled-up sources. 184 self.public_headers = set() # 'public' 185 186 # These are valid only for type == 'action' 187 self.script = '' 188 189 # These variables are propagated up when encountering a dependency 190 # on a source_set target. 191 self.libs = set() 192 self.proto_deps = set() 193 self.rtti = False 194 195 # TODO: come up with a better way to only run this once. 196 # is_finalized tracks whether finalize() was called on this target. 197 self.is_finalized = False 198 # 'common' is a pseudo-architecture used to store common architecture dependent properties (to 199 # make handling of common vs architecture-specific arguments more consistent). 200 self.arch = {'common': self.Arch()} 201 202 # This is used to get the name/version of libcronet 203 self.output_name = None 204 # Local Includes used for AIDL 205 self.local_aidl_includes = set() 206 # Each java_target will contain the transitive java sources found 207 # in generate_jni type target. 208 self.transitive_jni_java_sources = set() 209 # Deps for JNI Registration. Those are not added to deps so that 210 # the generated module would not depend on those deps. 211 self.jni_registration_java_deps = set() 212 # Path to the java jar path. This is used if the java library is 213 # an import of a JAR like `android_java_prebuilt` targets in GN 214 self.jar_path = "" 215 self.sdk_version = "" 216 self.build_file_path = "" 217 self.crate_name = None 218 self.crate_root = None 219 220 # Properties to forward access to common arch. 221 # TODO: delete these after the transition has been completed. 222 @property 223 def sources(self): 224 return self.arch['common'].sources 225 226 @sources.setter 227 def sources(self, val): 228 self.arch['common'].sources = val 229 230 @property 231 def inputs(self): 232 return self.arch['common'].inputs 233 234 @inputs.setter 235 def inputs(self, val): 236 self.arch['common'].inputs = val 237 238 @property 239 def outputs(self): 240 return self.arch['common'].outputs 241 242 @outputs.setter 243 def outputs(self, val): 244 self.arch['common'].outputs = val 245 246 @property 247 def args(self): 248 return self.arch['common'].args 249 250 @args.setter 251 def args(self, val): 252 self.arch['common'].args = val 253 254 @property 255 def response_file_contents(self): 256 return self.arch['common'].response_file_contents 257 258 @response_file_contents.setter 259 def response_file_contents(self, val): 260 self.arch['common'].response_file_contents = val 261 262 @property 263 def cflags(self): 264 return self.arch['common'].cflags 265 266 @property 267 def defines(self): 268 return self.arch['common'].defines 269 270 @property 271 def deps(self): 272 return self.arch['common'].deps 273 274 @deps.setter 275 def deps(self, val): 276 self.arch['common'].deps = val 277 278 @property 279 def rust_flags(self): 280 return self.arch['common'].rust_flags 281 282 @rust_flags.setter 283 def rust_flags(self, val): 284 self.arch['common'].rust_flags = val 285 286 @property 287 def include_dirs(self): 288 return self.arch['common'].include_dirs 289 290 @property 291 def ldflags(self): 292 return self.arch['common'].ldflags 293 294 def host_supported(self): 295 return 'host' in self.arch 296 297 def device_supported(self): 298 return any([name.startswith('android') for name in self.arch.keys()]) 299 300 def is_linker_unit_type(self): 301 return self.type in LINKER_UNIT_TYPES 302 303 def __lt__(self, other): 304 if isinstance(other, self.__class__): 305 return self.name < other.name 306 raise TypeError( 307 '\'<\' not supported between instances of \'%s\' and \'%s\'' % 308 (type(self).__name__, type(other).__name__)) 309 310 def __repr__(self): 311 return json.dumps({ 312 k: (list(sorted(v)) if isinstance(v, set) else v) 313 for (k, v) in self.__dict__.items() 314 }, 315 indent=4, 316 sort_keys=True) 317 318 def update(self, other, arch): 319 for key in ('cflags', 'defines', 'deps', 'include_dirs', 'ldflags', 320 'proto_deps', 'libs', 'proto_paths'): 321 getattr(self, key).update(getattr(other, key, [])) 322 323 for key_in_arch in ('cflags', 'defines', 'include_dirs', 'deps', 'ldflags'): 324 getattr(self.arch[arch], key_in_arch).update(getattr(other.arch[arch], key_in_arch, [])) 325 326 def get_archs(self): 327 """ Returns a dict of archs without the common arch """ 328 return {arch: val for arch, val in self.arch.items() if arch != 'common'} 329 330 def _finalize_set_attribute(self, key): 331 # Target contains the intersection of arch-dependent properties 332 getattr(self, key).update(set.intersection(*[getattr(arch, key) for arch in 333 self.get_archs().values()])) 334 335 # Deduplicate arch-dependent properties 336 for arch in self.get_archs().values(): 337 getattr(arch, key).difference_update(getattr(self, key)) 338 339 def _finalize_non_set_attribute(self, key): 340 # Only when all the arch has the same non empty value, move the value to the target common 341 val = getattr(list(self.get_archs().values())[0], key) 342 if val and all([val == getattr(arch, key) for arch in self.get_archs().values()]): 343 setattr(self, key, copy.deepcopy(val)) 344 345 def _finalize_attribute(self, key): 346 val = getattr(self, key) 347 if isinstance(val, set): 348 self._finalize_set_attribute(key) 349 elif isinstance(val, (list, str)): 350 self._finalize_non_set_attribute(key) 351 else: 352 raise TypeError(f'Unsupported type: {type(val)}') 353 354 def finalize(self): 355 """Move common properties out of arch-dependent subobjects to Target object. 356 357 TODO: find a better name for this function. 358 """ 359 if self.is_finalized: 360 return 361 self.is_finalized = True 362 363 if len(self.arch) == 1: 364 return 365 366 for key in ('sources', 'cflags', 'defines', 'include_dirs', 'deps', 367 'inputs', 'outputs', 'args', 'response_file_contents', 'ldflags', 'rust_flags'): 368 self._finalize_attribute(key) 369 370 def get_target_name(self): 371 return self.name[self.name.find(":") + 1:] 372 373 374 def __init__(self, builtin_deps, build_script_outputs): 375 self.builtin_deps = builtin_deps 376 self.build_script_outputs = build_script_outputs 377 self.all_targets = {} 378 self.jni_java_sources = set() 379 380 381 def _get_response_file_contents(self, action_desc): 382 # response_file_contents are formatted as: 383 # ['--flags', '--flag=true && false'] and need to be formatted as: 384 # '--flags --flag=\"true && false\"' 385 flags = action_desc.get('response_file_contents', []) 386 formatted_flags = [] 387 for flag in flags: 388 if '=' in flag: 389 key, val = flag.split('=') 390 formatted_flags.append('%s=\\"%s\\"' % (key, val)) 391 else: 392 formatted_flags.append(flag) 393 394 return ' '.join(formatted_flags) 395 396 def _is_java_group(self, type_, target_name): 397 # Per https://chromium.googlesource.com/chromium/src/build/+/HEAD/android/docs/java_toolchain.md 398 # java target names must end in "_java". 399 # TODO: There are some other possible variations we might need to support. 400 return type_ == 'group' and target_name.endswith('_java') 401 402 def _get_arch(self, toolchain): 403 if toolchain == '//build/toolchain/android:android_clang_x86': 404 return 'android_x86', 'x86' 405 elif toolchain == '//build/toolchain/android:android_clang_x64': 406 return 'android_x86_64', 'x64' 407 elif toolchain == '//build/toolchain/android:android_clang_arm': 408 return 'android_arm', 'arm' 409 elif toolchain == '//build/toolchain/android:android_clang_arm64': 410 return 'android_arm64', 'arm64' 411 elif toolchain == '//build/toolchain/android:android_clang_riscv64': 412 return 'android_riscv64', 'riscv64' 413 else: 414 return 'host', 'host' 415 416 def get_target(self, gn_target_name): 417 """Returns a Target object from the fully qualified GN target name. 418 419 get_target() requires that parse_gn_desc() has already been called. 420 """ 421 # Run this every time as parse_gn_desc can be called at any time. 422 for target in self.all_targets.values(): 423 target.finalize() 424 425 return self.all_targets[label_without_toolchain(gn_target_name)] 426 427 def parse_gn_desc(self, gn_desc, gn_target_name, java_group_name=None, is_test_target=False): 428 """Parses a gn desc tree and resolves all target dependencies. 429 430 It bubbles up variables from source_set dependencies as described in the 431 class-level comments. 432 """ 433 # Use name without toolchain for targets to support targets built for 434 # multiple archs. 435 target_name = label_without_toolchain(gn_target_name) 436 desc = gn_desc[gn_target_name] 437 type_ = desc['type'] 438 arch, chromium_arch = self._get_arch(desc['toolchain']) 439 metadata = desc.get("metadata", {}) 440 441 if is_test_target: 442 target_name += TESTING_SUFFIX 443 444 target = self.all_targets.get(target_name) 445 if target is None: 446 target = GnParser.Target(target_name, type_) 447 self.all_targets[target_name] = target 448 449 if arch not in target.arch: 450 target.arch[arch] = GnParser.Target.Arch() 451 else: 452 return target # Target already processed. 453 454 if 'target_type' in metadata.keys() and metadata["target_type"][0] == 'java_library': 455 target.type = 'java_library' 456 457 if target.name in self.builtin_deps: 458 # return early, no need to parse any further as the module is a builtin. 459 return target 460 461 if (target_name.startswith("//build/rust/std") or 462 desc.get("crate_name", "").endswith("_build_script")): 463 # We intentionally don't parse build/rust/std as we use AOSP's stdlib. 464 # Don't parse build_script as we can't execute them in AOSP, we use a different 465 # source of truth. 466 return target 467 468 target.testonly = desc.get('testonly', False) 469 470 deps = desc.get("deps", {}) 471 if desc.get("script", "") == "//tools/protoc_wrapper/protoc_wrapper.py": 472 target.type = 'proto_library' 473 target.proto_plugin = "proto" 474 target.proto_paths.update(self.get_proto_paths(desc)) 475 target.proto_exports.update(self.get_proto_exports(desc)) 476 target.proto_in_dir = self.get_proto_in_dir(desc) 477 target.arch[arch].sources.update(desc.get('sources', [])) 478 target.arch[arch].inputs.update(desc.get('inputs', [])) 479 elif target.type == 'source_set': 480 target.arch[arch].sources.update(source for source in desc.get('sources', []) if not source.startswith("//out")) 481 elif target.type == "rust_executable": 482 target.arch[arch].sources.update(source for source in desc.get('sources', []) if not source.startswith("//out")) 483 elif target.is_linker_unit_type(): 484 target.arch[arch].sources.update(source for source in desc.get('sources', []) if not source.startswith("//out")) 485 elif target.type == 'java_library': 486 sources = set() 487 for java_source in metadata.get("source_files", []): 488 if not java_source.startswith("//out") and java_source not in JAVA_FILES_TO_IGNORE: 489 sources.add(java_source) 490 target.sources.update(sources) 491 # Metadata attributes must be list, for jar_path, it is always a list 492 # of size one, the first element is an empty string if `jar_path` is not 493 # defined otherwise it is a path. 494 if metadata.get("jar_path", [""])[0]: 495 target.jar_path = label_to_path(metadata["jar_path"][0]) 496 target.sdk_version = metadata.get('sdk_version', ['current'])[0] 497 deps = metadata.get("all_deps", {}) 498 log.info('Found Java Target %s', target.name) 499 elif target.script == "//build/android/gyp/aidl.py": 500 target.type = "java_library" 501 target.sources.update(desc.get('sources', {})) 502 target.local_aidl_includes = _extract_includes_from_aidl_args(desc.get('args', '')) 503 elif target.type in ['action', 'action_foreach']: 504 target.arch[arch].inputs.update(desc.get('inputs', [])) 505 target.arch[arch].sources.update(desc.get('sources', [])) 506 outs = [re.sub('^//out/.+?/gen/', '', x) for x in desc['outputs']] 507 target.arch[arch].outputs.update(outs) 508 # While the arguments might differ, an action should always use the same script for every 509 # architecture. (gen_android_bp's get_action_sanitizer actually relies on this fact. 510 target.script = desc['script'] 511 target.arch[arch].args = desc['args'] 512 target.arch[arch].response_file_contents = self._get_response_file_contents(desc) 513 # _get_jni_registration_deps will return the dependencies of a target if 514 # the target is of type `generate_jni_registration` otherwise it will 515 # return an empty set. 516 target.jni_registration_java_deps.update(_get_jni_registration_deps(gn_target_name, gn_desc)) 517 # JNI java sources are embedded as metadata inside `jni_headers` targets. 518 # See https://source.chromium.org/chromium/chromium/src/+/main:third_party/jni_zero/jni_zero.gni;l=421;drc=78e8e27142ed3fddf04fbcd122507517a87cb9ad 519 # for more details 520 target.transitive_jni_java_sources.update(metadata.get("jni_source_files_abs", set())) 521 self.jni_java_sources.update(metadata.get("jni_source_files_abs", set())) 522 elif target.type == 'copy': 523 # TODO: copy rules are not currently implemented. 524 pass 525 elif target.type == 'group': 526 # Groups are bubbled upward without creating an equivalent GN target. 527 pass 528 elif target.type in ["rust_library", "rust_proc_macro"]: 529 target.arch[arch].sources.update(source for source in desc.get('sources', []) if not source.startswith("//out")) 530 else: 531 raise Exception(f"Encountered GN target with unknown type\nCulprit target: {gn_target_name}\ntype: {target.type}") 532 533 # Default for 'public' is //* - all headers in 'sources' are public. 534 # TODO(primiano): if a 'public' section is specified (even if empty), then 535 # the rest of 'sources' is considered inaccessible by gn. Consider 536 # emulating that, so that generated build files don't end up with overly 537 # accessible headers. 538 public_headers = [x for x in desc.get('public', []) if x != '*'] 539 target.public_headers.update(public_headers) 540 target.build_file_path = _get_build_path_from_label(target_name) 541 target.arch[arch].cflags.update(desc.get('cflags', []) + desc.get('cflags_cc', [])) 542 target.libs.update(desc.get('libs', [])) 543 target.arch[arch].ldflags.update(desc.get('ldflags', [])) 544 target.arch[arch].defines.update(desc.get('defines', [])) 545 target.arch[arch].include_dirs.update(desc.get('include_dirs', [])) 546 target.output_name = desc.get('output_name', None) 547 target.crate_name = desc.get("crate_name", None) 548 target.crate_root = desc.get("crate_root", None) 549 target.arch[arch].rust_flags = desc.get("rustflags", list()) 550 target.arch[arch].rust_flags.extend( 551 self.build_script_outputs 552 .get(label_without_toolchain(gn_target_name), {}) 553 .get(chromium_arch, list()) 554 ) 555 if target.type == "executable" and target.crate_root: 556 # Find a more decisive way to figure out that this is a rust executable. 557 # TODO: Add a metadata to the executable from Chromium side. 558 target.type = "rust_executable" 559 if "-frtti" in target.arch[arch].cflags: 560 target.rtti = True 561 562 for gn_dep_name in set(target.jni_registration_java_deps): 563 dep = self.parse_gn_desc(gn_desc, gn_dep_name, java_group_name, is_test_target) 564 target.transitive_jni_java_sources.update(dep.transitive_jni_java_sources) 565 566 # Recurse in dependencies. 567 for gn_dep_name in set(deps): 568 dep = self.parse_gn_desc(gn_desc, gn_dep_name, java_group_name, is_test_target) 569 570 if dep.type == 'proto_library': 571 target.proto_deps.add(dep.name) 572 elif dep.type == 'group': 573 target.update(dep, arch) # Bubble up groups's cflags/ldflags etc. 574 target.transitive_jni_java_sources.update(dep.transitive_jni_java_sources) 575 elif dep.type in ['action', 'action_foreach', 'copy']: 576 target.arch[arch].deps.add(dep.name) 577 target.transitive_jni_java_sources.update(dep.transitive_jni_java_sources) 578 elif dep.is_linker_unit_type(): 579 target.arch[arch].deps.add(dep.name) 580 elif dep.type == "rust_executable": 581 target.arch[arch].deps.add(dep.name) 582 elif dep.type == 'java_library': 583 target.deps.add(dep.name) 584 target.transitive_jni_java_sources.update(dep.transitive_jni_java_sources) 585 elif dep.type in ['rust_binary', "rust_library", "rust_proc_macro"]: 586 target.arch[arch].deps.add(dep.name) 587 if dep.type in ['static_library', 'source_set']: 588 # Bubble up static_libs and source_set. Necessary, since soong does not propagate 589 # static_libs up the build tree. 590 # Source sets are later translated to static_libraries, so it makes sense 591 # to reuse transitive_static_libs_deps. 592 target.arch[arch].transitive_static_libs_deps.add(dep.name) 593 594 if arch in dep.arch: 595 target.arch[arch].transitive_static_libs_deps.update( 596 dep.arch[arch].transitive_static_libs_deps) 597 target.arch[arch].deps.update(target.arch[arch].transitive_static_libs_deps) 598 return target 599 600 def get_proto_exports(self, proto_desc): 601 # exports in metadata will be available for source_set targets. 602 metadata = proto_desc.get('metadata', {}) 603 return metadata.get('exports', []) 604 605 def get_proto_paths(self, proto_desc): 606 args = proto_desc.get('args') 607 proto_paths = set() 608 for arg in args: 609 is_match = re.match(PROTO_IMPORT_DIRS_REGEX, arg) 610 if is_match: 611 proto_paths.add(re.sub('^\.\./\.\./', '', is_match.group(1))) 612 return proto_paths 613 614 615 def get_proto_in_dir(self, proto_desc): 616 args = proto_desc.get('args') 617 return re.sub('^\.\./\.\./', '', args[args.index('--proto-in-dir') + 1]) 618