def git_version_summary(path, env=None): git = find_git(env) if git is None: return ("GIT-UNKNOWN", {}) env.GIT = git environ = dict(os.environ) environ["GIT_DIR"] = '%s/.git' % path environ["GIT_WORK_TREE"] = path git = samba_utils.get_string(Utils.cmd_output(env.GIT + ' show --pretty=format:"%h%n%ct%n%H%n%cd" --stat HEAD', silent=True, env=environ)) lines = git.splitlines() if not lines or len(lines) < 4: return ("GIT-UNKNOWN", {}) fields = { "GIT_COMMIT_ABBREV": lines[0], "GIT_COMMIT_FULLREV": lines[2], "COMMIT_TIME": int(lines[1]), "COMMIT_DATE": lines[3], } ret = "GIT-" + fields["GIT_COMMIT_ABBREV"] if env.GIT_LOCAL_CHANGES: clean = Utils.cmd_output('%s diff HEAD | wc -l' % env.GIT, silent=True).strip() if clean == "0": fields["COMMIT_IS_CLEAN"] = 1 else: fields["COMMIT_IS_CLEAN"] = 0 ret += "+" return (ret, fields)
def CHECK_COMMAND(conf, cmd, msg=None, define=None, on_target=True, boolean=False): '''run a command and return result''' if msg is None: msg = 'Checking %s' % ' '.join(cmd) conf.COMPOUND_START(msg) cmd = cmd[:] if on_target: cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg)) try: ret = Utils.cmd_output(cmd).decode('utf8') except: conf.COMPOUND_END(False) return False if boolean: conf.COMPOUND_END('ok') if define: conf.DEFINE(define, '1') else: ret = ret.strip() conf.COMPOUND_END(ret) if define: conf.DEFINE(define, ret, quote=True) return ret
def abi_check_task(self): '''check if the ABI has changed''' abi_gen = self.ABI_GEN libpath = self.inputs[0].abspath(self.env) libname = os.path.basename(libpath) sigs = samba_utils.get_string(Utils.cmd_output([abi_gen, libpath])) parsed_sigs = parse_sigs(sigs, self.ABI_MATCH) sig_file = self.ABI_FILE old_sigs = samba_utils.load_file(sig_file) if old_sigs is None or Options.options.ABI_UPDATE: if not save_sigs(sig_file, parsed_sigs): raise Errors.WafError('Failed to save ABI file "%s"' % sig_file) Logs.warn('Generated ABI signatures %s' % sig_file) return parsed_old_sigs = parse_sigs(old_sigs, self.ABI_MATCH) # check all old sigs got_error = False for s in parsed_old_sigs: if not s in parsed_sigs: Logs.error( '%s: symbol %s has been removed - please update major version\n\tsignature: %s' % (libname, s, parsed_old_sigs[s])) got_error = True elif normalise_varargs(parsed_old_sigs[s]) != normalise_varargs( parsed_sigs[s]): Logs.error( '%s: symbol %s has changed - please update major version\n\told_signature: %s\n\tnew_signature: %s' % (libname, s, parsed_old_sigs[s], parsed_sigs[s])) got_error = True for s in parsed_sigs: if not s in parsed_old_sigs: Logs.error( '%s: symbol %s has been added - please mark it _PRIVATE_ or update minor version\n\tsignature: %s' % (libname, s, parsed_sigs[s])) got_error = True if got_error: raise Errors.WafError( 'ABI for %s has changed - please fix library version then build with --abi-update\nSee http://wiki.samba.org/index.php/Waf#ABI_Checking for more information\nIf you have not changed any ABI, and your platform always gives this error, please configure with --abi-check-disable to skip this check' % libname)
def find_tru64cc(conf): v = conf.env cc = None if v['CC']: cc = v['CC'] elif 'CC' in conf.environ: cc = conf.environ['CC'] if not cc: cc = conf.find_program('cc', var='CC') if not cc: conf.fatal('tru64cc was not found') cc = conf.cmd_to_list(cc) try: if not Utils.cmd_output(cc + ['-V']): conf.fatal('tru64cc %r was not found' % cc) except ValueError: conf.fatal('tru64cc -V could not be executed') v['CC'] = cc v['CC_NAME'] = 'tru64'
def vcs_dir_contents(path): """Return the versioned files under a path. :return: List of paths relative to path """ repo = path while repo != "/": if os.path.exists(os.path.join(repo, ".git")): ls_files_cmd = [ 'git', 'ls-files', '--full-name', os.path.relpath(path, repo) ] cwd = None env = dict(os.environ) env["GIT_DIR"] = os.path.join(repo, ".git") break repo = os.path.dirname(repo) if repo == "/": raise Exception("unsupported or no vcs for %s" % path) return get_string(Utils.cmd_output(ls_files_cmd, cwd=cwd, env=env)).split('\n')
def find_irixcc(conf): v = conf.env cc = None if v['CC']: cc = v['CC'] elif 'CC' in conf.environ: cc = conf.environ['CC'] if not cc: cc = conf.find_program('cc', var='CC') if not cc: conf.fatal('irixcc was not found') cc = conf.cmd_to_list(cc) try: if Utils.cmd_output(cc + ['-c99'] + ['-version']) != '': conf.fatal('irixcc %r was not found' % cc) except ValueError: conf.fatal('irixcc -v could not be executed') conf.env.append_unique('CCFLAGS', '-c99') v['CC'] = cc v['CC_NAME'] = 'irix'
def exec_test(self): testlock.acquire() fail = False try: filename = self.inputs[0].abspath(self.env) try: fu = getattr(self.generator.bld, 'all_test_paths') except AttributeError: fu = os.environ.copy() self.generator.bld.all_test_paths = fu lst = [] for g in self.generator.bld.groups: for tg in g: link_task = getattr(tg, 'link_task', None) if link_task: lst.append(link_task.outputs[0].parent.abspath()) def add_path(dct, path, var): dct[var] = os.pathsep.join(Utils.to_list(path) + [os.environ.get(var, '')]) if sys.platform == 'win32': add_path(fu, lst, 'PATH') elif sys.platform == 'darwin': add_path(fu, lst, 'DYLD_LIBRARY_PATH') add_path(fu, lst, 'LD_LIBRARY_PATH') else: add_path(fu, lst, 'LD_LIBRARY_PATH') try: ret = Utils.cmd_output(filename, cwd=self.inputs[0].parent.abspath(self.env), env=fu) except Exception as e: fail = True ret = '' + str(e) else: pass stats = getattr(self.generator.bld, 'utest_results', []) stats.append((filename, fail, ret)) self.generator.bld.utest_results = stats finally: testlock.release()
def CHECK_STANDARD_LIBPATH(conf): # at least gcc and clang support this: try: cmd = conf.env.CC + ['-print-search-dirs'] out = Utils.cmd_output(cmd).decode('utf8').split('\n') except ValueError: # option not supported by compiler - use a standard list of directories dirlist = ['/usr/lib', '/usr/lib64'] except: raise Errors.WafError('Unexpected error running "%s"' % (cmd)) else: dirlist = [] for line in out: line = line.strip() if line.startswith("libraries: ="): dirliststr = line[len("libraries: ="):] dirlist = [os.path.normpath(x) for x in dirliststr.split(':')] break conf.env.STANDARD_LIBPATH = dirlist
def read_perl_config_var(cmd): return Utils.to_list( Utils.cmd_output( [conf.env.get_flat('PERL'), '-MConfig', '-e', cmd]))
def read_perl_config_var(cmd): output = Utils.cmd_output( [conf.env.get_flat('PERL'), '-MConfig', '-e', cmd]) if not isinstance(output, str): output = output.decode('utf8') return Utils.to_list(output)