Exemple #1
0
def main():
    args, remaining_args = _ParseCLIArgs()

    if args.file_graph == '-':
        fp = sys.stdin
    else:
        fp = open(args.file_graph)

    mojom_file_graph = ReadMojomFileGraphFromFile(fp)
    modules = mojom_translator.TranslateFileGraph(mojom_file_graph)

    generator_modules = LoadGenerators(args.generators_string)

    for _, module in modules.iteritems():
        FixModulePath(module, os.path.abspath(args.depth))
        for generator_module in generator_modules:
            generator = generator_module.Generator(module, args.output_dir)

            # Look at unparsed args for generator-specific args.
            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)
Exemple #2
0
def _load_mojom(path_to_mojom):
    filename = os.path.abspath(path_to_mojom)

    # Parse
    mojom_file_graph = parser_runner.ParseToMojomFileGraph(SDK_DIR, [filename],
                                                           meta_data_only=True)
    if mojom_file_graph is None:
        raise Exception
    mojom_dict = mojom_translator.TranslateFileGraph(mojom_file_graph)
    return mojom_dict[filename]
Exemple #3
0
def process_mojom(path_to_mojom):
    filename = os.path.abspath(path_to_mojom)

    # Parse
    mojom_file_graph = parser_runner.ParseToFidlFileGraph(SDK_DIR, [filename],
                                                          meta_data_only=True)
    if mojom_file_graph is None:
        print("Error parsing %s" % filename)
    mojom_dict = mojom_translator.TranslateFileGraph(mojom_file_graph)
    mojom = mojom_dict[filename]

    # Output path
    attributes = mojom.attributes
    print(mojom_path(mojom.name, mojom.namespace, attributes))
def main():
    args, remaining_args = _ParseCLIArgs()

    if args.file_graph == '-':
        fp = sys.stdin
    else:
        fp = open(args.file_graph)

    mojom_file_graph = ReadMojomFileGraphFromFile(fp)
    mojom_modules = mojom_translator.TranslateFileGraph(mojom_file_graph)

    # Note that we are using the word "module" in two unrelated ways here.
    # A mojom module is the Python data structure defined in module.py that
    # represents a Mojom file (sometimes referred to as a Mojom module.)
    # A generator module is a Python module in the sense of the entity the Python
    # runtime loads corresponding to a .py file.
    generator_modules = LoadGenerators(args.generators_string)

    abs_src_root_path = os.path.abspath(args.src_root_path)
    for _, mojom_module in mojom_modules.iteritems():
        # If --no-gen-imports is specified then skip the code generation step for
        # any modules that do not have the |specified_name| field set. This field
        # being set indicates that the module was translated from a .mojom file
        # whose name was explicitly requested during parsing. Otherwise the module
        # is included only becuase of a mojom import statement.
        if args.no_gen_imports and not mojom_module.specified_name:
            continue
        FixModulePath(mojom_module, abs_src_root_path)
        for generator_module in generator_modules:
            generator = generator_module.Generator(mojom_module,
                                                   args.output_dir)

            # Look at unparsed args for generator-specific args.
            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)
                ]
            if args.generate_type_info:
                filtered_args.append("--generate_type_info")

            generator.GenerateFiles(filtered_args)
Exemple #5
0
def main():
    args, remaining_args = _ParseCLIArgs()

    if args.file_graph == '-':
        fp = sys.stdin
    else:
        fp = open(args.file_graph)

    mojom_file_graph = ReadMojomFileGraphFromFile(fp)
    modules = mojom_translator.TranslateFileGraph(mojom_file_graph)

    generator_modules = LoadGenerators(args.generators_string)

    for _, module in modules.iteritems():
        # If filenames are specified on the command line, only generate code for
        # the specified mojom files.
        # TODO(azani): This is not as robust as we would like since files with the
        # same name but different paths or files resolved through links might not
        # be correctly identified by module.name.
        if args.no_gen_imports and not module.specified_name:
            continue
        FixModulePath(module, os.path.abspath(args.depth))
        for generator_module in generator_modules:
            generator = generator_module.Generator(module, args.output_dir)

            # Look at unparsed args for generator-specific args.
            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)
                ]
            if args.generate_type_info:
                filtered_args.append("--generate_type_info")

            generator.GenerateFiles(filtered_args)