Example #1
0
    def test_embedded_dollar_dollar(self):
        self.n = ninja_syntax.Writer(self.out, width=15)  # force wrapping
        self.n.variable('foo', ['a$$b', '-somethinglong'], 0)
        self.assertEqual('''\
foo = a$$b $
    -somethinglong
''', self.out.getvalue())
Example #2
0
def do_build(args):
    """Top-level function called when running tuscan.py build."""
    logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s")

    if args.run == None:
        args.run = True
    if args.build == None:
        args.build = True

    timestamp = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
    args.touch_dir = os.path.join("output/results", args.toolchain, timestamp,
                                  "")

    ninja_file = "tuscan.ninja"
    with open(ninja_file, "w") as f:
        ninja = ninja_syntax.Writer(f, 72)
        create_build_file(args, ninja)

    if args.build:
        form = "%Y-%m-%d %H:%M:%S"
        sys.stderr.write(
            "Started build of toolchain %s at %s\n" %
            (args.toolchain, datetime.datetime.now().strftime(form)))
        rc = (run_ninja(args, ninja_file))
        sys.stderr.write(
            "Finished build of toolchain %s at %s\n" %
            (args.toolchain, datetime.datetime.now().strftime(form)))
        exit(rc)
def link_scan(deps_file, *inputs):
    objs = set()
    considered = set(inputs)
    queue = list(inputs)
    while queue:
        input = queue.pop()
        assert (input.endswith('.dd'))
        obj = input[:-3]
        objs.add(obj)
        _, deps = parse_flags_file(obj + '.flags')
        for dep in deps:
            if dep.startswith(mod_link_dir):
                continue  # no transitive link to imported named modules.
            objs.add(dep + '.o')
            continue

            # This shouldn't be needed. Leaving it so it can easily be enabled to check if it fixes issues.
            dyndep = dep + '.dd'
            if (dyndep not in considered):
                print('opening:', obj + '.flags')
                considered.add(dyndep)
                queue.append(dyndep)

    objs = sorted(objs)

    ninja = ninja_syntax.Writer(io.StringIO())
    ninja.variable('ninja_dyndep_version', 1)
    ninja.build(deps_file[:-len('.dd')], 'dyndep', implicit=objs)
    write_if_changed(ninja.output.getvalue(), deps_file, force=True)

    write_if_changed('\n'.join(objs), deps_file + '.flags', force=True)
Example #4
0
def main():
    src = Path("assets-src")
    assets = Path("assets-build")
    ninjafile = Path("build.ninja")
    n = ninja_syntax.Writer(ninjafile.open('w', encoding='utf-8'))
    n.variable("inkscape", "flatpak run org.inkscape.Inkscape")
    n.rule(name="svg2pdf", 
            command="$inkscape -z $in -A $out")
    n.rule(name="svg2pdflatex", 
            command="$inkscape -z $in -A $out --export-latex")

    src_pdf = src / Path("to_pdf")
    src_pdflatex = src / Path("to_pdflatex")

    def build(indir, rule):
        for f in (f for f in indir.iterdir() if f.is_file()):
            if f.suffix == ".svg":
                out = assets / f.with_suffix(".pdf").relative_to(indir)
                n.build(outputs=str(out),
                        rule=rule,
                        inputs=str(f))
    build(src_pdf, "svg2pdf")
    build(src_pdflatex, "svg2pdflatex")

    n.close()
    
    subprocess.run(['ninja'])
Example #5
0
    def write(self):
        # Defer touching the actual .ninja file until we are done building the contents to minimize
        # the window where the file isn't complete.
        content = io.BytesIO()

        # make ninja file directly executable. (bit set later)
        # can't use ninja.comment() because it adds a space after the !
        if self.globalEnv['NINJA']:
            content.write('#!%s -f\n\n' % self.globalEnv['NINJA'])

        ninja = ninja_syntax.Writer(content, width=100)
        ninja.comment('Generated by scons. DO NOT EDIT.')

        self.write_vars(ninja)
        self.write_rules(ninja)
        self.write_builds(ninja)
        self.write_regenerator(ninja)

        ninja.newline()
        for default in sorted(strmap(DEFAULT_TARGETS)):
            ninja.default(default)

        # Tell vim not to break up long lines.
        ninja.newline()
        ninja.comment('vim: set textwidth=0 :')

        with open(self.ninja_file, 'w') as file:
            file.write(content.getvalue())
        if self.globalEnv['NINJA'] and not self.globalEnv.TargetOSIs(
                'windows'):
            os.chmod(self.ninja_file, 0755)
