Example #1
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("grid", "qsub -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.iteritems():
             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()
     # Bundle the scripts
     for (scriptName, scriptSrcPath) in self._scriptsToBundle.iteritems():
         scriptDestPath = scriptName
         mkdirp(op.dirname(scriptDestPath))
         shutil.copy(scriptSrcPath, scriptDestPath)
         chmodPlusX(scriptDestPath)
Example #2
0
 def __init__(self, name):
     import ninja
     if not os.path.exists(BUILD_DIR):
         os.mkdir(BUILD_DIR)
     self.ninja_program = os.path.join(ninja.BIN_DIR, 'ninja')
     self.name = name
     self.filename = os.path.join(BUILD_DIR, 'build.{}.ninja'.format(name))
     self.writer = ninja.Writer(open(self.filename, 'w'))
     self.writer.rule('do_cmd', '$cmd')
     self.writer.rule('compile', '$cmd')
     self.compdb_targets = []
Example #3
0
    def __init__(self, options, ninja_build_file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "build.ninja")):
        self.output = open(ninja_build_file, "w")
        self.writer = ninja.Writer(self.output)
        self.source_dir = None
        self.build_dir = None
        self.artifact_dir = None
        self.include_dirs = []
        self.object_ext = ".bc"

        emflags = [
            "EXPORTED_FUNCTIONS=\"['_runBenchmark','_main','_malloc','_free']\"",
            "DISABLE_EXCEPTION_CATCHING=1",
            "TOTAL_MEMORY=83886080",
            "ALLOW_MEMORY_GROWTH=0",
            "FORCE_ALIGNED_MEMORY=1",
            "PRECISE_F32=0",
            "GC_SUPPORT=0",
            "NO_EXIT_RUNTIME=1"
        ]

        # Variables
        self.writer.variable("nacl_sdk_dir", options.nacl_sdk)
        self._set_pnacl_vars()
        self.writer.variable("emscripten_blis_dir", options.emscripten_blis)
        self.writer.variable("cflags", "-std=c99")
        self.writer.variable("optflags", "-O3")
        self.writer.variable("emflags", " ".join(map(lambda emflag: "-s " + emflag, emflags)))

        # Rules
        self.writer.rule("EMCC", "emcc -o $out -c $in -MMD -MF $out.d $optflags $cflags $includes",
            deps="gcc", depfile="$out.d",
            description="CC[Emscripten] $descpath")
        self.writer.rule("EMCCLD", "emcc -o $out $in $optflags $libs $libdirs $ldflags $emflags",
            description="CCLD[Emscripten] $descpath")
        self.writer.rule("PNACLCC", "$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("PNACLCCLD", "$pnacl_cc -o $out $in $libs $libdirs $ldflags",
            description="CCLD[PNaCl] $descpath")
        self.writer.rule("PNACLFINALIZE", "$pnacl_finalize $finflags -o $out $in",
            description="FINALIZE[PNaCl] $descpath")
        self.writer.rule("CONCATENATE", "cat $in > $out",
            description="CONCATENATE $out")
        self.writer.rule("UGLIFYJS", "uglifyjs $in > $out",
            description="UGLIFYJS $out")
Example #4
0
def generate(build_file, release):
    with open(build_file, 'w') as f, \
            contextlib.closing(ninja.Writer(f, width=120)) as n:
        n.variable('builddir', 'build')
        n.variable('projectdir', '.')
        n.variable('cxx', 'clang++')
        n.variable('cxxflags',
                   '-c -fcolor-diagnostics -fpic -Wall -Wextra -Werror -std=c++17'
                   ' {variant_flags} {include_flags}'.format(
                       variant_flags=('-O3 -mtune=native'
                                      if release else
                                      '-O0 -g -fprofile-instr-generate -fcoverage-mapping'),
                       include_flags=' '.join([
                           '-isystem {}'.format(os.environ['CATCH_HOME']),
                           '-isystem {}'.format(os.environ['BOOST_HOME']),
                           '-isystem {}/include'.format(os.environ['LLVM_HOME']),
                       ]),
                   ))
        n.variable('linkflags', '-Wl,--no-undefined {variant_flags}'.format(
            variant_flags='' if release else '-fprofile-instr-generate -fcoverage-mapping'))
        n.variable('libs', '-L{}/lib -lLLVM-8'.format(os.environ['LLVM_HOME']))

        n.rule('cxx', '$cxx $cxxflags $in -MMD -MF $out.d -o $out', depfile='$out.d', deps='gcc')
        n.rule('link', '$cxx $linkflags $in -o $out $libs')
        n.rule('ar', 'rm -f $out && ar crs $out $in')

        # Main build

        for cpp in find_files('src', include='.cpp$'):
            n.build('$builddir/obj/{}.o'.format(stripext(cpp)),
                    'cxx',
                    '$projectdir/src/{}'.format(cpp))

        n.build('$builddir/libwold.a',
                'ar',
                ['$builddir/obj/{}.o'.format(stripext(cpp))
                 for cpp in find_files('src', include='.cpp$', exclude='test/')])

        n.build('$builddir/tests',
                'link',
                ['$builddir/obj/{}.o'.format(stripext(cpp)) for cpp in glob_from('src', 'test/*.cpp')],
                variables=dict(libs='-L$builddir -lwold $libs'),
                implicit='$builddir/libwold.a')
