コード例 #1
0
    def _GenerateModule(self, args, remaining_args, generator_modules,
                        rel_filename):
        # Return the already-generated module.
        if rel_filename.path in self._processed_files:
            return self._processed_files[rel_filename.path]
        tree = self._parsed_files[rel_filename.path]

        dirname = os.path.dirname(rel_filename.path)

        # Process all our imports first and collect the module object for each.
        # We use these to generate proper type info.
        imports = {}
        for parsed_imp in tree.import_list:
            rel_import_file = FindImportFile(
                RelativePath(dirname, rel_filename.source_root),
                parsed_imp.import_filename, args.import_directories)
            imports[parsed_imp.import_filename] = self._GenerateModule(
                args, remaining_args, generator_modules, rel_import_file)

        # Set the module path as relative to the source root.
        # Normalize to unix-style path here to keep the generators simpler.
        module_path = rel_filename.relative_path().replace('\\', '/')

        module = translate.OrderedModule(tree, module_path, imports)

        if args.scrambled_message_id_salt_paths:
            salt = ''.join([
                ReadFileContents(f)
                for f in args.scrambled_message_id_salt_paths
            ])
            ScrambleMethodOrdinals(module.interfaces, salt)

        if self._should_generate(rel_filename.path):
            AddComputedData(module)
            for language, generator_module in generator_modules.iteritems():
                generator = generator_module.Generator(
                    module,
                    args.output_dir,
                    typemap=self._typemap.get(language, {}),
                    variant=args.variant,
                    bytecode_path=args.bytecode_path,
                    for_blink=args.for_blink,
                    use_once_callback=args.use_once_callback,
                    js_bindings_mode=args.js_bindings_mode,
                    export_attribute=args.export_attribute,
                    export_header=args.export_header,
                    generate_non_variant_code=args.generate_non_variant_code,
                    support_lazy_serialization=args.support_lazy_serialization,
                    allow_native_structs=args.allow_native_structs)
                filtered_args = []
                if hasattr(generator_module, 'GENERATOR_PREFIX'):
                    prefix = '--' + generator_module.GENERATOR_PREFIX + '_'
                    filtered_args = [
                        arg for arg in remaining_args if arg.startswith(prefix)
                    ]
                generator.GenerateFiles(filtered_args)

        # Save result.
        self._processed_files[rel_filename.path] = module
        return module
コード例 #2
0
    def _GenerateModule(self, args, remaining_args, generator_modules,
                        rel_filename, imported_filename_stack):
        # Return the already-generated module.
        if rel_filename.path in self._processed_files:
            return self._processed_files[rel_filename.path]

        if rel_filename.path in imported_filename_stack:
            print("%s: Error: Circular dependency" % rel_filename.path + \
                MakeImportStackMessage(imported_filename_stack + [rel_filename.path]))
            sys.exit(1)

        module_path = _GetModulePath(rel_filename, args.output_dir)
        with open(module_path, 'rb') as f:
            module = Module.Load(f)

        if args.scrambled_message_id_salt_paths:
            salt = b''.join(
                map(ReadFileContents, args.scrambled_message_id_salt_paths))
            ScrambleMethodOrdinals(module.interfaces, salt)

        if self._should_generate(rel_filename.path):
            AddComputedData(module)
            for language, generator_module in generator_modules.items():
                generator = generator_module.Generator(
                    module, args.output_dir, typemap=self._typemap.get(language, {}),
                    variant=args.variant, bytecode_path=args.bytecode_path,
                    for_blink=args.for_blink,
                    js_bindings_mode=args.js_bindings_mode,
                    js_generate_struct_deserializers=\
                            args.js_generate_struct_deserializers,
                    export_attribute=args.export_attribute,
                    export_header=args.export_header,
                    generate_non_variant_code=args.generate_non_variant_code,
                    support_lazy_serialization=args.support_lazy_serialization,
                    disallow_native_types=args.disallow_native_types,
                    disallow_interfaces=args.disallow_interfaces,
                    generate_message_ids=args.generate_message_ids,
                    generate_fuzzing=args.generate_fuzzing,
                    enable_kythe_annotations=args.enable_kythe_annotations,
                    extra_cpp_template_paths=args.extra_cpp_template_paths,
                    generate_extra_cpp_only=args.generate_extra_cpp_only)
                filtered_args = []
                if hasattr(generator_module, 'GENERATOR_PREFIX'):
                    prefix = '--' + generator_module.GENERATOR_PREFIX + '_'
                    filtered_args = [
                        arg for arg in remaining_args if arg.startswith(prefix)
                    ]
                generator.GenerateFiles(filtered_args)

        # Save result.
        self._processed_files[rel_filename.path] = module
        return module
コード例 #3
0
    def _GenerateModule(self, args, remaining_args, generator_modules,
                        rel_filename, imported_filename_stack):
        # Return the already-generated module.
        if rel_filename.path in self._processed_files:
            return self._processed_files[rel_filename.path]

        if rel_filename.path in imported_filename_stack:
            print("%s: Error: Circular dependency" % rel_filename.path + \
                MakeImportStackMessage(imported_filename_stack + [rel_filename.path]))
            sys.exit(1)

        tree = _UnpickleAST(
            _FindPicklePath(rel_filename,
                            args.gen_directories + [args.output_dir]))
        dirname = os.path.dirname(rel_filename.path)

        # Process all our imports first and collect the module object for each.
        # We use these to generate proper type info.
        imports = {}
        for parsed_imp in tree.import_list:
            rel_import_file = FindImportFile(
                RelativePath(dirname, rel_filename.source_root),
                parsed_imp.import_filename, args.import_directories)
            imports[parsed_imp.import_filename] = self._GenerateModule(
                args, remaining_args, generator_modules, rel_import_file,
                imported_filename_stack + [rel_filename.path])

        # Set the module path as relative to the source root.
        # Normalize to unix-style path here to keep the generators simpler.
        module_path = rel_filename.relative_path().replace('\\', '/')

        module = translate.OrderedModule(tree, module_path, imports)

        if args.scrambled_message_id_salt_paths:
            salt = ''.join(
                map(ReadFileContents, args.scrambled_message_id_salt_paths))
            ScrambleMethodOrdinals(module.interfaces, salt)

        if self._should_generate(rel_filename.path):
            AddComputedData(module)
            for language, generator_module in generator_modules.items():
                generator = generator_module.Generator(
                    module,
                    args.output_dir,
                    typemap=self._typemap.get(language, {}),
                    variant=args.variant,
                    bytecode_path=args.bytecode_path,
                    for_blink=args.for_blink,
                    js_bindings_mode=args.js_bindings_mode,
                    use_old_js_lite_bindings_names=args.
                    use_old_js_lite_bindings_names,
                    export_attribute=args.export_attribute,
                    export_header=args.export_header,
                    generate_non_variant_code=args.generate_non_variant_code,
                    support_lazy_serialization=args.support_lazy_serialization,
                    disallow_native_types=args.disallow_native_types,
                    disallow_interfaces=args.disallow_interfaces,
                    generate_message_ids=args.generate_message_ids,
                    generate_fuzzing=args.generate_fuzzing,
                    enable_kythe_annotations=args.enable_kythe_annotations)
                filtered_args = []
                if hasattr(generator_module, 'GENERATOR_PREFIX'):
                    prefix = '--' + generator_module.GENERATOR_PREFIX + '_'
                    filtered_args = [
                        arg for arg in remaining_args if arg.startswith(prefix)
                    ]
                generator.GenerateFiles(filtered_args)

        # Save result.
        self._processed_files[rel_filename.path] = module
        return module