Beispiel #1
0
def _run(argv):
    svg_files = [os.path.abspath(f) for f in argv[1:]]
    if len(set(os.path.basename(f) for f in svg_files)) != len(svg_files):
        sys.exit("Input svgs must have unique names")

    os.makedirs(build_dir(), exist_ok=True)
    if FLAGS.gen_svg_font_diffs:
        os.makedirs(os.path.join(build_dir(), "resvg_png"), exist_ok=True)
        os.makedirs(os.path.join(build_dir(), "skia_png"), exist_ok=True)
        os.makedirs(os.path.join(build_dir(), "diff_png"), exist_ok=True)

    build_file = resolve_rel_build("build.ninja")
    if FLAGS.gen_ninja:
        print(f"Generating {os.path.relpath(build_file)}")
        with open(build_file, "w") as f:
            nw = ninja_syntax.Writer(f)
            write_preamble(nw)
            write_picosvg_builds(nw, svg_files)
            write_codepointmap_build(nw, svg_files)
            write_fea_build(nw, svg_files)
            write_font_build(nw, svg_files)
            if FLAGS.gen_svg_font_diffs:
                write_svg_font_diff_build(nw, svg_files)

    # TODO: report on failed svgs
    # this is the delta between inputs and picos
    ninja_cmd = ["ninja", "-C", os.path.dirname(build_file)]
    if FLAGS.exec_ninja:
        print(" ".join(ninja_cmd))
        subprocess.run(ninja_cmd, check=True)
    else:
        print("To run:", " ".join(ninja_cmd))

    return
Beispiel #2
0
def main():
    parser = argparse.ArgumentParser(
        description=
        "Creates the Ninja build script for the Dinosaur Planet decompilation project."
    )
    parser.add_argument("--base-dir",
                        type=str,
                        dest="base_dir",
                        help="The root of the project (default=..).",
                        default="..")
    parser.add_argument(
        "--target",
        type=str,
        help=
        "The filename of the ROM to create (excluding extension suffix, default=dino).",
        default="dino")
    parser.add_argument("--skip-dlls",
                        dest="skip_dlls",
                        action="store_true",
                        help="Don't recompile DLLs (use original).")

    args = parser.parse_args()

    # Create config
    config = BuildConfig(target=args.target, skip_dlls=args.skip_dlls or False)

    # Do all path lookups from the base directory
    os.chdir(Path(args.base_dir).resolve())

    # Verify this is the correct directory
    expected_link_script_path = Path.cwd().joinpath(
        config.link_script).absolute()
    if not expected_link_script_path.exists():
        print(
            f"Could not find linker script at {expected_link_script_path}. Is the base directory '{args.base_dir}' correct?"
        )
        sys.exit(1)

    # Gather input files
    scanner = InputScanner(config)
    input = scanner.scan()

    # Create ninja build file
    ninja_file = open("build.ninja", "w")

    # Write
    writer = BuildNinjaWriter(ninja_syntax.Writer(ninja_file), input, config)
    writer.write()
    writer.close()
def _run(argv):
    if len(argv) < 2:
        sys.exit("Expected list of SVG filepath")

    os.makedirs(FLAGS.build_dir, exist_ok=True)
    build_file = os.path.join(FLAGS.build_dir, "build.ninja")
    if FLAGS.gen_ninja:
        logging.info(f"Generating %s", os.path.relpath(build_file))
        with open(build_file, "w") as f:
            nw = ninja_syntax.Writer(f)
            _write_svg_preamble(nw)
            _write_svg_symbol_builds(nw, argv[1:])

    ninja_cmd = ["ninja", "-C", os.path.dirname(build_file)]
    if FLAGS.exec_ninja:
        print(" ".join(ninja_cmd))
        subprocess.run(ninja_cmd, check=True)
    else:
        print("To run:", " ".join(ninja_cmd))