Example #6
0
    def generate(self):
        import ninja_syntax
        import confu.globals
        confu.globals.build_ninja_path = os.path.join(self.root_dir,
                                                      "build.ninja")
        with open(confu.globals.build_ninja_path, "w") as build_ninja:
            # Minimal version with implicit outputs support
            build_ninja.write("ninja_required_version = 1.7\n")

            ninja = ninja_syntax.Writer(build_ninja)
            self.generate_variables(ninja)
            self.generate_rules(ninja)

            import sys
            configure_path = os.path.abspath(os.path.normpath(sys.argv[0]))
            args = sys.argv[1:]
            ninja.rule("configure",
                       configure_path + " $args",
                       description="CONFIGURE $args",
                       pool="console",
                       generator=True)
            ninja.rule("clean",
                       "ninja -f $config -t clean",
                       description="CLEAN",
                       pool="console")

            ninja.build("build.ninja",
                        "configure",
                        configure_path,
                        variables={"args": " ".join(args)})
            ninja.build("clean",
                        "clean",
                        variables={"config": confu.globals.build_ninja_path})

            self.modules._record(ninja)
Example #7
0
def read_dragon_configuration():
    f = open("DragonMake", 'r')
    config = yaml.safe_load(f)
    project_dirs = ''

    for i in config:
        if i == 'package_name':
            exports['package_name'] = config[i]
            continue
        elif i == 'install_command':
            exports['install_command'] = config[i]
            continue
        elif i == 'exports':
            exports.update(config[i])

        package_config = {'name': i, 'dir': '.'}
        package_config.update(config[i])
        project_config = process_package(package_config)

        f = open(f"{project_config['dir']}/build.ninja", 'w+')
        ninja = ninja_syntax.Writer(f)
        create_buildfile(ninja, project_config['type'], project_config)
        f.close()
        project_dirs = project_dirs + ' ' + project_config['dir']

    exports['project_dirs'] = project_dirs
Example #8
0
    def generate_ninja(self):
        winsdk_helper = WinSDKHelper()
        ninja = ninja_syntax.Writer(open(self.ninja_filename, "w+"))
        ninja.rule(
            "dxc",
            f"\"{winsdk_helper.dxc_path}\" $in -Fh $out -Od -Zi -Qembed_debug -all_resources_bound -H -T $target -Vn $header $defines"
        )

        header_files = []

        for shader_config in self.configs:
            filename = f"{SHADERS_DIR}/{shader_config['file']}"
            file_path = os.path.normpath(filename)
            name, _ = os.path.splitext(os.path.basename(file_path))
            header, _ = os.path.splitext(name)

            defines = dict()

            dxil_header = f"{name}_Compiled.h"
            header_files.append(dxil_header)
            target_map = {"CS": "cs_6_0", "VS": "vs_6_0", "PS": "ps_6_0"}

            ninja.build(dxil_header,
                        "dxc",
                        filename,
                        variables={
                            "target": target_map[shader_config["type"]],
                            "header": f"{header}_ShaderData"
                        } | defines)

        with open(f"{INTERMEDIATE_DIR}/CompiledShaders.h",
                  "w+") as compiled_shaders_h:
            for header_file in header_files:
                compiled_shaders_h.write(
                    f"#include \"{os.path.basename(header_file)}\"\n")
Example #9
0
    def test_leading_space(self):
        self.n = ninja_syntax.Writer(self.out, width=14)  # force wrapping
        self.n.variable('foo', ['', '-bar', '-somethinglong'], 0)
        self.assertEqual('''\
foo = -bar $
    -somethinglong
''', self.out.getvalue())
Example #10
0
def create_ninja_file():
    # Do this during execution to allow downloading the syntax file first.
    sys.path.insert(0, 'vendor/ninja/misc')
    import ninja_syntax

    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    buildfile = open('build.ninja', 'w')
    return ninja_syntax.Writer(buildfile)
