def _link(self, linker, src, dst=None, *, includes=[], macros=[], cflags=[], libs=[], lflags=[], objects=[], buildroot=None): buildroot = buildroot or self.ctx.buildroot src = Path(src) if dst is None: dst = src.replaceext('') dst = Path(dst).addroot(buildroot) obj = self.cxx.compile(src, includes=includes, macros=macros, buildroot=buildroot, flags=cflags) return linker(dst, list(chain(objects, [obj])), libs=libs, flags=lflags, buildroot=buildroot)
def copy_dir_to(ctx, dstdir, srcdir, *, pattern=None) -> fbuild.db.DSTS: #print("Copy dir to: from srcdir = " + # str(srcdir) + ", pattern=" + str(pattern) + # ", to " + str(dstdir)) srcdir = Path(srcdir) srcs = [] dsts = [] for src in srcdir.find(pattern=pattern, include_dirs=False): dst = src.removeroot(srcdir+os.sep).addroot(dstdir) dst.parent.makedirs() srcs.append(src) dsts.append(dst) #ctx.logger.check(' * copy', '%s -> %s' % (src, dst), color='yellow') try: src.copy(dst) except shutil.SameFileError: pass ctx.db.add_external_dependencies_to_call(srcs=srcs) return dsts
def test_flx(phase, felix, src, *args, **kwargs): src = Path(src) passed = True for static in False, True: try: exe = felix.compile(src, static=static, flags=["--usage=prototype"]) except fbuild.ExecutionError as e: phase.ctx.logger.log(e, verbose=1) if e.stdout: phase.ctx.logger.log(e.stdout.decode("utf-8", "ignore").strip(), verbose=1) if e.stderr: phase.ctx.logger.log(e.stderr.decode("utf-8", "ignore").strip(), verbose=1) passed = False continue if static: dst = exe + ".static.stdout" else: dst = exe + ".shared.stdout" expect = src.replaceext(".expect") passed &= check_flx( phase.ctx, felix, *args, exe=exe, dst=dst, expect=expect if expect.exists() else None, static=static, **kwargs ) return passed
def copy_dir_to(ctx, dstdir, srcdir, *, pattern=None) -> fbuild.db.DSTS: #print("Copy dir to: from srcdir = " + # str(srcdir) + ", pattern=" + str(pattern) + # ", to " + str(dstdir)) srcdir = Path(srcdir) srcs = [] dsts = [] for src in srcdir.find(pattern=pattern, include_dirs=False): dst = src.removeroot(srcdir + os.sep).addroot(dstdir) dst.parent.makedirs() srcs.append(src) dsts.append(dst) #ctx.logger.check(' * copy', '%s -> %s' % (src, dst), color='yellow') try: src.copy(dst) except shutil.SameFileError: pass ctx.db.add_external_dependencies_to_call(srcs=srcs) return dsts
def build_libtsm(ctx, c, xkbcommon): base = Path('deps/libtsm') src = base / 'src' shl = src / 'shared' tsm = src / 'tsm' sources = Path.glob( tsm / '*.c') + [shl / 'shl-htable.c', base / 'external' / 'wcwidth.c'] includes = [shl, tsm, base] if xkbcommon is not None: cflags = xkbcommon.cflags else: cflags = [] macros = ['_GNU_SOURCE=1'] if not ctx.options.release: macros.append('BUILD_ENABLE_DEBUG') return Record(includes=includes, lib=c.build_lib('tsm', sources, includes=includes, macros=macros, cflags=cflags))
def test_flx(phase, felix, src, *args, **kwargs): src = Path(src) passed = True for static in False, True: try: exe = felix.compile(src, static=static) except fbuild.ExecutionError as e: phase.ctx.logger.log(e, verbose=1) if e.stdout: phase.ctx.logger.log(e.stdout.decode('utf-8','ignore').strip(), verbose=1) if e.stderr: phase.ctx.logger.log(e.stderr.decode('utf-8','ignore').strip(), verbose=1) passed = False continue if static: dst = exe + '.static.stdout' else: dst = exe + '.shared.stdout' expect = src.replaceext('.expect') passed &= check_flx(phase.ctx, felix, *args, exe=exe, dst=dst, expect=expect if expect.exists() else None, static=static, **kwargs) return passed
def __init__(self, options): # Convert the paths to Path objects. options.buildroot = Path(options.buildroot) if options.state_file is None: options.state_file = STATE_FILE_DEFAULTS[options.database_engine] options.state_file = options.buildroot / options.state_file options.log_file = options.buildroot / options.log_file self.logger = fbuild.console.Log(verbose=options.verbose, nocolor=options.nocolor or options.no_color, threadcount=options.threadcount, show_threads=options.show_threads) self.db = fbuild.db.database.Database(self, engine=options.database_engine, explain=options.explain_database) self.scheduler = fbuild.sched.Scheduler(options.threadcount, logger=self.logger) self.options = options self.install_prefix = Path('/usr/local') self.to_install = [] self.tmpdir = self.buildroot / '.tmp' fbuild.temp.set_default_tempdir(self.tmpdir)
def test(ctx): """Run the felix tests and other commands.""" # Make sure we're built. phases, iscr, felix = build(ctx) from buildsystem.flx import test_flx failed_srcs = [] def test(src): try: passed = test_flx(phases.target, felix, src) except fbuild.ConfigFailed as e: ctx.logger.log(str(e)) passed = False return src, passed # Run the dynamic loading tests first try: lib1 = felix.compile('test/regress/drt/lib1.flx', static=False) lib2 = felix.compile('test/regress/drt/lib2.flx', static=False) except fbuild.ExecutionError as e: ctx.logger.log(e, verbose=1) else: if not test_flx(phases.target, felix, 'test/regress/drt/main1.flx', env={'lib1': lib1, 'lib2': lib2}): failed_srcs.append('test/regress/drt/main1.flx') srcs = Path.globall( 'test/*/*.flx', 'test/*/*/*.flx', 'tut/*/*.flx', exclude=[ 'test/drivers/*.flx', 'test/faio/posix-*.flx', 'test/faio/win-*.flx', 'test/regress/drt/*.flx', 'test/regress/bt/*.flx', 'test/regress/kf/*.flx', 'test/regress/nd/*.flx', 'test/test-data/*.flx', ]) if 'posix' in phases.target.platform: srcs.extend(Path.glob('test/faio/posix-*.flx')) if 'windows' in phases.target.platform: srcs.extend(Path.glob('test/faio/win-*.flx')) for src, passed in phases.target.ctx.scheduler.map( test, sorted(srcs, reverse=True)): if not passed: failed_srcs.append(src) if failed_srcs: ctx.logger.log('\nThe following tests failed:') for src in failed_srcs: ctx.logger.log(' %s' % src, color='yellow')
def build(ctx): ocaml = fbuild.builders.ocaml.batteries.Ocaml(ctx) lib = ocaml.ocamlc.build_lib('lib', Path.glob('lib*.ml{,i}'), packages=['sexplib.syntax']) print('here', lib) exe = ocaml.ocamlc.build_exe('exe.byte', ['exe.ml'], libs=[lib]) ctx.logger.log(' * running %s:' % exe) ctx.execute([exe]) lib = ocaml.ocamlopt.build_lib('lib', Path.glob('lib*.ml{,i}'), packages=['sexplib.syntax']) exe = ocaml.ocamlopt.build_exe('exe.byte', ['exe.ml'], libs=[lib]) ctx.logger.log(' * running %s:' % exe) ctx.execute([exe]) # We can also build bytecode and native libraries at the same time. lib = ocaml.build_lib('lib', Path.glob('lib*.ml{,i}'), packages=['sexplib.syntax']) exe = ocaml.build_exe('exe', ['exe.ml'], libs=[lib]).bytecode
def __init__(self, ctx, exe=None): super().__init__(ctx) if exe is None: exe = call('fbuildroot.src_dir', ctx) / 'buildsystem/interscript/bin/iscr.py' self.exe = Path(exe)
def __call__(self, dst, srcs, *args, buildroot=None, **kwargs): """Run a scala script.""" dst = Path(dst).addroot(buildroot or self.ctx.buildroot) dst.makedirs() stdout, stderr = self._run(srcs, *args, dst=dst, **kwargs) return dst, stdout, stderr
def __call__(self, dst, srcs: fbuild.db.SRCS, *, libs: fbuild.db.SRCS = (), ldlibs=(), external_libs=(), flags=(), ranlib_flags=(), prefix=None, suffix=None, buildroot=None, **kwargs) -> fbuild.db.DST: buildroot = buildroot or self.ctx.buildroot #libs = set(libs) #libs.update(self.libs) #libs = sorted(libs) #assert srcs or libs, 'no sources passed into ar' assert srcs, 'no sources passed into ar' prefix = prefix or self.prefix suffix = suffix or self.suffix dst = Path(dst).addroot(buildroot) dst = dst.parent / prefix + dst.name + suffix dst.parent.makedirs() srcs = list(Path.globall(srcs)) cmd = [self.exe] cmd.extend(self.flags) cmd.extend(flags) cmd.append(dst) cmd.extend(srcs) #cmd.extend(libs) #cmd.extend(self.external_libs) #cmd.extend(external_libs) self.ctx.execute(cmd, msg1=str(self), msg2='%s -> %s' % (' '.join(srcs), dst), color='link', **kwargs) if self.ranlib is not None: cmd = [self.ranlib] cmd.extend(self.ranlib_flags) cmd.extend(ranlib_flags) cmd.append(dst) self.ctx.execute(cmd, msg1=self.ranlib.name, msg2=dst, color='link', **kwargs) return dst
def build(ctx): rec = configure(ctx) src = rec.dasm.translate('src/x86_64.dasc', 'codegen.c') rejit = rec.c.build_lib('rejit', Path.glob('src/*.c') + Path.glob('utf/*.c'), includes=['.', ctx.buildroot]) rec.c.build_exe('bench', ['bench.c'], libs=[rejit]) rec.c.build_exe('ex', ['ex.c'], libs=[rejit]) if rec.tests: rec.c.build_exe('tst', ['tst.c'], cflags=rec.testflags, libs=[rejit])
def build_flx_backend(phase): path = Path('src/compiler/flx_backend') return phase.ocaml.build_lib(path / 'flx_backend', srcs=Path.glob(path / '*.ml{,i}'), libs=[ build_flx_lex(phase), build_flx_misc(phase), build_flx_core(phase) ])
def build(phase): path = Path('src', 'compiler', 'sex') dypgen = call('buildsystem.dypgen.build_exe', phase) return phase.ocaml.build_lib(path/'sex', Path.globall( path/'*.ml{,i}', dypgen(path/'sex_parse.dyp'), phase.ocamllex(path/'sex_lex.mll'), exclude=path/'sex.ml'), libs=[ call('buildsystem.ocs.build_lib', phase), call('buildsystem.dypgen.build_lib', phase)])
def tempdir(*args, **kwargs): ''' Create a temporary directory and yield it's path. When we regain context, remove the directory. ''' path = Path(_tempfile.mkdtemp(*args, **kwargs)) try: yield path finally: path.rmtree()
def build_exe(phase): path = Path('src/compiler/dypgen/dypgen') exe = phase.ocaml.build_exe( path / 'dypgen', Path.globall(path / '*.ml{,i}', phase.ocamllex(path / 'dypgen_lexer.mll'), phase.ocamllex(path / 'extract_type.mll'), phase.ocamllex(path / 'insert_linenum.mll')), libs=[build_lib(phase)]) return Builder(phase.ctx, exe)
def build_flx_bind(phase): path = Path('src/compiler/flx_bind') return phase.ocaml.build_lib(path / 'flx_bind', srcs=Path.glob(path / '*.ml{,i}'), libs=[ build_flx_lex(phase), build_flx_misc(phase), build_flx_core(phase), build_flx_desugar(phase) ], external_libs=[])
def tempdir(*args, **kwargs): ''' Create a temporary directory and yield it's path. When we regain context, remove the directory. ''' path = Path(_tempfile.mkdtemp(*args, **kwargs)) try: yield path finally: path.rmtree(ignore_errors=True)
def build_flx_cpp_backend(phase): path = Path('src/compiler/flx_cpp_backend') return phase.ocaml.build_lib(path / 'flx_cpp_backend', srcs=Path.globall(path / '*.ml{,i}', ), libs=[ build_flx_lex(phase), build_flx_misc(phase), build_flx_core(phase), build_flx_frontend(phase), build_flx_backend(phase) ], external_libs=[])
def tempdir(dir=None, delete=False, *args, **kwargs): ''' Create a temporary directory and yield it's path. If *delete* is truthy, when we regain context, remove the directory. ''' path = Path(_tempfile.mkdtemp(dir=dir or _default_tempdir, *args, **kwargs)) try: yield path finally: if delete: path.rmtree(ignore_errors=True)
def build_flx_lex(phase): path = Path('src/compiler/flx_lex') dypgen = call('buildsystem.dypgen.build_exe', phase) return phase.ocaml.build_lib(path / 'flx_lex', srcs=Path.globall(path / '*.ml{,i}'), libs=[ call('buildsystem.dypgen.build_lib', phase), call('buildsystem.ocs.build_lib', phase), call('buildsystem.sex.build', phase), build_flx_version(phase) ])
def compile(self, src: fbuild.db.SRC, dst=None, *, flags=[], quieter=0, stdout_quieter=0, **kwargs) -> fbuild.db.DST: """Compile a c file and cache the results.""" src = Path(src) # Generate the dependencies while we compile the file. try: obj, stdout, stderr = self.compiler( src, dst, flags=list(chain(('/showIncludes', ), flags)), quieter=quieter, stdout_quieter=1 if stdout_quieter == 0 else stdout_quieter, **kwargs) except fbuild.ExecutionError as e: if quieter == 0 and stdout_quieter == 0: # We errored out, but we've hidden the stdout output. # Display the output while filtering out the dependeny # info. for line in io.StringIO(e.stdout.decode()): if not self._dep_regex.match(line) and \ line != src.name.splitext()[0] + '\r\n': self.ctx.logger.write(line) raise e # Parse the output and return the module dependencies. deps = [] for line in io.StringIO(stdout.decode()): m = self._dep_regex.match(line) if m: # The path sometimes is absolute, so try to convert it into a # relative path. try: deps.append(Path(m.group(1)).relpath()) except ValueError: # We couldn't find a relative path, so it must be from # outside our project. Lets just ignore that dependency # for now. pass elif quieter == 0 and stdout_quieter == 0: if line != src.name + '\r\n': self.ctx.logger.write(line) self.ctx.db.add_external_dependencies_to_call(srcs=deps) return obj
def build_flx_core(phase): path = Path('src/compiler/flx_core') return phase.ocaml.build_lib(path / 'flx_core', srcs=Path.glob(path / '*.ml{,i}'), libs=[ call('buildsystem.dypgen.build_lib', phase), call('buildsystem.ocs.build_lib', phase), build_flx_lex(phase), build_flx_parse(phase), build_flx_misc(phase), ], external_libs=[])
def build_flx_pkgconfig(host_phase, target_phase, flx_builder): return flx_builder.build_flx_pkgconfig_exe( dst=Path('host')/'bin'/'flx_pkgconfig', src=Path('src')/'tools'/'flx_pkgconfig.flx', includes=[ target_phase.ctx.buildroot / 'host'/'lib', target_phase.ctx.buildroot / 'share'/'lib', ], cxx_includes=[Path('src')/'flx_pkgconfig', target_phase.ctx.buildroot / 'share'/'lib'/'rtl', target_phase.ctx.buildroot / 'host'/'lib'/'rtl'], cxx_libs=[call('buildsystem.flx_rtl.build_runtime', host_phase, target_phase).static], )
def post_options(options, args): options.prefix = Path(options.prefix) options.bindir = Path(options.prefix / 'bin' if options.bindir is None else options.bindir) options.libdir = Path(options.prefix / 'lib' if options.libdir is None else options.libdir) if options.debug: options.buildroot = Path(options.buildroot, 'debug') else: options.buildroot = Path(options.buildroot, 'release') return options, args
def run_test(src): src = Path(src) dst = _make_stdout_dst(ctx, src) expect = src.replaceext('.expect') # Make sure the destination directory exists. dst.parent.makedirs() if not expect.exists(): expect = None passed = check_flxi_test(ctx, src=src, dst=dst, expect=expect) return src, passed
def move_to(ctx, dstdir, srcs:fbuild.db.SRCS) -> fbuild.db.DSTS: dstdir.makedirs() dsts = [] for src in srcs: src = Path(src) dst = dstdir / src.name ctx.logger.check(' * move', '%s -> %s' % (src, dst), color='yellow') src.move(dst) dsts.append(dst) return dsts
def __call__( self, src: fbuild.db.SRC, *, break_on_error=True, flags=[], buildroot=None, **kwargs ) -> fbuild.db.DSTS: buildroot = buildroot or self.ctx.buildroot src = Path(src) cmd = [ sys.executable, self.exe.relpath(buildroot), "--cache-prefix=lpsrc-cache", "--trace=sources", "--trace=changes", "--nocache", ] if break_on_error: cmd.append("--break-on-error") cmd.extend(flags) cmd.append(src.relpath(buildroot)) stdout, stderr = self.ctx.execute( cmd, "iscr extracting", src, color="green", cwd=buildroot, env={"PYTHONPATH": Path("buildsystem").relpath(buildroot)}, **kwargs ) srcs = [] dsts = [] ipk_regex = re.compile("^CREATING .* NAMED FILE SOURCE (.*) \[.*\]") file_regex = re.compile("^File (.*) is (NEW|CHANGED|unchanged)") for line in io.StringIO(stdout.decode()): m = ipk_regex.match(line) if m: path = Path(m.group(1)) if not path.exists(): # The path may be relative to the .pak file. path = src.parent / path srcs.append(path) else: m = file_regex.match(line) if m: dsts.append(Path(m.group(1))) # self.ctx.db.add_external_dependencies_to_call(srcs=srcs) return dsts
def build_runtime(host_phase, target_phase): path = Path('src/faio') buildsystem.copy_hpps_to_rtl( target_phase.ctx, path / 'faio_job.hpp', path / 'faio_timer.hpp', path / 'faio_posixio.hpp', path / 'faio_winio.hpp', ) dst = 'host/lib/rtl/faio' srcs = [ path / 'faio_job.cpp', path / 'faio_timer.cpp', ] includes = [ target_phase.ctx.buildroot / 'host/lib/rtl', Path('src', 'flx_async'), Path('src', 'pthread'), Path('src', 'demux'), Path('src', 'rtl'), Path('src', 'exceptions'), Path('src', 'gc'), path, ] macros = ['BUILD_FAIO'] libs = [ call('buildsystem.flx_pthread.build_runtime', target_phase), call('buildsystem.flx_async.build_runtime', host_phase, target_phase), call('buildsystem.demux.build_runtime', target_phase), ] if 'win32' in target_phase.platform: srcs.append(path / 'faio_winio.cpp') includes.append(Path('src', 'demux', 'win')) if 'posix' in target_phase.platform: srcs.append(path / 'faio_posixio.cpp') includes.append(Path('src', 'demux', 'posix')) return Record(static=buildsystem.build_cxx_static_lib( target_phase, dst, srcs, includes=includes, macros=macros, libs=[lib.static for lib in libs]), shared=buildsystem.build_cxx_shared_lib( target_phase, dst, srcs, includes=includes, macros=macros, libs=[lib.shared for lib in libs]))
def check_fluid(linker): fluidsynth = Path(linker.prefix + 'fluidsynth' + linker.suffix) fluidsynth = fluidsynth.addroot(Path('fluidsynth') / 'fluidsynth' / 'src') message = textwrap.dedent(''' You need to build Fluidsynth separately first! Try runnung 'cd fluidsynth/fluidsynth; cmake'. (See http://sourceforge.net/p/fluidsynth/wiki/BuildingWithCMake/ for info.) '''.rstrip().lstrip('\n')).replace('\n', ' ', 1) if not fluidsynth.exists(): raise fbuild.ConfigFailed(message) return fluidsynth
def _copy_or_move(ctx, src, dst, function, function_name): """ Helper function to simplify copies and moves. """ src = Path(src) dst = Path(dst).addroot(ctx.buildroot) if not dst.exists(): # if dst ends with the separator, treat it like a directory if dst.endswith(os.sep): dst.makedirs() dst = dst / src.name else: dst.parent.makedirs() elif dst.isdir(): # If the dst is a directory, we're just copying that file into that # directory. dst = dst / src.name ctx.logger.check(' * %s' % function_name, '%s -> %s' % (src, dst), color='yellow') function(src, dst) return dst
def build_flx_core(phase): path = Path('src/compiler/flx_core') return phase.ocaml.build_lib(path / 'flx_core', srcs=Path.glob(path / '*.ml{,i}'), libs=[build_flx_misc(phase)], external_libs=['nums'], packages=['batteries'])
def __call__(self, src, *args, includes=[], debug=None, static=False, stdout=None, flags=[], cwd=None, **kwargs): cmd = [self.exe] if debug is None: debug = self.debug if debug: cmd.append('--debug') if static: cmd.append('--static') if stdout: cmd.append('--stdout=' + stdout) cmd.extend('-I' + i for i in sorted(includes) if Path(i).exists()) cmd.extend(self.flags) cmd.extend(flags) cmd.append(src) return self.ctx.execute(cmd, *args, **kwargs)
def build_flx_pkgconfig(phase, flx_builder): #print('[fbuild] [flx] building flx_pkgconfig') #dlfcn_h = config_call('fbuild.config.c.posix.dlfcn_h', # phase.platform, # phase.cxx.static, # phase.cxx.shared) #if dlfcn_h.dlopen: # external_libs = dlfcn_h.external_libs #else: # external_libs = [] external_libs = [] return flx_builder.build_flx_pkgconfig_exe( dst=Path('host') / 'bin' / 'flx_pkgconfig', src=phase.ctx.buildroot / 'share' / 'src' / 'tools' / 'flx_pkgconfig.flx', includes=[ phase.ctx.buildroot / 'host' / 'lib', phase.ctx.buildroot / 'share' / 'lib', ], cxx_includes=[ phase.ctx.buildroot / 'share' / 'lib' / 'rtl', phase.ctx.buildroot / 'host' / 'lib' / 'rtl' ], cxx_libs=[call('buildsystem.flx_rtl.build_runtime', phase).static] + external_libs, )
def build_flx(phase, flx_builder): print('[fbuild] [flx] building flx') #dlfcn_h = config_call('fbuild.config.c.posix.dlfcn_h', # phase.platform, # phase.cxx.static, # phase.cxx.shared) #if dlfcn_h.dlopen: # external_libs = dlfcn_h.external_libs # print("HAVE dlfcn.h, library=" + str (external_libs)) #else: # print("NO dlfcn.h available") # external_libs = [] external_libs = [] #print("[fbuild:flx.py:build_flx] ********** BUILDING FLX ***********************************************") return flx_builder.build_exe( aasync=False, dst=Path('host') / 'bin' / 'bootflx', src=phase.ctx.buildroot / 'share' / 'src' / 'tools' / 'bootflx.flx', includes=[ phase.ctx.buildroot / 'host' / 'lib', phase.ctx.buildroot / 'share' / 'lib', ], cxx_includes=[ phase.ctx.buildroot / 'share' / 'lib' / 'rtl', phase.ctx.buildroot / 'host' / 'lib' / 'rtl' ], cxx_libs=[ call('buildsystem.flx_rtl.build_runtime', phase).static, call('buildsystem.re2.build_runtime', phase).static, ] + external_libs, )
def f(lib): if lib in new_libs: return if isinstance(lib, fbuild.builders.c.Library): for libpath in lib.libpaths: if libpath not in libpaths: libpaths.append(libpath) for l in lib.external_libs: if l not in external_libs: external_libs.append(l) # In order to make linux happy, we'll recursively walk the # dependencies first, then add the library. for l in lib.libs: f(l) parent, lib = Path(lib).split() if parent not in libpaths: libpaths.append(parent) lib = lib.name[len('lib'):] lib = lib.rsplit('.', 1)[0] if lib not in new_libs: new_libs.append(lib)
def build_flx_drivers(ctx, phase): libs = [ call('buildsystem.ocs.build_lib', phase), call('buildsystem.sex.build', phase), call('buildsystem.dypgen.build_lib', phase), build_flx_version(phase), build_flx_lex(phase), build_flx_parse(phase), build_flx_misc(phase), build_flx_file(phase), build_flx_core(phase), build_flx_desugar(phase), build_flx_bind(phase), build_flx_frontend(phase), build_flx_opt(phase), build_flx_lower(phase), build_flx_backend(phase), build_flx_cpp_backend(phase), build_flx_version_hook(phase), ] external_libs = ['nums', 'unix', 'str'] flxg = phase.ocaml.build_exe('host/bin/flxg', Path.glob('src/compiler/flxg/*.ml{,i}'), libs=libs, external_libs=external_libs) return Record( flxg=flxg, )
def build_flx_frontend(phase): path = Path('src/compiler/flx_frontend') return phase.ocaml.build_lib(path / 'flx_frontend', srcs=Path.glob(path / '*.ml{,i}'), libs=[ build_flx_misc(phase), build_flx_core(phase)])
def __call__(self, src:fbuild.db.SRC, dst=None, *, suffix=None, verbose=False, name_prefix=None, defines=False, flags=[], buildroot=None) -> fbuild.db.DST: buildroot = buildroot or self.ctx.buildroot suffix = suffix or self.suffix dst = Path.addroot(dst or src, buildroot).replaceext(suffix) dst.parent.makedirs() cmd = [self.exe] if verbose: cmd.append('-v') if name_prefix is not None: cmd.extend(('-p', name_prefix)) if defines: cmd.append('-d') cmd.extend(self.flags) cmd.extend(flags) cmd.extend(('-o', dst)) cmd.append(src) self.ctx.execute(cmd, self.exe, '%s -> %s' % (src, dst), color='yellow') return dst
def build_flx_drivers(phase): path = Path('src/compiler/drivers') call('buildsystem.ocs.build_exe', phase) lib = phase.ocaml.build_lib(path / 'flx_driver', srcs=Path.glob(path / '*.ml{,i}')) return { 'flxi': phase.ocaml.build_exe('bin/flxi', srcs=Path(path / 'flxi' / '*.ml{,i}').glob(), libs=[ call('buildsystem.dypgen.build_lib', phase), call('buildsystem.ocs.build_lib', phase), lib, build_flx_misc(phase), build_flx_core(phase), build_flx_parse(phase), build_flx_bind(phase), build_flx_codegen(phase)], external_libs=[ 'batteries', 'threads', 'llvm', 'llvm_analysis', 'llvm_executionengine', 'llvm_scalar_opts', 'llvm_target'], flags=['-thread'], packages=['batteries'], cc=phase.cxx.static.compiler.gcc.exe) }
def copy_to(ctx, dstdir, srcs:fbuild.db.SRCS) -> fbuild.db.DSTS: dstdir.makedirs() dsts = [] for src in srcs: src = Path(src) dst = dstdir / src.name ctx.logger.check(' * copy', '%s -> %s' % (src, dst), color='yellow') try: src.copy(dst) except shutil.SameFileError: pass dsts.append(dst) return dsts
def build_lib(phase): path = Path('src/compiler/dypgen/dyplib') # dyplib cannot be built with ocamlcp. ocaml = phase.ocamlc if phase.ocaml == phase.ocamlcp else phase.ocaml return ocaml.build_lib(path/'dyp', Path.glob(path/'*.ml{,i}'))
def build(phase, felix): print ("BUILDING PLUGINS") for f in Path.glob('src/lib/plugins/*'): copy(ctx=phase.ctx, src=f, dst=phase.ctx.buildroot / 'share'/f[4:]) plugins = [ #"ocaml2html", #"py2html", #"fdoc2html", #"flx2html", #"cpp2html", #"fpc2html", #"fdoc_slideshow", #"fdoc_paragraph", #"fdoc_heading", #"fdoc_fileseq", #"fdoc_scanner", #"fdoc_button", "toolchain_clang_osx", "toolchain_clang_linux", "toolchain_gcc_osx", "toolchain_gcc_linux", "toolchain_gcc48_linux", ] for base in plugins: shlib = felix.compile(phase.ctx.buildroot/('share/lib/plugins/'+base+'.flx'),flags=['-od',phase.ctx.buildroot/'host/lib/rtl'])
def build_flx_drivers(ctx, phase): libs = [ call('buildsystem.ocs.build_lib', phase), call('buildsystem.sex.build', phase), call('buildsystem.dypgen.build_lib', phase), build_flx_version(phase), build_flx_lex(phase), build_flx_parse(phase), build_flx_misc(phase), build_flx_file(phase), build_flx_core(phase), build_flx_desugar(phase), build_flx_bind(phase), build_flx_frontend(phase), build_flx_opt(phase), build_flx_lower(phase), build_flx_backend(phase), build_flx_cpp_backend(phase), build_flx_version_hook(phase), ] external_libs = ['unix', 'str'] flxg = phase.ocaml.build_exe('host/bin/flxg', Path.glob('src/compiler/flxg/*.ml{,i}'), libs=libs, external_libs=external_libs) return Record(flxg=flxg, )
def build(ctx): rec = configure(ctx) static = rec.static shared = rec.shared libregexp = static.build_lib('regexp9', Path.glob('libregexp/*.c', exclude=['*test*.c'])) static.build_exe('o', ['o.c'], libs=[libregexp]) static.build_exe('tst', ['o.c'], macros=['UTEST'], libs=[libregexp])
def build_midifi(ctx, rec, midifile): all_sources = [] for pat in 'midifi/*.flx', 'sfml/sfml/*.flx', 'midifile-flx/midifile.flx': all_sources.extend(Path.glob(pat)) rec.felix.compile('midifi', 'midifi.flx', all_sources, rec.static, includes=['sfml', 'midifile', 'midifile-flx'], pkgconfig_paths=['build/config'], libs=[midifile])
def __call__(self, src: fbuild.db.SRC, header, dst=None) -> fbuild.db.DSTS: dst = Path.addroot(dst or src, self.ctx.buildroot).replaceext(self.suffix) dst.parent.makedirs() header = Path.addroot(header, self.ctx.buildroot) header.parent.makedirs() cmd = [self.exe] cmd.extend(self.flags) if self.debug: cmd.append('-d') cmd.extend(('-o', dst)) cmd.append('--header='+header) cmd.append(src) self.ctx.execute(cmd, self.exe, '%s -> %s %s' % (src, dst, header), color='yellow') return [dst, header]
def build_runtime(host_phase, target_phase): path = Path('src', 'rtl') buildsystem.copy_hpps_to_rtl(target_phase.ctx, path / 'flx_rtl.hpp', path / 'flx_rtl_shapes.hpp', path / 'flx_compiler_support_headers.hpp', path / 'flx_compiler_support_bodies.hpp', path / 'flx_dynlink.hpp', path / 'flx_i18n.hpp', path / 'flx_ioutil.hpp', path / 'flx_strutil.hpp', path / 'flx_executil.hpp', path / 'flx_sync.hpp', path / 'flx_world.hpp', path / 'flx_async_world.hpp', path / 'flx_world_config.hpp', path / 'plat_linux.hpp', ) for f in Path.glob(path/"*.hpp"): print("Copying " + f + " --> " +target_phase.ctx.buildroot/f ) copy(ctx=target_phase.ctx, src=f,dst=target_phase.ctx.buildroot/f) srcs = [copy(ctx=target_phase.ctx, src=f, dst=target_phase.ctx.buildroot / f) for f in Path.glob(path / '*.cpp')] includes = [ target_phase.ctx.buildroot / 'host/lib/rtl', target_phase.ctx.buildroot / 'share/lib/rtl' ] macros = ['BUILD_RTL'] libs = [ call('buildsystem.flx_async.build_runtime', host_phase,target_phase), call('buildsystem.flx_exceptions.build_runtime', target_phase), call('buildsystem.flx_gc.build_runtime', host_phase, target_phase), ] dlfcn_h = config_call('fbuild.config.c.posix.dlfcn_h', target_phase.platform, target_phase.cxx.static, target_phase.cxx.shared) if dlfcn_h.dlopen: external_libs = dlfcn_h.external_libs else: external_libs = [] dst = 'host/lib/rtl/flx' return Record( static=buildsystem.build_cxx_static_lib(target_phase, dst, srcs, includes=includes, macros=macros, libs=[lib.static for lib in libs], external_libs=external_libs), shared=buildsystem.build_cxx_shared_lib(target_phase, dst, srcs, includes=includes, macros=macros, libs=[lib.shared for lib in libs], external_libs=external_libs))
class Iscr(fbuild.db.PersistentObject): def __init__(self, ctx, exe=None): super().__init__(ctx) if exe is None: exe = call('fbuildroot.src_dir', ctx) / 'buildsystem/interscript/bin/iscr.py' self.exe = Path(exe) @fbuild.db.cachemethod def __call__(self, src:fbuild.db.SRC, *, break_on_error=True, flags=[], buildroot=None, **kwargs) -> fbuild.db.DSTS: buildroot = buildroot or self.ctx.buildroot src = Path(src) cmd = [ sys.executable, self.exe.relpath(buildroot), '--cache-prefix=lpsrc-cache', '--trace=sources', '--trace=changes', '--nocache', ] if break_on_error: cmd.append('--break-on-error') cmd.extend(flags) cmd.append(src.relpath(buildroot)) stdout, stderr = self.ctx.execute(cmd, 'iscr extracting', src, color='green', cwd=buildroot, env={'PYTHONPATH': Path('buildsystem').relpath(buildroot)}, **kwargs) srcs = [] dsts = [] ipk_regex = re.compile('^CREATING .* NAMED FILE SOURCE (.*) \[.*\]') file_regex = re.compile('^File (.*) is (NEW|CHANGED|unchanged)') for line in io.StringIO(stdout.decode()): m = ipk_regex.match(line) if m: path = Path(m.group(1)) if not path.exists(): # The path may be relative to the .pak file. path = src.parent / path srcs.append(path) else: m = file_regex.match(line) if m: dsts.append(Path(m.group(1))) #self.ctx.db.add_external_dependencies_to_call(srcs=srcs) return dsts
def build_flx_codegen(phase): path = Path('src', 'compiler', 'flx_codegen') return phase.ocaml.build_lib(path / 'flx_codegen', srcs=Path.glob(path / '*.ml{,i}'), includes=[phase.llvm_config.ocaml_libdir()], libs=[ build_flx_misc(phase), build_flx_core(phase)], packages=['batteries'])
def build_flx_bind(phase): path = Path('src/compiler/flx_bind') return phase.ocaml.build_lib(path / 'flx_bind', srcs=Path.glob(path / '*.ml{,i}'), libs=[ build_flx_misc(phase), build_flx_core(phase), build_flx_desugar(phase)], external_libs=['nums'])
def build_flx_bind(phase): path = Path('src', 'compiler', 'flx_bind') return phase.ocaml.build_lib(path / 'flx_bind', srcs=Path.glob(path / '*.ml{,i}'), libs=[ build_flx_misc(phase), build_flx_core(phase), build_flx_parse(phase)], packages=['batteries'])