コード例 #1
0
def generate_bindings_for_builtins_files(builtins_files=[],
                                         output_path=None,
                                         concatenate_output=False,
                                         combined_output=False,
                                         generate_only_wrapper_files=False,
                                         framework_name="",
                                         force_output=False):

    generators = []

    model = BuiltinsCollection(framework_name=framework_name)

    for filepath in builtins_files:
        with do_open(filepath, "r") as file:
            file_text = file.read()
            file_name = os.path.basename(filepath)

            # If this is a test file, then rewrite the filename to remove the
            # test running options encoded into the filename.
            if file_name.startswith(framework_name):
                (_, object_name, _) = file_name.split('-')
                file_name = object_name + '.js'
            model.parse_builtins_file(file_name, file_text)

    if combined_output:
        log.debug("Using generator style: combined files for all builtins.")
        generators.append(BuiltinsCombinedHeaderGenerator(model))
        generators.append(BuiltinsCombinedImplementationGenerator(model))
    else:
        log.debug("Using generator style: single files for each builtin.")
        if generate_only_wrapper_files:
            generators.append(BuiltinsWrapperHeaderGenerator(model))
            generators.append(BuiltinsWrapperImplementationGenerator(model))

            generators.append(BuiltinsInternalsWrapperHeaderGenerator(model))
            generators.append(
                BuiltinsInternalsWrapperImplementationGenerator(model))
        else:
            for object in model.objects:
                generators.append(
                    BuiltinsSeparateHeaderGenerator(model, object))
                generators.append(
                    BuiltinsSeparateImplementationGenerator(model, object))

    log.debug("")
    log.debug("Generating bindings for builtins.")

    test_result_file_contents = []

    for generator in generators:
        output_filepath = os.path.join(output_path,
                                       generator.output_filename())
        log.debug("Generating output file: %s" % generator.output_filename())
        output = generator.generate_output()

        log.debug("---")
        log.debug("\n" + output)
        log.debug("---")
        if concatenate_output:
            test_result_file_contents.append('### Begin File: %s' %
                                             generator.output_filename())
            test_result_file_contents.append(output)
            test_result_file_contents.append('### End File: %s' %
                                             generator.output_filename())
            test_result_file_contents.append('')
        else:
            log.debug("Writing file: %s" % output_filepath)
            output_file = LazyFileWriter(output_filepath, force_output)
            output_file.write(output)
            output_file.close()

    if concatenate_output:
        filename = concatenated_output_filename(builtins_files, framework_name,
                                                generate_only_wrapper_files)
        output_filepath = os.path.join(output_path, filename)
        log.debug("Writing file: %s" % output_filepath)
        output_file = LazyFileWriter(output_filepath, force_output)
        output_file.write('\n'.join(test_result_file_contents))
        output_file.close()
コード例 #2
0
def generate_bindings_for_builtins_files(builtins_files=[],
                                         output_path=None,
                                         concatenate_output=False,
                                         combined_output=False,
                                         generate_only_wrapper_files=False,
                                         framework_name="",
                                         force_output=False):

    generators = []

    model = BuiltinsCollection(framework_name=framework_name)

    for filepath in builtins_files:
        with open(filepath, "r") as file:
            file_text = file.read()
            file_name = os.path.basename(filepath)

            # If this is a test file, then rewrite the filename to remove the
            # test running options encoded into the filename.
            if file_name.startswith(framework_name):
                (_, object_name, _) = file_name.split('-')
                file_name = object_name + '.js'
            model.parse_builtins_file(file_name, file_text)

    if combined_output:
        log.debug("Using generator style: combined files for all builtins.")
        generators.append(BuiltinsCombinedHeaderGenerator(model))
        generators.append(BuiltinsCombinedImplementationGenerator(model))
    else:
        log.debug("Using generator style: single files for each builtin.")
        if generate_only_wrapper_files:
            generators.append(BuiltinsWrapperHeaderGenerator(model))
            generators.append(BuiltinsWrapperImplementationGenerator(model))

            generators.append(BuiltinsInternalsWrapperHeaderGenerator(model))
            generators.append(BuiltinsInternalsWrapperImplementationGenerator(model))
        else:
            for object in model.objects:
                generators.append(BuiltinsSeparateHeaderGenerator(model, object))
                generators.append(BuiltinsSeparateImplementationGenerator(model, object))

    log.debug("")
    log.debug("Generating bindings for builtins.")

    test_result_file_contents = []

    for generator in generators:
        output_filepath = os.path.join(output_path, generator.output_filename())
        log.debug("Generating output file: %s" % generator.output_filename())
        output = generator.generate_output()

        log.debug("---")
        log.debug("\n" + output)
        log.debug("---")
        if concatenate_output:
            test_result_file_contents.append('### Begin File: %s' % generator.output_filename())
            test_result_file_contents.append(output)
            test_result_file_contents.append('### End File: %s' % generator.output_filename())
            test_result_file_contents.append('')
        else:
            log.debug("Writing file: %s" % output_filepath)
            output_file = LazyFileWriter(output_filepath, force_output)
            output_file.write(output)
            output_file.close()

    if concatenate_output:
        filename = concatenated_output_filename(builtins_files, framework_name, generate_only_wrapper_files)
        output_filepath = os.path.join(output_path, filename)
        log.debug("Writing file: %s" % output_filepath) 
        output_file = LazyFileWriter(output_filepath, force_output)
        output_file.write('\n'.join(test_result_file_contents))
        output_file.close()