Example #11
0
    def test_fit_many_words(self):
        self.n = ninja_syntax.Writer(self.out, width=78)
        self.n._line('command = cd ../../chrome; python ../tools/grit/grit/format/repack.py ../out/Debug/obj/chrome/chrome_dll.gen/repack/theme_resources_large.pak ../out/Debug/gen/chrome/theme_resources_large.pak', 1)
        self.assertEqual('''\
  command = cd ../../chrome; python ../tools/grit/grit/format/repack.py $
      ../out/Debug/obj/chrome/chrome_dll.gen/repack/theme_resources_large.pak $
      ../out/Debug/gen/chrome/theme_resources_large.pak
''',
                         self.out.getvalue())
Example #12
0
def write(platform, build_type, build_file_name):
    try:
        with open(build_file_name, 'w') as build_file:
            n = ninja_syntax.Writer(build_file)
            platform.write(n, build_type)

    except IOError:
        print('failed to write build file: ', build_file_name)
        raise
Example #13
0
def ninja(thing):
    n = ninja_syntax.Writer(open('.build.ninja~', 'w'))

    dest = os.path.join(mirror.dest_root, thing)

    n.variable('root', os.getcwd())
    n.variable('dest', dest)
    n.variable('thing', thing)
    n.variable('mirror', mirror.debian)
    if not os.path.isdir(dest):
        os.makedirs(dest)

    n.rule('gen', ['../casync.py', '$thing'])
    n.build('build.ninja', 'gen', '../casync.py', variables={'generator': 1})

    n.rule(
        'idx',
        ['../add-to-sync.sh', '$out', '$in', '$dest/default.castr', '$thing'])

    # 8/8 + 1 = 2 on a quad-core with hyperthreading
    # 32/8 + 1 = 5 on a 32vCPU instance

    n.pool('huge', int(multiprocessing.cpu_count() / 8) + 1)
    n.pool('medium', int(multiprocessing.cpu_count() / 4) + 1)

    for dsc_path in mirror.all_dscs():
        dsc = mirror.read_dsc(dsc_path)
        src = dsc['Source']
        ver = dsc['Version']

        total_compressed = sum(int(file['size']) for file in dsc['Files'])

        # Rule of thumb: ~200mb packages expand to 2-3gb.
        # 64gb of ram for 32 cores -> 2gb of cache per core
        if total_compressed > 100 * 1024 * 1024:
            pool = 'huge'
        elif total_compressed > 10 * 1024 * 1024:
            pool = 'medium'
        else:
            pool = None

        if src.startswith('lib'):
            prefix = src[0:4]
        else:
            prefix = src[0]

        n.build('$dest/{}/{}/{}.caidx'.format(prefix, src, ver),
                'idx',
                '$mirror' + dsc_path,
                implicit='../add-to-sync.sh',
                variables={
                    'description': '{} {} {}'.format(thing, src, ver),
                    'pool': pool
                })

    n.close()
    os.rename('.build.ninja~', 'build.ninja')
Example #14
0
def FileWriter(path):
    """Context manager for a ninja_syntax object writing to a file."""
    try:
        os.makedirs(os.path.dirname(path))
    except OSError:
        pass
    f = open(path, 'w')
    yield ninja_syntax.Writer(f)
    f.close()
Example #15
0
def test_fails_input_file_missing(gbcli, tmp_path):
    build_file_path = tmp_path / "build.ninja"
    with build_file_path.open("wt") as build_file:
        writer = ninja_syntax.Writer(output=build_file)
        writer.rule("capitalize", "dd if=$in of=$out conv=ucase")
        writer.build("loremipsum.txt.u", "capitalize", "loremipsum.txt")

    with raises(CalledProcessError) as exc_info:
        gbcli(cwd=tmp_path)
    assert "error: 'loremipsum.txt', needed by 'loremipsum.txt.u', missing and no known rule to make it" in exc_info.value.output
Example #16
0
 def __init__(self, config_file_handle):
     self.__config_file_handle = config_file_handle
     # only generate action 0
     self.__output_dir = config_file_handle.get_config_file_action_output_dir(
         0)
     if os.path.exists(self.__output_dir) == False:
         os.mkdir(self.__output_dir)
     # gen build.ninja
     f = open(os.path.join(self.__output_dir, "build.ninja"), "w")
     self.__ninja_handle = ninja_syntax.Writer(f)