Beispiel #4
0
def _run(argv):
    if len(argv) != 2:
        sys.exit("Expected 1 non-flag argument, a font filename")
    font_filename = os.path.abspath(argv[1])
    root_font = ttLib.TTFont(font_filename)
    wght_range = icon_font.wght_range(root_font)

    os.makedirs(_build_dir(), exist_ok=True)
    os.makedirs(os.path.join(_build_dir(), "symbols"), exist_ok=True)
    build_file = _resolve_rel_build("build.ninja")
    if FLAGS.gen_ninja:
        logging.info(f"Generating %s", os.path.relpath(build_file))
        with open(build_file, "w") as f:
            nw = ninja_syntax.Writer(f)
            _write_preamble(nw, font_filename, root_font, wght_range)
            font_files = _write_font_builds(nw, font_filename, wght_range)
            _write_symbol_builds(nw, root_font, font_files)

    ninja_cmd = ["ninja", "-C", os.path.dirname(build_file)]
    if FLAGS.exec_ninja:
        print(" ".join(ninja_cmd))
        subprocess.run(ninja_cmd, check=True)
    else:
        print("To run:", " ".join(ninja_cmd))
Beispiel #5
0
def generate_single_build_file( test_path: str ):
    unit_test_root_dir = os.path.dirname( os.path.realpath( __file__ ) ) + os.path.sep

    if os.path.sep != test_path[-1]:
        test_path += os.path.sep
    if not os.path.isabs( test_path ):
        test_path = os.getcwd() + os.path.sep + test_path

    common_settings_filename = 'settings.yaml'
    common_settings_full_filename = unit_test_root_dir + common_settings_filename
    try:
        with open( common_settings_full_filename, 'r' ) as read_file:
            common_settings = yaml.load( read_file, Loader=yaml.BaseLoader )
    except FileNotFoundError:
        print( common_settings_filename + ' file does not exist, generation failed')
        sys.exit( 1 )

    settings_filename = 'build_settings.yaml'
    settings_full_filename = test_path + settings_filename
    try:
        with open( settings_full_filename, 'r' ) as read_file:
            settings = yaml.load( read_file, Loader=yaml.BaseLoader )
    except FileNotFoundError:
        print( settings_full_filename + ' file does not exist, generation failed')
        sys.exit( 1 )

    build_filename = 'build.ninja'
    build_full_filename = test_path + build_filename
    ninja_writer = ninja_syntax.Writer( open( build_full_filename, 'w' ) )
    n = ninja_writer

    script_full_filename = os.path.realpath( __file__ )
    script_filename = os.path.basename( script_full_filename )

    n.comment( 'This file is generated using ' + script_filename + ' script, do not edit it by hand!' )
    n.comment( 'Settings are parsed from ' + settings_filename + ' and ' + common_settings_filename + ' files' )
    n.newline()

    n.variable( 'ninja_required_version', '1.8' )
    n.newline()

    target_filename = os.path.basename( os.path.dirname( test_path ) )
    target_full_filename = test_path + target_filename
    if 'target' in settings:
        if os.path.isabs( settings['target'] ):
            target_full_filename = settings['target']
        else:
            target_full_filename = test_path + settings['target']
        target_filename = os.path.basename( target_full_filename )

    n.comment( 'Output target' )
    n.variable( 'target', target_full_filename )
    n.variable( 'target_path', test_path )
    n.newline()

    n.comment( 'Directory variables' )
    for key, value in common_settings['directories'].items():
        if '.' == value:
            value = unit_test_root_dir
        if not os.path.isabs( value ):
            value = unit_test_root_dir + value
        value = os.path.normpath( value )
        value += os.path.sep
        n.variable( key, value )

    n.variable( 'test_path', test_path )
    n.newline()

    n.comment( 'Common variables')
    for key, value in common_settings['ninja_variables'].items():
        n.variable( key, value )
    n.newline()

    inc_flags = list( '-I' + i for i in common_settings['include_directories'] )
    n.variable( 'inc_flags', inc_flags )
    n.newline()

    n.comment( 'Build and link rules' )
    n.rule( 'cxx',
        command='${compiler} -MMD -MT ${out} -MF ${out}.d ${compiler_flags} ${inc_flags} -c ${in} -o ${out}',
        depfile='${out}.d',
        description='CXX ${out}' )
    n.newline()

    n.rule( 'cxx_coverage',
        command='${compiler} -MMD -MT ${out} -MF ${out}.d ${compiler_flags} ${coverage_flag} ${inc_flags} -c ${in} -o ${out}',
        depfile='${out}.d',
        description='CXX ${out}' )
    n.newline()

    n.rule( 'link',
        command='${linker} -o ${out} ${in} ${linker_flags}',
        description='LINK ${out}' )
    n.newline()

    n.comment( 'Regenerate build files if build script changes.' )
    n.rule( 'configure',
        command='python3 ' + script_full_filename + ' ${target_path}',
        generator=True,
        description='Generating ${out} file' )
    n.newline()

    n.rule( 'run',
        command='$in --gtest_color=yes | tee $out',
        description='Running the test' )
    n.newline()

    n.comment( 'Build instructions' )
    objs = list()

    o = '${object_dir}' + remove_file_extension( remove_variable_prefix( settings['test_file'] ) ) + '.o'
    n.build( o, 'cxx', '${test_path}' + settings['test_file'] ) # prepending test path to fix warning links
    objs.append( o )

    o = '${object_dir}' + remove_file_extension( remove_variable_prefix( settings['file_under_test'] ) ) + '.o'
    n.build( o, 'cxx_coverage', settings['file_under_test'] )
    objs.append( o )

    if 'source_files' in settings:
        for f in settings['source_files']:
            o = '${object_dir}' + remove_file_extension( remove_variable_prefix( f ) ) + '.o'
            n.build( o, 'cxx', f )
            objs.append( o )
        n.newline()

    n.comment( 'Target linker instruction' )
    n.build( '${target}', 'link', objs )
    n.newline()

    n.comment( 'Build file generation instruction' )
    n.build( build_filename, 'configure', implicit=[script_full_filename, settings_filename, common_settings_full_filename] )
    n.newline()

    n.comment( 'Test run instruction' )
    n.build( '${target_path}/result.txt', 'run', '${target}' )
    n.build( 'run', 'phony ${target_path}/result.txt' )
    n.newline()

    n.build( 'all', 'phony ' + build_filename + ' ${target}' )
    n.default( 'all' )
