def coccinelle(dsc, analysis): raise NotImplemented("Not ported") run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): log = "" failed = False for semantic_patch in list_semantic_patches(): out, err, ret = run_command([ "spatch", "-D", "firehose", "--cocci-file", semantic_patch, "--dir", ".", "--no-show-diff", "--timeout", "120", ]) failed = (ret != 0) or failed parsed_results = parse_coccinelle(out) result_count = 0 for result in parsed_results: analysis.results.append(result) result_count += 1 log += "DEAL patch %s\n" % semantic_patch log += " %d results\n" % result_count return (analysis, log, failed, None)
def coccinelle(dsc, analysis): raise NotImplemented("Not ported") run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): log = "" failed = False for semantic_patch in list_semantic_patches(): out, err, ret = run_command([ "spatch", "-D", "firehose", "--cocci-file", semantic_patch, "--dir", ".", "--no-show-diff", "--timeout", "120", ]) failed = (ret != 0) or failed parsed_results = parse_coccinelle(out) result_count = 0 for result in parsed_results: analysis.results.append(result) result_count += 1 log += "DEAL patch %s\n" % semantic_patch log += " %d results\n" % result_count return (analysis, log, failed, None)
def pep8(dsc, analysis): run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): out, err, ret = run_command(['pep8', '.']) failed = ret != 0 for issue in parse_pep8(out.splitlines()): analysis.results.append(issue) return (analysis, out, failed, None)
def pep8(dsc, analysis): run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): out, err, ret = run_command(['pep8', '.']) failed = ret != 0 for issue in parse_pep8(out.splitlines()): analysis.results.append(issue) return (analysis, out, failed, None)
def perlcritic(dsc, analysis): run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): out, err, ret = run_command([ 'perlcritic', '--brutal', '.', '--verbose', '%f:%l:%c %s %p %m\n' ]) if ret == 1: raise Exception("Perlcritic had an internal error") failed = ret == 2 for issue in parse_perlcritic(out.splitlines()): analysis.results.append(issue) return (analysis, out, failed, None)
def sbuild(package, suite, arch, analysis): # chroot_name = "%s-%s" % (suite, arch) chroot_name = suite dsc = os.path.basename(package) if not dsc.endswith(".dsc"): raise ValueError("WTF") source, dsc = dsc.split("_", 1) version, _ = dsc.rsplit(".", 1) local = None if "-" in version: version, local = version.rsplit("-", 1) out, err, ret = run_command( [ "sbuild", ("--arch-all" if arch == "all" else "--no-arch-all"), "-c", chroot_name, "-v", "-d", suite, "-j", "8", package, ] ) ftbfs = ret != 0 return analysis, out, ftbfs, glob.glob("*changes")
def binary(): url = proxy.get_deb_url(package['binary_id']) deb = os.path.basename(url) out, err, ret = run_command(['wget', url]) if ret != 0: raise Exception("zomgwtf") yield deb
def sbuild(package, suite, arch, analysis): #chroot_name = "%s-%s" % (suite, arch) chroot_name = suite ensure_chroot_sanity(chroot_name) dsc = os.path.basename(package) if not dsc.endswith('.dsc'): raise ValueError("WTF") source, dsc = dsc.split("_", 1) version, _ = dsc.rsplit(".", 1) local = None if "-" in version: version, local = version.rsplit("-", 1) out, err, ret = run_command([ "sbuild", ("--arch-all" if arch == 'all' else '--no-arch-all'), "-c", chroot_name, "-v", "-d", suite, "-j", "8", package, ]) ftbfs = ret != 0 return analysis, out, ftbfs, glob.glob("*changes")
def sbuild(package, suite, arch, affinity, analysis): chroot_name = "{suite}-{affinity}".format(suite=suite, affinity=affinity) ensure_chroot_sanity(chroot_name) dsc = os.path.basename(package) if not dsc.endswith('.dsc'): raise ValueError("WTF") source, dsc = dsc.split("_", 1) version, _ = dsc.rsplit(".", 1) local = None if "-" in version: version, local = version.rsplit("-", 1) out, err, ret = run_command([ "sbuild", "--dist={suite}".format(suite=suite), "--arch={affinity}".format(affinity=affinity), "--chroot={chroot_name}".format(chroot_name=chroot_name), ("--arch-all" if arch == 'all' else '--no-arch-all'), "-v", "-j", "8", package, ]) ftbfs = ret != 0 return analysis, out, ftbfs, glob.glob("*changes")
def version(): out, err, ret = run_command([ 'pep8', '--version' ]) if ret != 0: raise Exception("pep8 is not installed") return ('pep8', out.strip())
def version(): out, err, ret = run_command([ 'cppcheck', '--version' ]) if ret != 0: raise Exception("cppcheck is not installed") name, version = out.split(" ") return (name, version.strip())
def ensure_chroot_sanity(chroot_name): out, ret, err = run_command(['schroot', '-l']) for chroot in out.splitlines(): chroot = chroot.strip() chroots = [chroot, "chroot:%s" % (chroot)] if chroot in chroots: return True raise ValueError("No such schroot (%s) found." % (chroot_name))
def version(lintian_binary='lintian'): out, err, ret = run_command([ lintian_binary, '--version' ]) if ret != 0: raise Exception(lintian_binary + " is not installed") name, version = out.split(" ") return (name, version.strip())
def version(): out, err, ret = run_command(["sbuild", "--version"]) if ret != 0: raise Exception("sbuild is not installed") vline = out.splitlines()[0] v = VERSION.match(vline) vdict = v.groupdict() return ("sbuild", vdict["version"])
def version(): out, err, ret = run_command([ 'fb', '-version' ]) if ret != 0: raise Exception("findbugs is not installed") name, version = out.split(" ") return (name, version.strip())
def version(): out, err, ret = run_command(["sbuild", '--version']) if ret != 0: raise Exception("sbuild is not installed") vline = out.splitlines()[0] v = VERSION.match(vline) vdict = v.groupdict() return ('sbuild', vdict['version'])
def version(): out, err, ret = run_command(["spatch", "--version"]) if ret != 0: raise Exception("spatch seems not to be installed") try: out = out.split()[2] # we only extract the version number except: out = out.strip() return ('coccinelle', out)
def version(): out, err, ret = run_command(["spatch", "--version"]) if ret != 0: raise Exception("spatch seems not to be installed") try: out = out.split()[2] # we only extract the version number except: out = out.strip() return ('coccinelle', out)
def ensure_chroot_sanity(chroot_name): out, ret, err = run_command(['schroot', '-l']) for chroot in out.splitlines(): chroot = chroot.strip() chroots = [ chroot, "chroot:%s" % (chroot) ] if chroot in chroots: return True raise ValueError("No such schroot (%s) found." % (chroot_name))
def cppcheck(dsc, analysis): run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): out, err, ret = run_command( ['cppcheck', '-j8', '--enable=all', '.', '--xml']) xmlbytes = err.encode() failed = False if err.strip() == '': return (analysis, err, failed) for issue in parse_cppcheck(xmlbytes): analysis.results.append(issue) if not failed and issue.severity in [ 'performance', 'portability', 'error', 'warning' ]: failed = True return (analysis, err, failed, None)
def findbugs(deb, analysis): run_command(["dpkg", "-x", deb, "binary"]) with cd('binary'): out, err, ret = run_command([ 'fb', 'analyze', '-effort:max', '-xml:withMessages', '.' ]) xmlbytes = out.encode("utf-8") failed = False # if err.strip() == '': # return (analysis, err, failed) for issue in parse_findbugs(xmlbytes): analysis.results.append(issue) if not failed and issue.severity in [ 'performance', 'portability', 'error', 'warning' ]: failed = True return (analysis, err, failed, None)
def desktop_file_validate(package_root, analysis): log = "" failed = False for dirpath, dirnames, filenames in os.walk(package_root): for fp in filenames: out, err, ret = run_command(['desktop-file-validate', fp]) for issue in parse_desktop_file_validate(out.splitlines()): analysis.results.append(issue) failed = True log += out log = log.strip() return (analysis, log, failed, None)
def cppcheck(dsc, analysis): run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): out, err, ret = run_command([ 'cppcheck', '-j8', '--enable=all', '.', '--xml' ]) xmlbytes = err.encode() failed = False if err.strip() == '': return (analysis, err, failed) for issue in parse_cppcheck(xmlbytes): analysis.results.append(issue) if not failed and issue.severity in [ 'performance', 'portability', 'error', 'warning' ]: failed = True return (analysis, err, failed, None)
def clanganalyzer(package, suite, arch, analysis): raise NotImplemented("Not ported") chroot_name = "%s-%s" % (suite, arch) with schroot(chroot_name) as chroot: # We should have the dsc file to bulid dsc = os.path.basename(package) if not dsc.endswith(".dsc"): raise ValueError("clanganalyzer runner must receive a dsc file") # Setup the chroot for scan-build run # 1/ install clang # TODO: check the return codes out, err, ret = chroot.run(["apt-get", "install", "-y", "clang", "wget"], user="******") # 2/ fake dpkg-buildpackage in the schroot # Replace the real dpkg-buildpackage by our script out_, err, ret = chroot.run( ["mv", "/usr/bin/dpkg-buildpackage", "/usr/bin/dpkg-buildpackage.faked"], user="******" ) out += out_ internal_report_dir = "/tmp/scan-build/" # We will output the scan-build plist reports there out_, err, ret = chroot.run(["mkdir", "-p", internal_report_dir], user="******") out += out_ out_, err, ret = chroot.run(["chmod", "777", internal_report_dir], user="******") out += out_ # Create the script fake_dpkg_url = "http://leo.cavaille.net/public/dpkg-buildpackage-html" out_, err, ret = chroot.run(["wget", "-O", "/usr/bin/dpkg-buildpackage", fake_dpkg_url], user="******") out += out_ # Make it executable out_, err, ret = chroot.run(["chmod", "755", "/usr/bin/dpkg-buildpackage"], user="******") out += out_ # Now run sbuild in this session chroot for the package out_, err, ret = run_command( ["sbuild", "-A", "--use-schroot-session", chroot.session, "-v", "-d", suite, "-j", "8", package] ) out += out_ # Parse the plist reports into Firehose and return # WARN : if the previous run did not delete the folder, this will fail # worst, if we run several instances of virtual builders, this will # fail because by default /tmp is a bind mount from the physical server reports_dir = glob.glob(internal_report_dir + "*") ### SCANDALOUS HACK !! return analysis, out, reports_dir, None
def lintian(targets, analysis, lintian_binary='lintian'): if not isinstance(targets, list): targets = [targets,] log = "" failed = False for target in targets: out, err, ret = run_command([lintian_binary, "-IE", "--pedantic", "--show-overrides", target]) for issue in parse_lintian(out.splitlines(), target): analysis.results.append(issue) if issue.severity in ['warning', 'error']: failed = True log += out return (analysis, log, failed, None)
def run(dsc, source, job, firehose): run_command(["dpkg-source", "-x", dsc, "source"]) with cd('source'): return desktop_file_validate('source', firehose)
def version(): out, err, ret = run_command(['perlcritic', '--version']) if ret != 0: raise Exception("perlcritic is not installed") return ('perlcritic', out.strip())
def clanganalyzer(package, suite, arch, analysis): raise NotImplemented("Not ported") chroot_name = "%s-%s" % (suite, arch) with schroot(chroot_name) as chroot: # We should have the dsc file to bulid dsc = os.path.basename(package) if not dsc.endswith('.dsc'): raise ValueError("clanganalyzer runner must receive a dsc file") # Setup the chroot for scan-build run # 1/ install clang # TODO: check the return codes out, err, ret = chroot.run([ 'apt-get', 'install', '-y', 'clang', 'wget' ], user='******') # 2/ fake dpkg-buildpackage in the schroot # Replace the real dpkg-buildpackage by our script out_, err, ret = chroot.run([ 'mv', '/usr/bin/dpkg-buildpackage', '/usr/bin/dpkg-buildpackage.faked' ], user='******') out += out_ internal_report_dir = "/tmp/scan-build/" # We will output the scan-build plist reports there out_, err, ret = chroot.run([ 'mkdir', '-p', internal_report_dir ], user='******') out += out_ out_, err, ret = chroot.run([ 'chmod', '777', internal_report_dir ], user='******') out += out_ # Create the script fake_dpkg_url = "http://leo.cavaille.net/public/dpkg-buildpackage-html" out_, err, ret = chroot.run([ 'wget', '-O', '/usr/bin/dpkg-buildpackage', fake_dpkg_url ], user='******') out += out_ # Make it executable out_, err, ret = chroot.run([ 'chmod', '755', '/usr/bin/dpkg-buildpackage' ], user='******') out += out_ # Now run sbuild in this session chroot for the package out_, err, ret = run_command([ "sbuild", "-A", "--use-schroot-session", chroot.session, "-v", "-d", suite, "-j", "8", package, ]) out += out_ # Parse the plist reports into Firehose and return # WARN : if the previous run did not delete the folder, this will fail # worst, if we run several instances of virtual builders, this will # fail because by default /tmp is a bind mount from the physical server reports_dir = glob.glob(internal_report_dir+'*') ### SCANDALOUS HACK !! return analysis, out, reports_dir, None
def version(): out, err, ret = run_command(['cppcheck', '--version']) if ret != 0: raise Exception("cppcheck is not installed") name, version = out.split(" ") return (name, version.strip())