def test_build(): if not osinfo.linux or not check_exists(): return topdir = directory(__file__).join('..').absolute directory(topdir.join('build')).remove() exit_code, proc_out = run('./wasp build', cwd=topdir.path) out_lines = proc_out.stdout.split('\n') # check if the commands succeeded assert '[SUCC] Command: `configure`' in out_lines assert '[SUCC] Command: `build`' in out_lines # check if dmd was used assert any('dmd' in l for l in out_lines) # check if jsmin was installed by npm assert any('jsmin@' in l for l in out_lines) bd = directory(topdir.join('build')) main_file = bd.join('main').absolute assert main_file.exists assert bd.join('buildtest').exists assert bd.join('node_modules').exists exit_code, proc_out = run(main_file.path) out = proc_out.stdout.split('\n') assert 'hello from dlang' in out assert bd.join('node_modules/jsmin/bin/jsmin').exists exit_code, proc_out = run('./wasp build', cwd=topdir.path) outs = proc_out.stdout.split('\n') assert '[SUCC] Command: `configure`' in outs assert '[SUCC] Command: `build`' in outs assert len(outs) == 2
def _retrieve_msvc(self): for varname in MSVC_VARS: v = os.environ.get(varname, None) if v is not None: if directory(v).exists: self._msvcpath = directory(v).join('../../VC').absolute return
def configure(): debug = value('debug', False) build_type = 'debug' if debug else 'release' native_arch = 'x64' if osinfo.x64 else 'x86' arch = value('msvc_arch') or native_arch capnpdir = directory('3rdparty/capnproto/windows/') capnplibdir = capnpdir.join(arch + '-' + build_type) inc = get_includes() inc.append('submodules/capnproto/c++/src') cli = cpp.CompilerCli(cpp.DEFAULT_COMPILER) node(':config').write({ 'includes': inc, 'debug': debug, 'libraries': [capnplibdir.join('capnp.lib'), capnplibdir.join('kj.lib')], 'defines': 'CAPNP_LITE', 'cflags': cli.default_flags(debug=debug, arch=arch) }) python_dir = value('python_dir') if python_dir is None: raise CommandFailedError("Be sure to specify the `python_dir` argument somewhere!") python_dir = directory(python_dir) node(':python').write({ 'includes': python_dir.join('include'), 'libraries': python_dir.join('libs/python35.lib'), })
def test_file_collection(): prepare() curdir = directory(__file__) testdir = directory(curdir.join('test-dir')) fs = testdir.glob('.*', dirs=False) col = FileCollection(fs) newcol = col.replace_extension('asdf') for f in newcol: assert f.extension == 'asdf'
def compile_schema(): directory(ctx.builddir.join('schema')).ensure_exists() schema_sources = [] tasks = [] for src in directory('src/schema').glob('.*\.capnp'): cmd = 'capnp compile --src-prefix=src/schema -oc++:{outp} {src}' tgt = file(ctx.builddir.join('schema').join(src.basename)).append_extension('.c++') schema_sources.append(tgt) capnp = shell(cmd, sources=src, targets=tgt) capnp.use(outp=ctx.builddir.join('schema')) tasks.append(capnp) return tasks, schema_sources
def include_found(self, header, headers, include_filepath, current_depth): include_paths = list(self.arguments.value('includes', [])) include_paths.append(directory(header)) for path in include_paths: if directory(path).isabs: continue f = directory(path).join(include_filepath) if f.exists and not f.isdir: if f.path in headers: return headers.add(f.path) self._scan(headers, f, current_depth+1)
def install(): destdir = directory(value('destdir', DEFAULT_PREFIX)) include_dir = directory(destdir.join('usr').join('include').join('capnqml')) include_dir.ensure_exists() for file in directory('src').glob('^.*(hpp|capnp)$', exclude='.*test.*'): yield copy(file, include_dir.join(file.relative('src').path)) bin_dir = directory(destdir.join('usr').join('bin')) bin_dir.ensure_exists() yield copy(ctx.builddir.join(ZMQLAUNCHER_NAME), bin_dir) lib_dir = directory(destdir.join('usr').join('lib')) lib_dir.ensure_exists() yield copy(ctx.builddir.join(LIBCAPNQML_NAME), lib_dir)
def test_file(): curdir = directory(__file__) testdir = directory(curdir.join('test-dir')) prepare() f = testdir.join('a.txt') assert isinstance(f, File) assert not f.isdir assert f.extension == 'txt' f = f.append_extension('asdf') assert not f.exists assert f.extension == 'asdf' f = f.replace_extension('fdsa') assert f.extension == 'fdsa'
def prepare(): curdir = directory(__file__) testdir = directory(curdir.join('test-dir')) testdir.remove(recursive=True) assert not testdir.exists testdir.ensure_exists() for f in ['a.txt', 'dira/dirb/b.txt', 'c.txt']: f = file(testdir.join(f)) directory(f).ensure_exists() assert directory(f).exists with open(f.path, 'w') as fwrite: fwrite.write('asdf') assert f.exists
def _run(self): base_dir = self.arguments.value('base_dir') include_dir = self.arguments.value('include_dir') lib_dir = self.arguments.value('lib_dir') assert include_dir is not None and lib_dir is not None includes = [] libraries = [] lib_dir = directory(lib_dir) for key in self._keys: fname = Modules.filename(lib_dir, key) if not lib_dir.join(fname).exists: self.log.fatal('qt.FindModules: Could not find shared object at `{0}`' .format(lib_dir.join(fname))) self.success = False return libraries.append(fname) include_paths = Modules.includedir(include_dir, key) for path in include_paths: if not file(path).exists: self.log.fatal('qt.FindModules: Could not find include directories at `{0}`' .format(', '.join(x.path for x in include_paths))) self.success = False return includes.extend(include_paths) self.result['includes'] = includes self.result['libraries'] = libraries self.success = True
def _find_exe(self, name): for path in self._env['path']: ret = directory(path).join(name) if ret.exists: return ret.path raise MsvcError('Could not find executable `{0}` ' 'in environment returned from `vcvarsall.bat`'.format(name))
def compile_schema(): tasks = [] directory(ctx.builddir.join('schema')).ensure_exists() schema_sources = [] for src in directory('src/schema').glob('.*\.capnp'): cmd = 'capnp compile --src-prefix=src/schema -oc++:{outp} {src_nobs}' tgt = file(ctx.builddir.join('schema').join(src.basename)).append_extension('.c++') capnp = shell(cmd, sources=src, targets=tgt) capnp.use(outp=ctx.builddir.join('schema')) # on windows, capnp compiler does not like backslashes, however # wasp formats with backslashes by default capnp.use(src_nobs=str(src).replace('\\', '/')) tasks.append(capnp) moved = tgt.replace_extension('cpp') mv = copy(tgt, moved).use(capnp) schema_sources.append(moved) tasks.append(mv) return tasks, schema_sources
def __init__(self, msvcpath=None, arch=None, debug=False): super().__init__() self._arch = arch if msvcpath is not None: self._msvcpath = directory(msvcpath) else: self._msvcpath = None self._env = {} self._debug = debug
def test_qtbuild(): if not osinfo.linux or not check_exists(): return topdir = directory(__file__).join('..').absolute directory(topdir.join('build')).remove() exit_code, proc_out = run('./wasp qt', cwd=topdir.path) out_lines = proc_out.stdout.split('\n') assert '[SUCC] Command: `qt`' in out_lines assert any('-fPIC' in l for l in out_lines) exit_code, proc_out = run('./wasp qt', cwd=topdir.path) out_lines = proc_out.stdout.split('\n') assert len(out_lines) == 1 assert '[SUCC] Command: `qt`' in out_lines bd = directory(topdir.join('build')) main_file = bd.join('buildtest/qtmain').absolute assert main_file.exists exit_code, proc_out = run(main_file.path) out = proc_out.stdout.split('\n') assert 'hello from qt' in out
def test_directory(): curdir = directory(__file__) testdir = directory(curdir.join('test-dir')) prepare() subdir = testdir.mkdir('subdir') assert isinstance(subdir, Directory) assert subdir.isdir assert subdir.exists assert isinstance(testdir.join('subdir'), Directory) home_dir = directory('~') assert subdir.relative(home_dir).absolute.path == subdir.absolute.path fs = [x.relative(testdir).path for x in testdir.glob('.*', dirs=False)] assert set(fs) == {'a.txt', 'dira/dirb/b.txt', 'c.txt'} fs = [x.relative(testdir).path for x in testdir.glob('.*', dirs=True, recursive=False)] assert set(fs) == {'a.txt', 'dira', 'c.txt', 'subdir'} fs = [x.relative(testdir).path for x in testdir.glob('.*', recursive=False, dirs=True, exclude='subdir')] assert set(fs) == {'a.txt', 'dira', 'c.txt'} testdir.join('dira').copy_to(subdir) assert set([x.relative(testdir).path for x in subdir.list()]) == {'subdir/dira'}
def glob(*dirs, sources=True, headers=False): ret = [] for d in dirs: # ensure that we are dealing with a directory # the directory function will raise if there is # an issue d = directory(d) if sources: ret.extend(d.glob(SRC_GLOB)) if headers: ret.extend(d.glob(HEADER_GLOB)) return ret
def _run(self): include_dir = self._include_dir lib_dir = self._lib_dir bin_dir = self._bin_dir base_dir = self._base_dir if osinfo.linux: data = { 'include_dir': include_dir or '/usr/include/qt', 'lib_dir': lib_dir or '/usr/lib', 'bin_dir': bin_dir or '/usr/bin', 'base_dir': base_dir or '/usr/share/qt' } elif osinfo.windows: if include_dir is not None: self.log.warn('qt.FindQt: setting include_dir with find_qt() is ignored. Use base_dir=... instead.') if base_dir is None: qtdir_re = re.compile('qt5\.([0-9])+') for p in directory('C:/Qt/').list(): if p.isdir and qtdir_re.match(p.basename.lower()): base_dir = p.path break if base_dir is None: self.log.fatal('qt.FindQt: Could not find Qt base dir. Either specify or copy qt to C:\\Qt\\<version>\\<compiler>') self.success = False return data = { 'include_dir': include_dir or directory(base_dir).join('include').path, 'lib_dir': lib_dir or directory(base_dir).join('lib').path, 'bin_dir': bin_dir or directory(base_dir).join('bin').path, 'base_dir': base_dir } else: self.log.fatal('qt.FindQt: Your platform is not supported!') self.success = False data = {} self.success = True self.result.update(data)
def test_rustbuild(): if not osinfo.linux or not check_exists(): return topdir = directory(__file__).join('..').absolute directory(topdir.join('build')).remove() exit_code, proc_out = run('./wasp rust', cwd=topdir.path) out_lines = proc_out.stdout.split('\n') err_lines = proc_out.stderr.split('\n') assert len(err_lines) == 1 and err_lines[0] == '' assert '[SUCC] Command: `rust`' in out_lines assert any('rustc' in l for l in out_lines) exit_code, proc_out = run('./wasp rust', cwd=topdir.path) out_lines = proc_out.stdout.split('\n') assert len(out_lines) == 2 exit_code, proc_out = run('./wasp clean rust', cwd=topdir.path) out_lines = proc_out.stdout.split('\n') assert any('rustc' in l for l in out_lines) assert '[SUCC] Command: `rust`' in out_lines bd = directory(topdir.join('build')) main_file = bd.join('main').absolute assert main_file.exists exit_code, proc_out = run(main_file.path) out = proc_out.stdout.split('\n') assert 'hello from rust' in out
def copy_dlls(self): qtdll_dir = ctx.builddir.mkdir('qtdlls') qt_basedir = directory(self.arguments.value('base_dir')) qt_bindir = directory(self.arguments.value('bin_dir')) for dllname in QT_DLLS: source = qt_bindir.join(dllname) target = qtdll_dir.join(source.basename) source.copy_to(target) qt_basedir.join('qml').copy_to(qtdll_dir) qt_basedir.join('plugins/platforms').copy_to(qtdll_dir) for (dirpath, dirnames, fnames) in os.walk(qtdll_dir.path): for fname in fnames: if any(fname.endswith(x) for x in ['.exp', '.pdb', '.lib']): directory(dirpath).join(fname).remove() if fname.endswith('.ilk'): debug_dll = fname.replace('.ilk', '.dll') directory(dirpath).join(fname).remove() directory(dirpath).join(debug_dll).remove()
def _process_args(self): kw = super()._process_args() include = self.arguments.value('includes', []) # relative directories must be mapped relative to self._cwd # unless they are given as an absolute path cli = CompilerCli(self._compilername) include = [cli.include_dir(directory(x).relative(self._cwd, skip_if_abs=True).path) for x in include] kw['includes'] = ' '.join(set(include)) kw['cflags'] = ' '.join(set(self.arguments.value('cflags', []))) csource = self.arguments.value('csource', None) if csource is None: raise TaskFailedError('No sources recognized. Are your source files ' 'using the right extensions? Expected one of [{}]' .format(', '.join(self.extensions))) kw['csource'] = csource defines = self.arguments.value('defines', []) kw['defines'] = cli.defines(defines) return kw
def zmqlauncher_name(): return ctx.builddir.join(ZMQLAUNCHER_NAME) @wasp.configure def configure(): yield qt.find_qt() m = qt.Modules qt_modules = qt.find_modules(keys=[m.core, m.qml, m.quick, m.quick_widgets, m.widgets]) qt_modules.produce(':qt-modules') yield qt_modules gtest_dir = directory('submodules/gtest/googletest') gtest_include = [gtest_dir, gtest_dir.join('include')] gtest_src = gtest_dir.join('src/gtest-all.cc') cxxopts_include = directory('submodules/cxxopts/src') @wasp.build def build(): moc_headers = list(Directory('src/qt').glob('^.*\.hpp$')) mocs = qt.moc(moc_headers) yield mocs schema_tasks, schema_sources = compile_schema() yield schema_tasks files = list(Directory('src').glob('^.*\.cpp$', recursive=False))
def check_exists(): for exe in ['dmd', 'npm', 'rustc', 'cargo', 'gcc', 'moc']: if not directory('/usr/bin').join(exe).exists: return False return True
def _prepare(self): super()._prepare() bin_dir = self.arguments.value('bin_dir') if bin_dir is not None: self._dirs = [directory(bin_dir)]
def includedir(cls, include_dir, key): include_dir = directory(include_dir) return [include_dir.join('Qt' + key), include_dir]
def filename(cls, lib_dir, key): if osinfo.windows: return directory(lib_dir).join('Qt5' + key + '.lib').path elif osinfo.linux: return directory(lib_dir).join('libQt5' + key + '.so').path
def test_serialize(): home_dir = directory('~') new_home_dir = factory.from_json(home_dir.to_json()) assert home_dir.path == new_home_dir.path assert home_dir.relative_to == new_home_dir.relative_to
import os import wasp from bps.util import first from wasp import copy, directory, file, factory from wasp.fs import CopyTask from wasp.generator import Generator, GeneratorCollection from wasp.main import init_context, retrieve_command_tasks from wasp import ctx curdir = directory(__file__) class DummyGenerator(Generator): key = 'foobar' def __init__(self, source=None, destination=None, restored=False): if source is not None: self.source = file(source) else: self.source = file(curdir.join('test-dir').join('test.txt')) if destination is not None: self.destination = file(destination) else: self.destination = self.source.append_extension('backup') self.restored = restored def run(self): yield copy(self.source, self.destination)