import os
import yaml


def remove_file_extension(filename: str) -> str:
    (root, _extension) = os.path.splitext(filename)
    return root


def extract_extension(filename: str) -> str:
    (_root, extension) = os.path.splitext(filename)
    return extension


BUILD_FILENAME = 'build.ninja'
ninja_writer = ninja_syntax.Writer(open(BUILD_FILENAME, 'w'))
n = ninja_writer

SETTINGS_FILENAME = 'build_settings.yaml'
with open(SETTINGS_FILENAME, 'r') as read_file:
    settings = yaml.load(read_file, Loader=yaml.BaseLoader)

SCRIPT_NAME = os.path.basename(__file__)

n.comment('This file is generated using ' + SCRIPT_NAME +
          ' script, do not edit it by hand!')
n.comment('Settings are parsed from ' + SETTINGS_FILENAME + ' file')
n.newline()

n.variable('ninja_required_version', '1.8')
n.newline()
Beispiel #7
0
def main(_) -> None:
    build_dir().mkdir(exist_ok=True)
    preflight_out_dir().mkdir(exist_ok=True)
    waved_out_dir().mkdir(exist_ok=True)
    build_file = build_dir() / "build.ninja"
    err_file = (build_dir() / "warp_errors.log").resolve()
    with open(build_file, "w") as f:
        nw = ninja_syntax.Writer(f)

        if FLAGS.fail_on_error:
            util_path = rel_build(Path("naive_warp.py"))
            nw.rule(f"waveflag", f"python {util_path} --out_file $out $in")
            nw.newline()
            nw.rule(
                f"waveflag-no-border",
                f"python {util_path} --border_size 0 --out_file $out $in",
            )
            nw.newline()
        else:
            util_path = rel_build(Path("warp_runner.py"))
            nw.rule(
                f"waveflag",
                f"python {util_path} --err_file {err_file} --out_file $out $in",
            )
            nw.newline()
            nw.rule(
                f"waveflag-no-border",
                f"python {util_path} --noborder --err_file {err_file} --out_file $out $in",
            )
            nw.newline()

        util_path = rel_build(Path("flag_preflight.py"))
        nw.rule(f"preflight", f"python {util_path} --out_file $out $in")
        nw.newline()

        with open("wave_list.txt") as f:
            for line in f:
                line = line.strip()
                if not line or line.startswith("#"):
                    continue
                src_svg, wave_name, *options = (p.strip()
                                                for p in line.split(" "))
                waveflag_rule = "waveflag"
                if options and not bool(int(options[0])):
                    waveflag_rule = "waveflag-no-border"

                nw.build(
                    str(preflight_out_dir() / src_svg),
                    "preflight",
                    str(noto_dir() / src_svg),
                )

                nw.build(
                    str(waved_out_dir() / wave_name),
                    waveflag_rule,
                    str(preflight_out_dir() / src_svg),
                )

    ninja_cmd = ["ninja", "-C", os.path.dirname(build_file)]
    if FLAGS.exec_ninja:
        print(" ".join(ninja_cmd))
        if err_file.is_file():
            err_file.unlink()
        subprocess.run(ninja_cmd, check=True)
