• Home
  • Raw
  • Download

Lines Matching refs:self

193   def __init__(self, runner, outf_name):  argument
195 self.runner = runner
196 self.debug = runner.args.debug
197 self.cargo_dir = '' # directory of my Cargo.toml
198 self.outf_name = outf_name # path to Android.bp
199 self.outf = None # open file handle of outf_name during dump*
201 self.host_supported = False
202 self.device_supported = False
203 self.has_warning = False
205 self.module_name = '' # unique in Android build system
206 self.module_type = '' # rust_{binary,library,test}[_host] etc.
207 self.defaults = '' # rust_defaults used by rust_test* modules
208 self.default_srcs = False # use 'srcs' defined in self.defaults
209 self.root_pkg = '' # parent package name of a sub/test packge, from -L
210 self.srcs = list() # main_src or merged multiple source files
211 self.stem = '' # real base name of output file
213 self.errors = '' # all errors found during parsing
214 self.line_num = 1 # runner told input source line number
215 self.line = '' # original rustc command line parameters
217 self.crate_name = '' # follows --crate-name
218 self.main_src = '' # follows crate_name parameter, shortened
219 self.crate_types = list() # follows --crate-type
220 self.cfgs = list() # follows --cfg, without feature= prefix
221 self.features = list() # follows --cfg, name in 'feature="..."'
222 self.codegens = list() # follows -C, some ignored
223 self.externs = list() # follows --extern
224 self.core_externs = list() # first part of self.externs elements
225 self.static_libs = list() # e.g. -l static=host_cpuid
226 self.shared_libs = list() # e.g. -l dylib=wayland-client, -l z
227 self.cap_lints = '' # follows --cap-lints
228 self.emit_list = '' # e.g., --emit=dep-info,metadata,link
229 self.edition = '2015' # rustc default, e.g., --edition=2018
230 self.target = '' # follows --target
232 def write(self, s): argument
234 self.outf.write(s + '\n')
236 def same_flags(self, other): argument
240 return (not self.errors and not other.errors and
241 self.edition == other.edition and
242 self.cap_lints == other.cap_lints and
243 self.emit_list == other.emit_list and
244 self.core_externs == other.core_externs and
245 self.codegens == other.codegens and
246 self.features == other.features and
247 self.static_libs == other.static_libs and
248 self.shared_libs == other.shared_libs and self.cfgs == other.cfgs)
250 def merge_host_device(self, other): argument
252 return (self.crate_name == other.crate_name and
253 self.crate_types == other.crate_types and
254 self.main_src == other.main_src and
256 (self.stem == other.stem or self.crate_types == ['test']) and
257 self.root_pkg == other.root_pkg and not self.skip_crate() and
258 self.same_flags(other))
260 def merge_test(self, other): argument
265 return (self.crate_types == other.crate_types and
266 self.crate_types == ['test'] and self.root_pkg == other.root_pkg and
267 not self.skip_crate() and
269 (len(self.srcs) > 1 or
270 (self.crate_name == test_base_name(self.main_src)) and
271 self.host_supported == other.host_supported and
272 self.device_supported == other.device_supported) and
273 self.same_flags(other))
275 def merge(self, other, outf_name): argument
280 should_merge_host_device = self.merge_host_device(other)
283 should_merge_test = self.merge_test(other)
285 self.runner.init_bp_file(outf_name)
287 self.outf = outf
289 self.do_merge(other, should_merge_test)
293 def do_merge(self, other, should_merge_test): argument
295 if self.debug:
296 self.write('\n// Before merge definition (1):')
297 self.dump_debug_info()
298 self.write('\n// Before merge definition (2):')
301 self.has_warning = self.has_warning or other.has_warning
302 if not self.target: # okay to keep only the first target triple
303 self.target = other.target
306 self.decide_module_type()
308 self.srcs.append(other.main_src)
310 prefix = self.root_pkg + '_tests'
311 self.module_name = self.runner.claim_module_name(prefix, self, 0)
312 self.stem = self.module_name
318 self.crate_name = pkg2crate_name(self.root_pkg)
319 if self.debug:
320 self.write('\n// After merge definition (1):')
321 self.dump_debug_info()
323 def find_cargo_dir(self): argument
325 if not is_dependent_file_path(self.main_src):
326 dir_name = os.path.dirname(self.main_src)
329 self.cargo_dir = dir_name
333 def add_codegens_flag(self, flag): argument
345 self.codegens.append(flag)
347 def parse(self, line_num, line): argument
349 self.line_num = line_num
350 self.line = line
357 self.crate_name = args[i]
363 self.crate_types.append(args[i])
365 self.crate_types.append('test')
368 self.target = args[i]
372 self.features.append(unquote(args[i].replace('\'feature=', '')[:-1]))
374 self.cfgs.append(args[i])
378 self.externs.append(extern_names)
379 self.core_externs.append(re.sub(' = .*', '', extern_names))
382 self.add_codegens_flag(args[i])
386 self.add_codegens_flag(arg[2:])
389 self.cap_lints = args[i]
394 self.root_pkg = re.sub(
397 self.root_pkg = re.sub('^.*/', '',
399 self.root_pkg = remove_version_suffix(self.root_pkg)
403 self.static_libs.append(re.sub('static=', '', args[i]))
405 self.shared_libs.append(re.sub('dylib=', '', args[i]))
407 self.shared_libs.append(args[i])
413 self.emit_list = arg.replace('--emit=', '')
415 self.edition = arg.replace('--edition=', '')
419 self.main_src = re.sub(r'^/[^ ]*/registry/src/', '.../', args[i])
420 self.main_src = re.sub(r'^\.\.\./github.com-[0-9a-f]*/', '.../',
421 self.main_src)
422 self.find_cargo_dir()
423 if self.cargo_dir: # for a subdirectory
424 if self.runner.args.no_subdir: # all .bp content to /dev/null
425 self.outf_name = '/dev/null'
426 elif not self.runner.args.onefile:
428 self.outf_name = self.cargo_dir + '/Android.bp'
429 self.main_src = self.main_src[len(self.cargo_dir) + 1:]
431 self.errors += 'ERROR: unknown ' + arg + '\n'
433 if not self.crate_name:
434 self.errors += 'ERROR: missing --crate-name\n'
435 if not self.main_src:
436 self.errors += 'ERROR: missing main source file\n'
438 self.srcs.append(self.main_src)
439 if not self.crate_types:
441 if 'test' in self.cfgs:
442 self.crate_types.append('test')
444 self.errors += 'ERROR: missing --crate-type or --test\n'
445 elif len(self.crate_types) > 1:
446 if 'test' in self.crate_types:
447 self.errors += 'ERROR: cannot handle both --crate-type and --test\n'
448 if 'lib' in self.crate_types and 'rlib' in self.crate_types:
449 self.errors += 'ERROR: cannot generate both lib and rlib crate types\n'
450 if not self.root_pkg:
451 self.root_pkg = self.crate_name
452 self.device_supported = self.runner.args.device
453 self.host_supported = not self.runner.args.no_host
454 self.cfgs = sorted(set(self.cfgs))
455 self.features = sorted(set(self.features))
456 self.codegens = sorted(set(self.codegens))
457 self.externs = sorted(set(self.externs))
458 self.core_externs = sorted(set(self.core_externs))
459 self.static_libs = sorted(set(self.static_libs))
460 self.shared_libs = sorted(set(self.shared_libs))
461 self.crate_types = sorted(set(self.crate_types))
462 self.decide_module_type()
463 self.module_name = altered_name(self.stem)
464 return self
466 def dump_line(self): argument
467 self.write('\n// Line ' + str(self.line_num) + ' ' + self.line)
469 def feature_list(self): argument
471 pkg = self.main_src
476 if not self.features:
478 return pkg + ' "' + ','.join(self.features) + '"'
480 def dump_skip_crate(self, kind): argument
481 if self.debug:
482 self.write('\n// IGNORED: ' + kind + ' ' + self.main_src)
483 return self
485 def skip_crate(self): argument
487 if (is_build_crate_name(self.crate_name) or
488 self.crate_name in EXCLUDED_CRATES):
489 return self.crate_name
490 if is_dependent_file_path(self.main_src):
494 def dump(self): argument
496 self.runner.init_bp_file(self.outf_name)
497 with open(self.outf_name, 'a') as outf:
498 self.outf = outf
499 if self.errors:
500 self.dump_line()
501 self.write(self.errors)
502 elif self.skip_crate():
503 self.dump_skip_crate(self.skip_crate())
505 if self.debug:
506 self.dump_debug_info()
507 self.dump_android_module()
509 def dump_debug_info(self): argument
513 self.write('//%12s = %s' % (name, value))
521 self.write(fmt % v)
523 self.dump_line()
524 dump('module_name', self.module_name)
525 dump('crate_name', self.crate_name)
526 dump('crate_types', self.crate_types)
527 dump('main_src', self.main_src)
528 dump('has_warning', self.has_warning)
529 dump('for_host', self.host_supported)
530 dump('for_device', self.device_supported)
531 dump('module_type', self.module_type)
532 opt_dump('target', self.target)
533 opt_dump('edition', self.edition)
534 opt_dump('emit_list', self.emit_list)
535 opt_dump('cap_lints', self.cap_lints)
536 dump_list('// cfg = %s', self.cfgs)
537 dump_list('// cfg = \'feature "%s"\'', self.features)
539 dump_list('// codegen = %s', self.codegens)
540 dump_list('// externs = %s', self.externs)
541 dump_list('// -l static = %s', self.static_libs)
542 dump_list('// -l (dylib) = %s', self.shared_libs)
544 def dump_android_module(self): argument
546 if len(self.crate_types) == 1:
547 self.dump_single_type_android_module()
549 if 'test' in self.crate_types:
550 self.write('\nERROR: multiple crate types cannot include test type')
553 for crate_type in self.crate_types:
554 self.decide_one_module_type(crate_type)
555 self.dump_one_android_module(crate_type)
557 def build_default_name(self): argument
563 name1 = altered_defaults(self.root_pkg) + '_defaults'
564 if self.runner.try_claim_module_name(name1, self):
566 name2 = name1 + '_' + self.crate_name
567 if self.runner.try_claim_module_name(name2, self):
569 name3 = name1 + '_' + self.main_src_basename_path()
570 if self.runner.try_claim_module_name(name3, self):
572 return self.runner.claim_module_name(name1, self, 0)
574 def dump_srcs_list(self): argument
576 if len(self.srcs) > 1:
577 srcs = sorted(set(self.srcs)) # make a copy and dedup
579 srcs = [self.main_src]
580 copy_out = self.runner.copy_out_module_name()
583 self.dump_android_property_list('srcs', '"%s"', srcs)
585 def dump_defaults_module(self): argument
587 name = self.build_default_name()
588 self.defaults = name
589 self.write('\nrust_defaults {')
590 self.write(' name: "' + name + '",')
591 if self.runner.args.global_defaults:
592 self.write(' defaults: ["' + self.runner.args.global_defaults + '"],')
593 self.write(' crate_name: "' + self.crate_name + '",')
594 if len(self.srcs) == 1: # only one source file; share it in defaults
595 self.default_srcs = True
596 if self.has_warning and not self.cap_lints:
597 self.write(' // has rustc warnings')
598 self.dump_srcs_list()
599 if 'test' in self.crate_types:
600 self.write(' test_suites: ["general-tests"],')
601 self.write(' auto_gen_config: true,')
602 self.dump_edition_flags_libs()
603 self.write('}')
605 def dump_single_type_android_module(self): argument
607 crate_type = self.crate_types[0]
610 self.dump_one_android_module(crate_type)
614 if (self.host_supported and self.device_supported) or len(self.srcs) > 1:
615 self.srcs = sorted(set(self.srcs))
616 self.dump_defaults_module()
617 saved_srcs = self.srcs
619 self.srcs = [src]
620 saved_device_supported = self.device_supported
621 saved_host_supported = self.host_supported
622 saved_main_src = self.main_src
623 self.main_src = src
625 self.device_supported = False
626 self.host_supported = True
627 self.module_name = self.test_module_name()
628 self.decide_one_module_type(crate_type)
629 self.dump_one_android_module(crate_type)
631 self.device_supported = True
632 self.host_supported = False
633 self.module_name = self.test_module_name()
634 self.decide_one_module_type(crate_type)
635 self.dump_one_android_module(crate_type)
636 self.host_supported = saved_host_supported
637 self.device_supported = saved_device_supported
638 self.main_src = saved_main_src
639 self.srcs = saved_srcs
641 def dump_one_android_module(self, crate_type): argument
643 if not self.module_type:
644 self.write('\nERROR: unknown crate_type ' + crate_type)
646 self.write('\n' + self.module_type + ' {')
647 self.dump_android_core_properties()
648 if not self.defaults:
649 self.dump_edition_flags_libs()
650 if self.runner.args.host_first_multilib and self.host_supported and crate_type != 'test':
651 self.write(' compile_multilib: "first",')
652 if self.runner.args.apex_available and crate_type == 'lib':
653 self.write(' apex_available: [')
654 for apex in self.runner.args.apex_available:
655 self.write(' "%s",' % apex)
656 self.write(' ],')
657 if self.runner.args.min_sdk_version and crate_type == 'lib':
658 self.write(' min_sdk_version: "%s",' % self.runner.args.min_sdk_version)
659 self.write('}')
661 def dump_android_flags(self): argument
663 if not self.codegens and not self.cap_lints:
665 self.write(' flags: [')
666 if self.cap_lints:
667 self.write(' "--cap-lints ' + self.cap_lints + '",')
669 self.dump_android_property_list_items(codegens_fmt, self.codegens)
670 self.write(' ],')
672 def dump_edition_flags_libs(self): argument
673 if self.edition:
674 self.write(' edition: "' + self.edition + '",')
675 self.dump_android_property_list('features', '"%s"', self.features)
676 self.dump_android_property_list('cfgs', '"%s"', self.cfgs)
677 self.dump_android_flags()
678 if self.externs:
679 self.dump_android_externs()
680 self.dump_android_property_list('static_libs', '"lib%s"', self.static_libs)
681 self.dump_android_property_list('shared_libs', '"lib%s"', self.shared_libs)
683 def main_src_basename_path(self): argument
684 return re.sub('/', '_', re.sub('.rs$', '', self.main_src))
686 def test_module_name(self): argument
689 suffix = self.main_src_basename_path()
691 if self.device_supported:
693 return self.root_pkg + host_device + '_test_' + suffix
695 def decide_module_type(self): argument
697 crate_type = self.crate_types[0] if self.crate_types else ''
698 self.decide_one_module_type(crate_type)
700 def decide_one_module_type(self, crate_type): argument
702 host = '' if self.device_supported else '_host'
704 self.module_type = 'rust_binary' + host
707 self.stem = altered_stem(self.crate_name)
708 self.module_name = altered_name(self.crate_name)
713 self.module_type = 'rust_library' + host
714 self.stem = 'lib' + self.crate_name
715 self.module_name = altered_name(self.stem)
717 self.module_type = 'rust_library' + host
718 self.stem = 'lib' + self.crate_name
719 self.module_name = altered_name(self.stem)
721 self.module_type = 'rust_library' + host + '_dylib'
722 self.stem = 'lib' + self.crate_name
723 self.module_name = altered_name(self.stem) + '_dylib'
725 self.module_type = 'rust_ffi' + host + '_shared'
726 self.stem = 'lib' + self.crate_name
727 self.module_name = altered_name(self.stem) + '_shared'
729 self.module_type = 'rust_ffi' + host + '_static'
730 self.stem = 'lib' + self.crate_name
731 self.module_name = altered_name(self.stem) + '_static'
733 self.module_type = 'rust_test' + host
736 self.stem = self.test_module_name()
742 if self.module_name:
747 self.module_name = self.runner.claim_module_name(
748 self.module_name, self, 0)
750 self.stem = self.module_name
752 self.module_type = 'rust_proc_macro'
753 self.stem = 'lib' + self.crate_name
754 self.module_name = altered_name(self.stem)
756 self.module_type = ''
757 self.stem = ''
759 def dump_android_property_list_items(self, fmt, values): argument
762 self.write(' ' + (fmt % escape_quotes(v)) + ',')
764 def dump_android_property_list(self, name, fmt, values): argument
768 self.write(' ' + name + ': [')
769 self.dump_android_property_list_items(fmt, values)
770 self.write(' ],')
772 self.write(' ' + name + ': [' +
775 def dump_android_core_properties(self): argument
777 self.write(' name: "' + self.module_name + '",')
779 if self.defaults:
780 self.write(' defaults: ["' + self.defaults + '"],')
781 elif self.runner.args.global_defaults:
782 self.write(' defaults: ["' + self.runner.args.global_defaults + '"],')
783 if self.stem != self.module_name:
784 self.write(' stem: "' + self.stem + '",')
785 if self.has_warning and not self.cap_lints and not self.default_srcs:
786 self.write(' // has rustc warnings')
787 if self.host_supported and self.device_supported and self.module_type != 'rust_proc_macro':
788 self.write(' host_supported: true,')
789 if not self.defaults:
790 self.write(' crate_name: "' + self.crate_name + '",')
791 if not self.default_srcs:
792 self.dump_srcs_list()
793 if 'test' in self.crate_types and not self.defaults:
803 self.write(' test_suites: ["general-tests"],')
804 self.write(' auto_gen_config: true,')
805 if 'test' in self.crate_types and self.host_supported:
806 self.write(' test_options: {')
807 self.write(' unit_test: true,')
808 self.write(' },')
810 def dump_android_externs(self): argument
815 for lib in self.externs:
832 self.write(' rustlibs: [\n' + rust_libs + ' ],')
835 self.dump_android_property_list('proc_macros', '"lib%s"', so_libs)
841 def __init__(self, runner, outf_name): argument
843 self.runner = runner
844 self.pkg = ''
845 self.outf_name = outf_name # path to Android.bp
847 self.line_num = 1
848 self.line = ''
849 self.flags = '' # e.g. "crs"
850 self.lib = '' # e.g. "/.../out/lib*.a"
851 self.objs = list() # e.g. "/.../out/.../*.o"
853 def parse(self, pkg, line_num, args_line): argument
855 self.pkg = pkg
856 self.line_num = line_num
857 self.line = args_line
863 self.flags = unquote(args[0])
864 self.lib = unquote(args[1])
865 self.objs = sorted(set(map(unquote, args[2:])))
866 return self
868 def write(self, s): argument
869 self.outf.write(s + '\n')
871 def dump_debug_info(self): argument
872 self.write('\n// Line ' + str(self.line_num) + ' "ar" ' + self.line)
873 self.write('// ar_object for %12s' % self.pkg)
874 self.write('// flags = %s' % self.flags)
875 self.write('// lib = %s' % short_out_name(self.pkg, self.lib))
876 for o in self.objs:
877 self.write('// obj = %s' % short_out_name(self.pkg, o))
879 def dump_android_lib(self): argument
881 self.write('\ncc_library_static {')
882 self.write(' name: "' + file_base_name(self.lib) + '",')
883 self.write(' host_supported: true,')
884 if self.flags != 'crs':
885 self.write(' // ar flags = %s' % self.flags)
886 if self.pkg not in self.runner.pkg_obj2cc:
887 self.write(' ERROR: cannot find source files.\n}')
889 self.write(' srcs: [')
890 obj2cc = self.runner.pkg_obj2cc[self.pkg]
894 for obj in self.objs:
895 self.write(' "' + short_out_name(self.pkg, obj2cc[obj].src) + '",')
900 self.write(' ],')
901 self.write(' cflags: [')
902 self.write(' "-O3",') # TODO(chh): is this default correct?
903 self.write(' "-Wno-error",')
905 self.write(' "-f' + x + '",')
907 self.write(' "-D' + x + '",')
908 self.write(' ],')
909 self.write('}')
911 def dump(self): argument
913 self.runner.init_bp_file(self.outf_name)
914 with open(self.outf_name, 'a') as outf:
915 self.outf = outf
916 if self.runner.args.debug:
917 self.dump_debug_info()
918 self.dump_android_lib()
924 def __init__(self, runner, outf_name): argument
926 self.runner = runner
927 self.pkg = ''
928 self.outf_name = outf_name # path to Android.bp
930 self.line_num = 1
931 self.line = ''
932 self.src = ''
933 self.obj = ''
934 self.dflags = list() # -D flags
935 self.fflags = list() # -f flags
936 self.iflags = list() # -I flags
937 self.wflags = list() # -W flags
938 self.other_args = list()
940 def parse(self, pkg, line_num, args_line): argument
942 self.pkg = pkg
943 self.line_num = line_num
944 self.line = args_line
953 self.obj = unquote(args[i])[2:]
955 self.src = unquote(args[i])
957 self.src = unquote(args[i])
960 self.obj = unquote(args[i])
963 self.iflags.append(unquote(args[i]))
965 self.dflags.append(unquote(args[i])[2:])
967 self.fflags.append(unquote(args[i])[2:])
969 self.wflags.append(unquote(args[i])[2:])
973 self.other_args.append(unquote(args[i]))
975 self.dflags = sorted(set(self.dflags))
976 self.fflags = sorted(set(self.fflags))
979 if self.pkg not in self.runner.pkg_obj2cc:
980 self.runner.pkg_obj2cc[self.pkg] = {}
981 self.runner.pkg_obj2cc[self.pkg][self.obj] = self
982 return self
984 def write(self, s): argument
985 self.outf.write(s + '\n')
987 def dump_debug_flags(self, name, flags): argument
988 self.write('// ' + name + ':')
990 self.write('// %s' % f)
992 def dump(self): argument
994 if not self.runner.args.debug:
996 self.runner.init_bp_file(self.outf_name)
997 with open(self.outf_name, 'a') as outf:
998 self.outf = outf
999 self.write('\n// Line ' + str(self.line_num) + ' "cc" ' + self.line)
1000 self.write('// cc_object for %12s' % self.pkg)
1001 self.write('// src = %s' % short_out_name(self.pkg, self.src))
1002 self.write('// obj = %s' % short_out_name(self.pkg, self.obj))
1003 self.dump_debug_flags('-I flags', self.iflags)
1004 self.dump_debug_flags('-D flags', self.dflags)
1005 self.dump_debug_flags('-f flags', self.fflags)
1006 self.dump_debug_flags('-W flags', self.wflags)
1007 if self.other_args:
1008 self.dump_debug_flags('other args', self.other_args)
1014 def __init__(self, args): argument
1015 self.bp_files = set() # Remember all output Android.bp files.
1016 self.root_pkg = '' # name of package in ./Cargo.toml
1018 self.args = args
1019 self.dry_run = not args.run
1020 self.skip_cargo = args.skipcargo
1021 self.cargo_path = './cargo' # path to cargo, will be set later
1022 self.checked_out_files = False # to check only once
1023 self.build_out_files = [] # output files generated by build.rs
1025 self.cc_objects = list()
1026 self.pkg_obj2cc = {}
1028 self.ar_objects = list()
1029 self.crates = list()
1030 self.dependencies = list() # dependent and build script crates
1031 self.warning_files = set()
1033 self.name_owners = {}
1035 self.errors = ''
1036 self.setup_cargo_path()
1039 self.cargo = ['clean'] + args.cargo
1046 self.cargo = ['clean', 'build ' + default_target]
1048 self.cargo.append('build --tests ' + default_target)
1050 def setup_cargo_path(self): argument
1052 if self.args.cargo_bin:
1053 self.cargo_path = os.path.join(self.args.cargo_bin, 'cargo')
1054 if not os.path.isfile(self.cargo_path):
1055 sys.exit('ERROR: cannot find cargo in ' + self.args.cargo_bin)
1056 print('WARNING: using cargo in ' + self.args.cargo_bin)
1067 rust_version = self.find_rust_version(my_dir, linux_dir)
1069 self.cargo_path = os.path.join(cargo_bin, 'cargo')
1070 if not os.path.isfile(self.cargo_path):
1075 def find_rust_version(self, my_dir, linux_dir): argument
1102 def find_out_files(self): argument
1104 list1 = glob.glob(TARGET_TMP + '/*/*/build/' + self.root_pkg + '-*/out/*')
1106 list2 = glob.glob(TARGET_TMP + '/*/build/' + self.root_pkg + '-*/out/*')
1109 def copy_out_files(self): argument
1111 if self.checked_out_files:
1113 self.checked_out_files = True
1114 cargo_out_files = self.find_out_files()
1122 self.build_out_files = sorted(out_files)
1124 def has_used_out_dir(self): argument
1129 def copy_out_module_name(self): argument
1130 if self.args.copy_out and self.build_out_files:
1131 return 'copy_' + self.root_pkg + '_build_out'
1135 def read_license(self, name): argument
1150 def dump_copy_out_module(self, outf): argument
1152 copy_out = self.copy_out_module_name()
1159 if len(self.build_out_files) > 1:
1161 for f in self.build_out_files:
1165 outf.write(' out: ["' + self.build_out_files[0] + '"],\n')
1168 def init_bp_file(self, name): argument
1170 if name not in self.bp_files:
1171 self.bp_files.add(name)
1172 license_section = self.read_license(name)
1180 self.dump_copy_out_module(outf)
1182 def dump_test_mapping_files(self): argument
1184 if self.dry_run:
1186 elif self.args.no_test_mapping:
1190 for bp_file_name in self.bp_files:
1192 return self
1194 def try_claim_module_name(self, name, owner): argument
1196 if name not in self.name_owners or owner == self.name_owners[name]:
1197 self.name_owners[name] = owner
1201 def claim_module_name(self, prefix, owner, counter): argument
1207 if self.try_claim_module_name(name, owner):
1211 def find_root_pkg(self): argument
1222 self.root_pkg = name.match(line).group(1)
1227 def run_cargo(self): argument
1229 if self.skip_cargo:
1230 return self
1240 return self
1241 if not self.dry_run:
1244 if not self.args.use_cargo_lock and had_cargo_lock: # save it
1249 os.environ['PATH'] = os.path.dirname(self.cargo_path) + ':' + saved_path
1252 if self.args.add_workspace:
1262 if self.args.verbose:
1264 for c in self.cargo:
1267 if self.args.features is not None:
1269 if self.args.features:
1270 features += ' --features ' + self.args.features
1271 cmd_v_flag = ' -vv ' if self.args.vv else ' -v '
1272 cmd = self.cargo_path + cmd_v_flag
1274 if self.args.rustflags and c != 'clean':
1275 cmd = 'RUSTFLAGS="' + self.args.rustflags + '" ' + cmd
1276 if self.dry_run:
1279 if self.args.verbose:
1287 if self.args.verbose:
1290 if not self.dry_run:
1293 elif not self.args.use_cargo_lock: # restore saved Cargo.lock
1295 return self
1297 def dump_dependencies(self): argument
1299 if not self.dependencies:
1302 for c in self.dependencies:
1305 self.init_bp_file('Android.bp')
1311 def dump_pkg_obj2cc(self): argument
1313 if not self.args.debug:
1315 self.init_bp_file('Android.bp')
1317 sorted_pkgs = sorted(self.pkg_obj2cc.keys())
1319 if not self.pkg_obj2cc[pkg]:
1322 obj2cc = self.pkg_obj2cc[pkg]
1327 def apply_patch(self): argument
1329 if self.args.patch:
1330 if self.dry_run:
1331 print('Dry-run skip patch file:', self.args.patch)
1333 if not os.path.exists(self.args.patch):
1334 self.append_to_bp('ERROR cannot find patch file: ' + self.args.patch)
1335 return self
1336 if self.args.verbose:
1337 print('### INFO: applying local patch file:', self.args.patch)
1339 self.args.patch)
1340 return self
1342 def gen_bp(self): argument
1344 if self.dry_run:
1347 self.find_root_pkg()
1348 if self.args.copy_out:
1349 self.copy_out_files()
1350 elif self.find_out_files() and self.has_used_out_dir():
1351 print('WARNING: ' + self.root_pkg + ' has cargo output files; ' +
1354 self.parse(cargo_out, 'Android.bp')
1355 self.crates.sort(key=get_module_name)
1356 for obj in self.cc_objects:
1358 self.dump_pkg_obj2cc()
1359 for crate in self.crates:
1362 for lib in self.ar_objects:
1363 if lib.pkg == self.root_pkg:
1368 if self.args.dependencies and self.dependencies:
1369 self.dump_dependencies()
1370 if self.errors:
1371 self.append_to_bp('\n' + ERRORS_LINE + '\n' + self.errors)
1372 return self
1374 def add_ar_object(self, obj): argument
1375 self.ar_objects.append(obj)
1377 def add_cc_object(self, obj): argument
1378 self.cc_objects.append(obj)
1380 def add_crate(self, crate): argument
1383 if self.args.debug: # include debug info of all crates
1384 self.crates.append(crate)
1385 if self.args.dependencies: # include only dependent crates
1388 self.dependencies.append(crate)
1390 for c in self.crates:
1395 self.crates.append(crate)
1397 def find_warning_owners(self): argument
1400 for f in self.warning_files:
1403 for c in self.crates:
1414 for c in self.crates:
1418 def rustc_command(self, n, rustc_line, line, outf_name): argument
1430 self.add_crate(Crate(self, outf_name).parse(n, args))
1432 self.assert_empty_vv_line(new_rustc)
1435 def cc_ar_command(self, n, groups, outf_name): argument
1439 self.add_cc_object(CCObject(self, outf_name).parse(pkg, n, line))
1441 self.add_ar_object(ARObject(self, outf_name).parse(pkg, n, line))
1443 def append_to_bp(self, line): argument
1444 self.init_bp_file('Android.bp')
1448 def assert_empty_vv_line(self, line): argument
1450 self.append_to_bp('ERROR -vv line: ' + line)
1453 def parse(self, inf, outf_name): argument
1462 rustc_line = self.assert_empty_vv_line(rustc_line)
1467 self.add_crate(Crate(self, outf_name).parse(n, args_line))
1468 self.assert_empty_vv_line(rustc_line)
1470 new_rustc = self.rustc_command(n, rustc_line, line, outf_name)
1472 self.cc_ar_command(n, CC_AR_VV_PAT.match(line), outf_name)
1474 self.assert_empty_vv_line(rustc_line)
1477 self.warning_files.add(fpath)
1479 if not self.args.ignore_cargo_errors:
1480 self.errors += line
1483 self.find_warning_owners()