Example #17
0
    def _generate(self, output, newline=True):
        writer = ninja_syntax.Writer(output)
        writer.comment('This file is generated by Ninju v{} ({})'.format(
            NINJU_VERSION, NINJU_URL))
        writer.newline()

        for task in self._seq:
            task.write(writer)
            if newline:
                writer.newline()
        return writer
Example #18
0
def main():
    target = 'nest'
    srcdir = 'src'
    inputdir = joinp('whitgl', 'input')
    builddir = 'build'
    targetdir = joinp(builddir, 'out')
    if build.plat == 'Darwin':
        packagedir = joinp(targetdir, 'Nest.app', 'Contents')
        executabledir = joinp(packagedir, 'MacOS')
        data_out = joinp(packagedir, 'Resources', 'data')
    else:
        executabledir = targetdir
        data_out = joinp(targetdir, 'data')
    objdir = joinp(builddir, 'obj')
    libdir = joinp(builddir, 'lib')
    data_in = 'data'
    buildfile = open(joinp('build', 'build.ninja'), 'w')
    n = ninja_syntax.Writer(buildfile)
    cflags, ldflags = build.flags(inputdir)
    cflags += ' -Iwhitgl/inc -Isrc -g -O2'
    n.variable('cflags', cflags)
    n.variable('ldflags', ldflags)
    n.variable('scripts_dir', joinp('whitgl', 'scripts'))
    build.rules(n)
    if build.plat == 'Windows':
        n.rule('windres',
               command='windres $in -O coff -o $out',
               description='windres $out')
    obj = build.walk_src(n, srcdir, objdir)
    if build.plat == 'Windows':
        obj += n.build(joinp(objdir, 'icon.res'), 'windres',
                       joinp(data_in, 'win', 'nest.rc'))
    whitgl = [joinp('whitgl', 'build', 'lib', 'whitgl.a')]
    targets = []
    targets += n.build(joinp(executabledir, target), 'link', obj + whitgl)
    n.newline()

    data = build.walk_data(n, data_in, data_out)

    targets += n.build('data', 'phony', data)
    n.newline()

    targets += build.copy_libs(n, inputdir, executabledir)

    if build.plat == 'Darwin':
        targets += n.build(joinp(packagedir, 'Info.plist'), 'cp',
                           joinp(data_in, 'osx', 'Info.plist'))
        targets += n.build(joinp(packagedir, 'Resources', 'Nest.icns'), 'cp',
                           joinp(data_in, 'osx', 'Nest.icns'))

    n.build('all', 'phony', targets)
    n.default('all')
Example #19
0
    def __init__(self, options):
        self.output = open("build.ninja", "w")
        self.writer = ninja_syntax.Writer(self.output)
        self.source_dir = None
        self.build_dir = None
        self.artifact_dir = None
        self.prefix_dir = options.prefix
        self.include_dirs = []
        self.object_ext = ".bc"

        # Variables
        self.writer.variable("nacl_sdk_dir", options.nacl_sdk)
        self._set_pnacl_vars()
        self.writer.variable("cflags", "-std=gnu11")
        self.writer.variable("cxxflags", "-std=gnu++11")
        self.writer.variable("optflags", "-O3")

        # Rules
        self.writer.rule(
            "cc",
            "$pnacl_cc -o $out -c $in -MMD -MF $out.d $optflags $cflags $includes",
            deps="gcc",
            depfile="$out.d",
            description="CC[PNaCl] $descpath")
        self.writer.rule(
            "cxx",
            "$pnacl_cxx -o $out -c $in -MMD -MF $out.d $optflags $cxxflags $includes",
            deps="gcc",
            depfile="$out.d",
            description="CXX[PNaCl] $descpath")
        self.writer.rule("ccld",
                         "$pnacl_cc -o $out $in $libs $libdirs $ldflags",
                         description="CCLD[PNaCl] $descpath")
        self.writer.rule("cxxld",
                         "$pnacl_cxx -o $out $in $libs $libdirs $ldflags",
                         description="CXXLD[PNaCl] $descpath")
        self.writer.rule("ar",
                         "$pnacl_ar rcs $out $in",
                         description="AR[PNaCl] $descpath")
        self.writer.rule("finalize",
                         "$pnacl_finalize $finflags -o $out $in",
                         description="FINALIZE[PNaCl] $descpath")
        self.writer.rule("translate",
                         "$pnacl_translate -arch $arch -o $out $in",
                         description="TRANSLATE[PNaCl] $descpath")
        self.writer.rule("run",
                         "$pnacl_sel_ldr $in",
                         description="RUN[PNaCl] $descpath",
                         pool="console")
        self.writer.rule("install",
                         "install -m $mode $in $out",
                         description="INSTALL $out")