Beispiel #8
0
def _run(argv):
    additional_srcs = tuple(Path(f) for f in argv if f.endswith(".svg"))
    font_configs = config.load_configs(
        tuple(Path(f) for f in argv if f.endswith(".toml")),
        additional_srcs=additional_srcs,
    )
    if not font_configs:
        font_configs = (config.load(additional_srcs=additional_srcs), )

    os.makedirs(build_dir(), exist_ok=True)
    if FLAGS.gen_svg_font_diffs:
        os.makedirs(os.path.join(build_dir(), "resvg_png"), exist_ok=True)
        os.makedirs(os.path.join(build_dir(), "skia_png"), exist_ok=True)
        os.makedirs(os.path.join(build_dir(), "diff_png"), exist_ok=True)
    build_file = build_dir() / "build.ninja"

    assert not FLAGS.gen_svg_font_diffs or (
        len(font_configs)
        == 1), "Can only generate diffs for one font at a time"

    if len(font_configs) > 1:
        assert all(not _is_vf(c) for c in font_configs)

    logging.info(f"Proceeding with {len(font_configs)} config(s)")

    for font_config in font_configs:
        if _is_vf(font_config) and _is_svg(font_config):
            raise ValueError("svg formats cannot have multiple masters")
        _write_config_for_build(font_config)
        write_source_names(font_config)

    if FLAGS.gen_ninja:
        logging.info(f"Generating {build_file.relative_to(build_dir())}")
        with open(build_file, "w") as f:
            nw = ninja_syntax.Writer(f)
            write_preamble(nw)

            # Separate loops for separate content to keep related rules together

            for font_config in font_configs:
                for master in font_config.masters:
                    write_glyphmap_rule(nw, font_config, master)

            for font_config in font_configs:
                write_config_preamble(nw, font_config)

            for font_config in font_configs:
                write_fea_build(nw, font_config)

            for font_config in font_configs:
                for master in font_config.masters:
                    write_glyphmap_build(nw, font_config, master)

            picosvg_builds = set()
            for font_config in font_configs:
                for master in font_config.masters:
                    if not font_config.color_format.startswith("untouchedsvg"):
                        write_picosvg_builds(picosvg_builds, nw,
                                             font_config.clip_to_viewbox,
                                             master)
            nw.newline()

            for font_config in font_configs:
                if FLAGS.gen_svg_font_diffs:
                    assert not _is_vf(font_config)
                    write_svg_font_diff_build(nw, font_config.output_file,
                                              font_config.masters[0].sources)

                for master in font_config.masters:
                    if _is_vf(font_config):
                        write_ufo_build(nw, font_config, master)

            for font_config in font_configs:
                if _is_vf(font_config):
                    write_variable_font_build(nw, font_config)
                else:
                    write_static_font_build(nw, font_config)

    ninja_cmd = ["ninja", "-C", os.path.dirname(build_file)]
    if FLAGS.exec_ninja:
        logging.info(" ".join(ninja_cmd))
        subprocess.run(ninja_cmd, check=True)
    else:
        logging.info("To run: " + " ".join(ninja_cmd))