Example #1
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
Example #2
0
def main():
    args = parse_args()
    mojom_module = args.mojom_module[0]
    output_dir = args.output_dir[0]
    excluded = args.exclude[0] if args.exclude else ""

    generator_module = importlib.import_module('mojom_objc_generator')
    bytecode_path = os.path.join(output_dir, "objc_templates_bytecode")
    fileutil.EnsureDirectoryExists(bytecode_path)
    template_expander.PrecompileTemplates({"objc": generator_module}, bytecode_path)
    generator = generator_module.Generator(None)
    generator.bytecode_path = bytecode_path
    generator.excludedTypes = excluded.split(',')
    with open(mojom_module, 'rb') as f:
        generator.module = Module.Load(f)
    generator.GenerateFiles(output_dir)
Example #3
0
def main():
    global ast_root_dir

    args = parse_args()
    mojom_module = args.mojom_module[0]
    module_include_path = args.module_include_path[0]
    output_dir = args.output_dir[0]

    ast_root_dir = os.path.dirname(mojom_module)

    generator_module = importlib.import_module('mojom_objc_generator')
    bytecode_path = os.path.join(output_dir, "objc_templates_bytecode")
    fileutil.EnsureDirectoryExists(bytecode_path)
    template_expander.PrecompileTemplates({"objc": generator_module},
                                          bytecode_path)
    generator = generator_module.Generator(None)
    generator.bytecode_path = bytecode_path
    generator.module_include_path = module_include_path
    with open(mojom_module, 'rb') as f:
        generator.module = Module.Load(f)
    generator.GenerateFiles(output_dir)
Example #4
0
def _VerifyImportDeps(args, __):
    fileutil.EnsureDirectoryExists(args.output_dir)

    if args.filelist:
        with open(args.filelist) as f:
            args.filename.extend(f.read().split())

    for filename in args.filename:
        rel_path = RelativePath(filename, args.depth, args.output_dir)
        module_path = _GetModulePath(rel_path, args.output_dir)
        with open(module_path, 'rb') as f:
            module = Module.Load(f)
            mojom_imports = set(imp.path for imp in module.imports)

        sources = set()

        target_prefix = args.deps_file.split(".deps_sources_list")[0]
        sources = GetSourcesList(target_prefix, sources, args.output_dir)

        if (not sources.issuperset(mojom_imports)):
            target_name = target_prefix.rsplit("/", 1)[1]
            target_prefix_without_gen_dir = target_prefix.split(
                args.output_dir + "/", 1)[1]
            full_target_name = "//" + target_prefix_without_gen_dir.rsplit(
                "/", 1)[0] + ":" + target_name

            print(">>> File \"%s\"" % filename)
            print(">>> from target \"%s\"" % full_target_name)
            print(
                ">>> is missing dependencies for the following imports:\n%s" %
                list(mojom_imports.difference(sources)))
            sys.exit(1)

        source_filename, _ = os.path.splitext(rel_path.relative_path())
        output_file = source_filename + '.v'
        output_file_path = os.path.join(args.output_dir, output_file)
        WriteFile("", output_file_path)

    return 0