Example #20
0
def do_game(name, extra_cflags, data_types):
    target = name.lower()
    srcdir = 'src'
    inputdir = joinp('whitgl', 'input')
    builddir = 'build'
    targetdir = joinp(builddir, 'out')
    if plat == 'Darwin':
        packagedir = joinp(targetdir, '%s.app' % name, 'Contents')
        executabledir = joinp(packagedir, 'MacOS')
        data_out = joinp(packagedir, 'Resources', 'data')
    else:
        executabledir = targetdir
        data_out = joinp(targetdir, 'data')
    objdir = joinp(builddir, 'obj')
    libdir = joinp(builddir, 'lib')
    data_in = 'data'
    if not os.path.exists('build'):
        os.makedirs('build')
    buildfile = open(joinp('build', 'build.ninja'), 'w')
    n = ninja_syntax.Writer(buildfile)
    n.variable('builddir', builddir)
    n.variable('scriptsdir', joinp('whitgl', 'scripts'))
    n.newline()
    cflags, ldflags = flags(inputdir)
    cflags = cflags + ' -Iwhitgl/inc -Isrc ' + extra_cflags
    n.variable('cflags', cflags)
    n.variable('ldflags', ldflags)
    n.newline()
    rules(n)
    obj = walk_src(n, srcdir, objdir)
    whitgl = [joinp('whitgl', 'build', 'lib', 'whitgl.a')]
    targets = []
    targets += n.build(joinp(executabledir, target), 'link', obj + whitgl)
    n.newline()

    data = walk_data(n, data_in, data_out, data_types)

    targets += n.build('data', 'phony', data)
    n.newline()

    targets += copy_libs(n, inputdir, executabledir)

    if plat == 'Darwin':
        targets += n.build(joinp(packagedir, 'Info.plist'), 'cp',
                           joinp(data_in, 'osx', 'Info.plist'))
        targets += n.build(joinp(packagedir, 'Resources', 'Icon.icns'), 'icon',
                           joinp('art', 'icon', 'icon.png'))

    n.build('all', 'phony', targets)
    n.default('all')
Example #21
0
    def __enter__(self):
        # Context manager object can be reused: if this is the case
        # we will append the new commands to the file.
        self.n = ninja_syntax.Writer(self.ninjafile.open('a',
                                                         encoding='utf-8'))

        self.n.variable('FFMPEG', "ffmpeg -y -threads 0")

        # !!!!! The order is important !!!! You should lenscorrect BEFORE applying
        # video stabilization, as lenscorrect uses the center of the image as a reference,
        # and vidstab moves things around.

        FMT422 = "format=yuv422p"
        FMT444 = "format=yuv444p"

        LENSCORRECT = 'lenscorrection=cx=0.5:cy=0.5:k1=-0.227:k2=0.045'

        LENSCORRECT_FILTER = ','.join([FMT444, LENSCORRECT, FMT422])
        self.n.rule(name='lenscorrect',
                    command=('$FFMPEG $pre_args '
                             '-i $in '
                             f'-filter:v {LENSCORRECT_FILTER} '
                             '-c:a copy '
                             '-c:v dnxhd -profile:v dnxhr_sq '
                             '$out'))

        # "Note the use of the ffmpeg's unsharp filter which is always
        # recommended." (https://github.com/georgmartius/vid.stab)
        VIDSTAB_DETECT = "vidstabdetect=result=$out"
        VIDSTAB_TRANSFORM = 'vidstabtransform=input="$in_stab"'
        UNSHARP = 'unsharp=5:5:0.8:3:3:0.4'

        PASS1_FILTER = ','.join([FMT444, VIDSTAB_DETECT])
        PASS2_FILTER = ','.join([FMT444, VIDSTAB_TRANSFORM, UNSHARP, FMT422])
        self.n.rule(name='vidstab-pass1',
                    command=('$FFMPEG $pre_args '
                             '-i $in '
                             f'-filter:v  {PASS1_FILTER} '
                             '-f null -'))  # out must be a .trf file
        self.n.rule(name='vidstab-pass2',
                    command=('$FFMPEG $pre_args '
                             '-i $infile '
                             f'-filter:v {PASS2_FILTER} '
                             '-c:a copy '
                             '-c:v dnxhd -profile:v dnxhr_sq '
                             '$out'))
        # A note on dnxhr: `-c:v dnxhd profile:v dnxhr_sq` is equivalent to `-c:v dnxhd -b:v 145M`
        # but is framerate and resolution independant
        # /!\ with profile dnxhr_sd, the format is necessarily yuv422p.
        return self