Example #5
0
    def _build_with_ninja(self, ext):
        import ninja

        build_file = os.path.join(TOP_DIR, 'build.{}.ninja'.format(ext.name))
        log.debug('Ninja build file at {}'.format(build_file))
        w = ninja.Writer(open(build_file, 'w'))

        w.rule('compile', '$cmd')
        w.rule('link', '$cmd')

        @contextmanager
        def patch(obj, attr_name, val):
            orig_val = getattr(obj, attr_name)
            setattr(obj, attr_name, val)
            yield
            setattr(obj, attr_name, orig_val)

        orig_compile = distutils.unixccompiler.UnixCCompiler._compile
        orig_link = distutils.unixccompiler.UnixCCompiler.link

        def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
            depfile = os.path.splitext(obj)[0] + '.d'

            def spawn(cmd):
                w.build([obj],
                        'compile', [src],
                        variables={
                            'cmd': cmd,
                            'depfile': depfile,
                            'deps': 'gcc'
                        })

            extra_postargs.extend(['-MMD', '-MF', depfile])
            with patch(self, 'spawn', spawn):
                orig_compile(self, obj, src, ext, cc_args, extra_postargs,
                             pp_opts)

        def link(self,
                 target_desc,
                 objects,
                 output_filename,
                 output_dir=None,
                 libraries=None,
                 library_dirs=None,
                 runtime_library_dirs=None,
                 export_symbols=None,
                 debug=0,
                 extra_preargs=None,
                 extra_postargs=None,
                 build_temp=None,
                 target_lang=None):

            w.close()
            ninja._program('ninja', ['-f', build_file])

            orig_link(self, target_desc, objects, output_filename, output_dir,
                      libraries, library_dirs, runtime_library_dirs,
                      export_symbols, debug, extra_preargs, extra_postargs,
                      build_temp, target_lang)

        with patch(distutils.unixccompiler.UnixCCompiler, '_compile',
                   _compile):
            with patch(distutils.unixccompiler.UnixCCompiler, 'link', link):
                with patch(self, 'force', True):
                    self._build_default(ext)
Example #6
0
    def __init__(self,
                 options,
                 ninja_build_file=os.path.join(
                     os.path.dirname(os.path.abspath(__file__)),
                     "build.ninja")):
        self.output = open(ninja_build_file, "w")
        self.writer = ninja.Writer(self.output)
        self.source_dir = None
        self.build_dir = None
        self.artifact_dir = None
        self.object_ext = ".o"

        use_icc = detect_intel_compiler(options.cc)
        use_ifort = detect_intel_compiler(options.fc)

        if use_icc:
            cflags = Configuration._cflags_intel_map[options.arch]
        else:
            cflags = Configuration._cflags_gnu_map[options.arch]
        if options.offload:
            cflags += Configuration._offload_cflags
        else:
            cflags += ["-D__ERD_PROFILE__"]
            if use_icc:
                cflags += ["-offload=none", "-diag-disable", "161,2423"]
        cflags += Configuration._extra_cflags
        fflags = []
        if use_ifort:
            fflags = Configuration._fflags_intel_map[options.arch]
        else:
            fflags = Configuration._fflags_gnu_map[options.arch]
        fflags += Configuration._extra_fflags
        ldflags = Configuration._extra_ldflags

        cflags = " ".join(cflags)
        if options.cflags:
            cflags = cflags + " " + options.cflags
        fflags = " ".join(fflags)
        if options.fflags:
            fflags = fflags + " " + options.fflags
        ldflags = " ".join(ldflags)
        if options.ldflags:
            ldflags = ldflags + " " + options.ldflags

        # Variables
        self.writer.variable("fc", options.fc)
        self.writer.variable("fflags", fflags)
        self.writer.variable("cc", options.cc)
        self.writer.variable("cflags", cflags)
        self.writer.variable("ldflags", ldflags)
        self.writer.variable("ar", options.ar)
        if options.offload:
            self.writer.variable("arflags", "-qoffload-build")

        # Rules
        self.writer.rule(
            "CC",
            "$cc $cflags $includes -MMD -MT $out -MF $out.d -o $out -c $in",
            description="CC $descpath",
            depfile="$out.d")
        self.writer.rule("FC",
                         "$fc $fflags -o $out -c $in",
                         description="FC $descpath")
        self.writer.rule("CCLD",
                         "$cc -o $out $objs $libdirs $libs $ldflags",
                         description="CCLD $descpath")
        self.writer.rule("AR",
                         "$ar $arflags rcs $out $in",
                         description="AR $descpath")
Example #7
0
platform = options.platform
if platform is None:
    platform = sys.platform
    if platform.startswith('linux'):
        platform = 'linux'
    elif platform.startswith('freebsd'):
        platform = 'freebsd'
    elif platform.startswith('mingw'):
        platform = 'mingw'
    elif platform.startswith('win'):
        platform = 'windows'

BUILD_FILENAME = 'build.ninja'
buildfile = open(BUILD_FILENAME, 'w')
n = ninja.Writer(buildfile)
n.comment('This file is used to build ninja itself.')
n.comment('It is generated by ' + os.path.basename(__file__) + '.')
n.newline()


def src(filename):
    return os.path.join('src', filename)


def built(filename):
    return os.path.join('$builddir', filename)


def doc(filename):
    return os.path.join('doc', filename)