Example #22
0
def main(argv):
    n = ninja_syntax.Writer(open('build.ninja', 'w'))

    n.comment('Translate, compile, and test mycpp examples.')
    n.comment('Generated by %s.' % os.path.basename(__file__))
    n.newline()

    n.rule('translate',
           command='./run.sh ninja-translate $in $out',
           description='translate $in $out')
    n.newline()
    n.rule('compile',
           command='./run.sh ninja-compile $variant $in $out',
           description='compile $variant $in $out')
    n.newline()

    # TODO:
    # _ninja/
    #   logs/  # side effects
    #     typecheck/  # optional?
    #     translate/
    #     compile/
    #     test/
    #     benchmark/
    #   tasks/  # these are proper outputs, at least for test and benchmark?
    #     typecheck/  # optional?
    #     translate/
    #     compile/
    #     test/
    #     benchmark/
    #
    #   gen/    # source
    #   bin/    # binaries

    examples = ['cgi', 'containers']
    for ex in examples:
        n.build('_ninja/gen/%s.cc' % ex, 'translate', 'examples/%s.py' % ex)
        n.newline()

        # TODO: Can also parameterize by CXX: Clang or GCC.
        for variant in ['gc_debug', 'asan', 'opt']:
            n.build('_ninja/bin/%s.$variant' % ex,
                    'compile',
                    '_ninja/gen/%s.cc' % ex,
                    variables=[('variant', variant)])
            n.newline()
Example #23
0
    def __generate_headers__(self):
        with PushDir(self.args.dir) as dir:
            shutil.rmtree(dir)
        dag_levels = self.__generate_dag__()
        executor = Executor(self.args.jobs)
        id_t = 'h%s'
        with PushDir(self.args.dir) as dir:
            ninja_file = open(os.path.join(dir, 'build.ninja'), 'w')
            ninja = ninja_syntax.Writer(ninja_file, width=100)

            ninja.variable('CXXFLAGS', '-c -std=c++2a -O0 -x c++')
            ninja.rule(
                'CXX',
                command='"{cxx}" $CXXFLAGS $in -o $out'.format(cxx=self.cxx),
                description='CXX $out')

            dag_deps = {}
            for dag_level in dag_levels:
                for m in dag_level:
                    m_cpp = os.path.join(dir, id_t % (m['index']) + '.cpp')
                    executor.add_task([self.__compile_headers__, m_cpp],
                                      m['index'], [])
                    dag_deps[m['index']] = m['deps']
            for n in range(int(self.args.count)):
                id = id_t % (n)
                hpp = os.path.join(dir, id + '.hpp')
                cpp = os.path.join(dir, id + '.cpp')
                obj = os.path.join(dir, id + '.o')
                deps = [id_t % (n) for n in dag_deps[n]]
                source = self.__make_headers_source__(id, deps)
                ninja.build(obj, 'CXX', cpp)
                ninja.default(obj)
                if self.args.debug:
                    print('FILE: %s' % (hpp))
                    print(source[0])
                    print('-----')
                    print('FILE: %s' % (cpp))
                    print(source[1])
                    print('-----')
                else:
                    with open(hpp, 'w') as f:
                        f.write(source[0])
                    with open(cpp, 'w') as f:
                        f.write(source[1])
        return executor
Example #24
0
def main():
    target = 'whitgl.a'
    srcdir = 'src'
    examplesrcdir = 'example'
    inputdir = 'input'
    builddir = 'build'
    exampledir = joinp(builddir, 'example')
    objdir = joinp(builddir, 'obj')
    libdir = joinp(builddir, 'lib')
    data_in = joinp(examplesrcdir, 'data')
    data_out = joinp(exampledir, 'data')
    if not os.path.exists('build'):
        os.makedirs('build')
    buildfile = open(joinp('build', 'build.ninja'), 'w')
    n = ninja_syntax.Writer(buildfile)
    n.variable('builddir', builddir)
    n.variable('scriptsdir', 'scripts')
    n.newline()
    cflags, ldflags = flags('input')
    n.variable('cflags', cflags)
    n.variable('ldflags', ldflags)
    n.newline()
    rules(n)
    # Library
    obj = walk_src(n, srcdir, objdir)
    staticlib = n.build(joinp(libdir, target), 'static', obj)
    targets = []
    targets += staticlib
    n.newline()

    # Example
    obj = walk_src(n, examplesrcdir, objdir)
    targets += n.build(joinp(exampledir, 'example'), 'link', obj + staticlib)
    n.newline()

    data = walk_data(n, data_in, data_out)

    targets += n.build('data', 'phony', data)
    n.newline()

    targets += copy_libs(n, inputdir, exampledir)

    n.build('all', 'phony', targets)
    n.default('all')
Example #25
0
def main():
    target = 'bloodworm'
    srcdir = 'src'
    inputdir = joinp('whitgl', 'input')
    builddir = 'build'
    targetdir = joinp(builddir, 'out')
    if build.plat == 'Darwin':
        packagedir = joinp(targetdir, 'Bloodworm.app', 'Contents')
        executabledir = joinp(packagedir, 'MacOS')
        data_out = joinp(packagedir, 'Resources', 'data')
    else:
        executabledir = targetdir
        data_out = joinp(targetdir, 'data')
    objdir = joinp(builddir, 'obj')
    libdir = joinp(builddir, 'lib')
    data_in = 'data'
    buildfile = open('build.ninja', 'w')
    n = ninja_syntax.Writer(buildfile)
    cflags = build.cflags + ' -Iwhitgl/inc -Isrc'
    build.rules(n, cflags, build.ldflags)
    #if build.plat == 'Windows':
    #  n.rule('windres', command='windres $in -O coff -o $out', description='windres $out')
    obj = build.walk_src(n, srcdir, objdir)
    #if build.plat == 'Windows':
    #  obj += n.build(joinp(objdir, 'icon.res'), 'windres', joinp(data_in, 'win', 'Bloodworm.rc'))
    whitgl = [joinp('whitgl', 'build', 'lib', 'whitgl.a')]
    targets = []
    targets += n.build(joinp(executabledir, target), 'link', obj + whitgl)
    n.newline()

    data = build.walk_data(n, data_in, data_out, ['png', 'ogg', 'lvl', 'wav'])

    targets += n.build('data', 'phony', data)
    n.newline()

    targets += build.copy_libs(n, inputdir, executabledir)

    if build.plat == 'Darwin':
        targets += n.build(joinp(packagedir, 'Info.plist'), 'cp',
                           joinp(data_in, 'osx', 'Info.plist'))

    n.build('all', 'phony', targets)
    n.default('all')
Example #26
0
def outer(argv0, args):
    use_custom_otangle = '--use-custom-otangle' in args
    if use_custom_otangle:
        args.remove('--use-custom-otangle')

    build_book_tex = '--build-book-tex' in args
    if build_book_tex:
        args.remove('--build-book-tex')

    underscores = '--underscores' in args
    if underscores:
        args.remove('--underscores')

    build = Path('')
    me = Path(argv0).parent
    src = Path(args[0])

    with (build / 'build.ninja').open('wt') as f:
        w = ninja_syntax.Writer(f)
        inner(src, build, w, use_custom_otangle, build_book_tex, underscores)
def scan_header_unit(raw, header_name, dyndeps, pcmflags):
    #TODO this will eventually need to handle named module imports from headers,
    #     but since clang currently chokes on those I'm omitting it as a simplification.
    _, sources = parse_makefile(raw)
    source_mods = []
    source_reals = set()
    hu_reals = {}

    # This is an O(N + M) algorithm for checking os.samefile() on
    # every file in sources against every file in header_units
    def file_id(path):
        stat = os.stat(path)
        return (stat.st_dev, stat.st_ino)

    self_id = file_id(header_name)
    for s in sources:
        s_id = file_id(s)
        if s_id != self_id:  # the input header is listed as a source
            source_reals.add(s_id)

    for hu in header_units:
        hu_reals[file_id(hu)] = to_out_base(hu) + '.pcm'

    for s in source_reals:
        if s in hu_reals:
            source_mods.append(hu_reals[s])

    pcm = to_out_base(header_name) + '.pcm'

    ninja = ninja_syntax.Writer(io.StringIO())
    ninja.variable('ninja_dyndep_version', 1)
    ninja.build(pcm, 'dyndep', implicit=source_mods)

    # XXX because the flags file isn't in the ninja deps graph, restat isn't quite safe :(
    write_if_changed(ninja.output.getvalue(), dyndeps)

    write_if_changed(''.join(f'-fmodule-file={s}\n' for s in source_mods),
                     pcmflags)
Example #28
0
    def write(self):
        file = open(self.ninja_file, 'w')

        # make ninja file directly executable. (bit set later)
        # can't use ninja.comment() because it adds a space after the !
        if self.globalEnv['NINJA']:
            file.write('#!%s -f\n\n' % self.globalEnv['NINJA'])

        ninja = ninja_syntax.Writer(file, width=100)
        ninja.comment('Generated by scons. DO NOT EDIT.')

        self.write_vars(ninja)
        self.write_rules(ninja)
        self.write_builds(ninja)
        self.write_regenerator(ninja)

        ninja.newline()
        for default in sorted(strmap(DEFAULT_TARGETS)):
            ninja.default(default)

        ninja.close()
        if self.globalEnv['NINJA'] and not self.globalEnv.TargetOSIs(
                'windows'):
            os.chmod(self.ninja_file, 0755)
Example #29
0
    def write(self, outputNinjaFname="build.ninja"):
        f = open(outputNinjaFname, "w")
        with closing(ninja.Writer(f)) as w:
            w.comment("Variables")
            w.variable("ncpus", "8")
            w.variable("scratchDir", "/scratch")
            if self._grid:
                w.variable("sgeQueue", self._sgeQueue)
                w.variable("grid", "qsub -q $sgeQueue -sync y -cwd -V -b y -e log -o log")
                w.variable("gridSMP", "$grid -pe smp $ncpus")
            else:
                w.variable("grid", "")
                w.variable("gridSMP", "")
            w.newline()
            w.comment("Rules")
            for rule in self._rules.items():
                w.rule(*rule)
                w.newline()
            w.newline()
            w.comment("Build targets")
            for buildStmt in self._buildStmts:
                w.build(buildStmt.outputs, buildStmt.rule, buildStmt.inputs,
                        variables=buildStmt.variables)
                w.newline()

        # Install the bundled resources
        for br in self._resourcesToBundle:
            resSrcPath = getResourcePath(br.resourceName)
            resDestPath = br.destPath or br.resourceName
            mkdirp(op.dirname(resDestPath))
            if not br.substitutions:
                shutil.copy(resSrcPath, resDestPath)
            else:
                tContent = readFile(resSrcPath)
                t = jinja2.Template(tContent)
                writeFile(resDestPath, t.render(br.substitutions))
Example #30
0
parser.add_option('--force-pselect', action='store_true',
                  help='ppoll() is used by default where available, '
                       'but some platforms may need to use pselect instead',)
(options, args) = parser.parse_args()
if args:
    print('ERROR: extra unparsed command-line arguments:', args)
    sys.exit(1)

platform = Platform(options.platform)
if options.host:
    host = Platform(options.host)
else:
    host = platform

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

if options.bootstrap:
    # Make the build directory.
    try:
        os.mkdir('build')
    except OSError:
        pass
    # Wrap ninja_writer with the Bootstrapper, which also executes the
    # commands.
    print('bootstrapping ninja...')
    n = Bootstrap(n, verbose=options.verbose)

n.comment('This file is used to build ninja itself.')
n.comment('It is generated by ' + os.path.basename(__file__) + '.')