Example #1
0
def do_build(srpm, target, build_number, use_mock, xs_build_sys):
    if xs_build_sys:
	mock = "/usr/bin/mock"
    else:
	mock = "mock"
    if use_mock:
        cmd = [mock, "--configdir=mock", 
               "--resultdir=%s" % TMP_RPM_PATH, "--rebuild",
               "--target", target,
#               "--enable-plugin=tmpfs",
               "--define", "extrarelease .%d" % build_number,
               "-v", srpm]
        if not xs_build_sys:
            cmd = ["sudo"] + cmd + ["--disable-plugin=package_state"]
    else:
        cmd = ["rpmbuild", "--rebuild", "-v", "%s" % srpm,
               "--target", target, "--define",
               "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"]

    doexec(cmd)

    srpms = glob.glob(os.path.join(TMP_RPM_PATH, "*.src.rpm"))
    for srpm in srpms:
        print_col(bcolours.WARNING,"Removing SRPM %s" % srpm)        
        os.unlink(srpm)

    return glob.glob(os.path.join(TMP_RPM_PATH, "*.rpm"))
Example #2
0
def do_build(srpm, target, build_number, use_mock, xs_build_sys):
    if xs_build_sys:
        mock = ["/usr/bin/mock"]
    else:
        mock = ["planex-cache", "--debug"]
    if use_mock:
        cmd = mock + ["--configdir=%s" % MOCK_DIR,
                      "--resultdir=%s" % TMP_RPM_PATH, "--rebuild",
                      "--target", target,
                      # "--enable-plugin=tmpfs",
                      "--define", "extrarelease .%d" % build_number,
                      "-v"]
        if not xs_build_sys:
            cmd = cmd + ["--disable-plugin=package_state"]
    else:
        cmd = ["rpmbuild", "--rebuild", "-v",
               "--target", target, "--define",
               "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"]

    res = run(cmd + [srpm])

    print "stdout: %s" % res['stdout']
    srpms = glob.glob(os.path.join(TMP_RPM_PATH, "*.src.rpm"))
    for srpm in srpms:
        print_col(bcolours.WARNING, "Removing SRPM %s" % srpm)
        os.unlink(srpm)

    return glob.glob(os.path.join(TMP_RPM_PATH, "*.rpm"))
Example #3
0
def ensure_existing_ok(hashes, spec_path):
    pkg_name = name_from_spec(spec_path)

    one_correct = False

    for srpm in glob.glob(os.path.join(SRPMS_DIR, '%s-*.src.rpm' % pkg_name)):
        # Check it's for the right package:
        cmd = ["rpm", "-qp", srpm, "--qf", "%{name}"]
        result = run(cmd)['stdout'].strip().split('\n')

        if result[0] == pkg_name:
            cmd = ["rpm", "--dump", "-qp", srpm]
            result = run(cmd)['stdout'].strip().split('\n')
            ok = True
            for line in result:
                split = line.split()
                fname = split[0]
                thishash = split[3]
                if fname not in hashes or hashes[fname] != thishash:
                    ok = False

            if not ok:
                print_col(
                    bcolours.WARNING,
                    "WARNING: Removing SRPM '%s' (hash mismatch with desired)"
                    % srpm)
                os.remove(srpm)
            else:
                one_correct = True

    return one_correct
Example #4
0
def ensure_existing_ok(hashes, spec_path):
    pkg_name = name_from_spec(spec_path)

    one_correct = False

    for srpm in glob.glob(os.path.join(SRPMS_DIR, '%s-*.src.rpm' % pkg_name)):
        # Check it's for the right package:
        cmd = ["rpm", "-qp", srpm, "--qf", "%{name}"]
        result = run(cmd)['stdout'].strip().split('\n')

        if result[0] == pkg_name:
            cmd = ["rpm", "--dump", "-qp", srpm]
            result = run(cmd)['stdout'].strip().split('\n')
            is_ok = True
            for line in result:
                split = line.split()
                fname = split[0]
                thishash = split[3]
                if fname not in hashes or hashes[fname] != thishash:
                    is_ok = False

            if not is_ok:
                print_col(bcolours.WARNING,
                          "WARNING: Removing SRPM '%s' "
                          "(hash mismatch with desired)" % srpm)
                os.remove(srpm)
            else:
                one_correct = True

    return one_correct
Example #5
0
def dump_manifest():
    print "---------------------------------------"
    print_col(bcolours.OKGREEN, "MANIFEST")
    sources = MANIFEST.keys()
    sources.sort()
    for source in sources:
        basename = source.split("/")[-1]
        if basename.endswith(".git"):
            basename = basename[:-4]
        if basename.endswith(".hg"):
            basename = basename[:-3]
        print basename.rjust(40), MANIFEST[source]
Example #6
0
def dump_manifest():
    print "---------------------------------------"
    print_col(bcolours.OKGREEN, "MANIFEST")
    sources = manifest.keys()
    sources.sort()
    for source in sources:
        basename = source.split("/")[-1]
        if basename.endswith(".git"):
            basename = basename[:-4]
        if basename.endswith(".hg"):
            basename = basename[:-3]
        print basename.rjust(40), manifest[source]
Example #7
0
def build_srpms(config):
    """Build SRPMs for all SPECs"""
    print_col(bcolours.OKGREEN, "Building/checking SRPMS for all files in SPECSDIR")
    print "  Getting %s hashes for source to check against existing SRPMS..." % HASHFN,
    sys.stdout.flush()
    hashes = get_hashes(HASHFN)
    print "OK"
    specs = glob.glob(SPECS_GLOB)
    n=0
    for spec_path in specs:
        prepare_srpm(spec_path, config)
        n+=build_srpm(hashes, spec_path)
    print_col(bcolours.OKGREEN,"Rebuilt %d out of %d SRPMS" % (n,len(specs)))
Example #8
0
def build_srpms(config):
    """Build SRPMs for all SPECs"""
    print_col(bcolours.OKGREEN,
              "Building/checking SRPMS for all files in SPECSDIR")
    print "  Getting %s hashes for source to check against existing SRPMS..." % HASHFN,
    sys.stdout.flush()
    hashes = get_hashes(HASHFN)
    print "OK"
    specs = glob.glob(SPECS_GLOB)
    n = 0
    for spec_path in specs:
        prepare_srpm(spec_path, config)
        n += build_srpm(hashes, spec_path)
    print_col(bcolours.OKGREEN, "Rebuilt %d out of %d SRPMS" % (n, len(specs)))
Example #9
0
def sort_mockconfig(config):
    config_dir = config.config_dir
    if not os.path.exists('mock'):
        os.makedirs('mock')
        print_col(bcolours.OKGREEN, "Creating mock configuration for current working directory")
        # Copy in all the files from config_dir
        mock_files = glob.glob(os.path.join(config_dir,'mock','*'))

        for f in mock_files:
            basename = f.split('/')[-1]
            dest_fname = os.path.join('mock',basename)
            print "  copying file '%s' to '%s'" % (f,dest_fname)
            shutil.copyfile(f,dest_fname)
            planex_build_root = os.path.join(os.getcwd(),BUILD_ROOT_DIR)
            with open(dest_fname,'w') as dst:
                with open(f) as src:
                    for line in src:
                        dst.write(re.sub(r"@PLANEX_BUILD_ROOT@", planex_build_root, line))
Example #10
0
def main(argv):
    """
    Main function.  Process all the specfiles in the directory
    given by config_dir.
    """
    config = parse_cmdline(argv)
    try:
        sort_makefile()
        prepare_buildroot()
        sort_mockconfig(config)
        copy_patches_to_buildroot(config)
        copy_specs_to_buildroot(config)
        if config.build_srpms:
            build_srpms(config)
        dump_manifest()
    except exceptions.NoRepository:
        print_col(bcolours.FAIL,
                  "No repository found: have you run 'planex-clone'?")
        sys.exit(1)
Example #11
0
def sort_mockconfig(config):
    config_dir = config.config_dir
    if not os.path.exists('mock'):
        os.makedirs('mock')
        print_col(bcolours.OKGREEN,
                  "Creating mock configuration for current working directory")
        # Copy in all the files from config_dir
        mock_files = glob.glob(os.path.join(config_dir, 'mock', '*'))

        for f in mock_files:
            basename = f.split('/')[-1]
            dest_fname = os.path.join('mock', basename)
            print "  copying file '%s' to '%s'" % (f, dest_fname)
            shutil.copyfile(f, dest_fname)
            planex_build_root = os.path.join(os.getcwd(), BUILD_ROOT_DIR)
            with open(dest_fname, 'w') as dst:
                with open(f) as src:
                    for line in src:
                        dst.write(
                            re.sub(r"@PLANEX_BUILD_ROOT@", planex_build_root,
                                   line))
Example #12
0
def sort_makefile():
    name = "Makefile"
    makefile_common = resource_string(__name__, 'Makefile.common')
    firstline = "# Autogenerated by planex. Do not edit!\n"
    # If there's a makefile already there, check it was written by us
    try:
        with open(name) as makefile:
            line = makefile.readline()
            if line != firstline:
                print_col(bcolours.OKGREEN,
                          "Not overwriting existing Makefile")
                return
    except IOError:
        # Makefile does not exist
        pass

    with open(name, 'w') as makefile:
        makefile.write(firstline)
        makefile.write("DIST := .el6\n")
        makefile.write("all : rpms\n")
        makefile.write(makefile_common)
Example #13
0
def copy_specs_to_buildroot(config):
    """Pull in spec files, preprocessing if necessary"""
    config_dir = config.config_dir
    specs = glob.glob(os.path.join(config_dir, config.specs_path, "*.spec"))
    spec_ins = glob.glob(os.path.join(config_dir, config.specs_path, "*.spec.in"))
    for spec_path in specs + spec_ins:
        check_spec_name(spec_path)
        basename = spec_path.split("/")[-1]
        if spec_path.endswith('.in'):
            print_col(bcolours.OKGREEN,"Configuring and fetching sources for '%s'" % basename)
            scmsources = [sources.Source(source, config) for source in sources_from_spec(spec_path)
                          if (is_scm(source))]
            mapping = {}
            for source in scmsources:
                source.pin()
                manifest[source.repo_name]=source.scmhash
                mapping[source.orig_url]=source.extendedurl
            preprocess_spec(spec_path, SPECS_DIR, scmsources, mapping)
        else:
            print_col(bcolours.OKGREEN, "Fetching sources for '%s'" % basename)
            shutil.copy(spec_path, SPECS_DIR)
Example #14
0
def sort_mockconfig(config):
    config_dir = config.config_dir
    if not os.path.exists(MOCK_DIR):
        print_col(bcolours.OKGREEN,
                  "Creating mock configuration for current working directory")

        yum_config = load_mock_config(os.path.join(config_dir,
                                                   'mock', 'default.cfg'))
        yumbase = get_yumbase(yum_config)
        if yumbase.repos.findRepos(PLANEX_REPO_NAME) == []:
            print_col(bcolours.FAIL, "Planex repository not found")
            print """
Please add a repository stanza similar to:

[%s]
name=Mock output
baseurl = file://@PLANEX_BUILD_ROOT@/RPMS
gpgcheck=0
priority=1
enabled=1
metadata_expire=0
""" % PLANEX_REPO_NAME
            sys.exit(1)

        os.makedirs(MOCK_DIR)

        # Copy in all the files from config_dir
        mock_files = glob.glob(os.path.join(config_dir, 'mock', '*'))

        for mock_file in mock_files:
            basename = mock_file.split('/')[-1]
            dest_fname = os.path.join(MOCK_DIR, basename)
            print "  copying file '%s' to '%s'" % (mock_file, dest_fname)
            shutil.copyfile(mock_file, dest_fname)
            planex_build_root = os.path.join(os.getcwd(), BUILD_ROOT_DIR)
            with open(dest_fname, 'w') as dst:
                with open(mock_file) as src:
                    for line in src:
                        dst.write(re.sub(r"@PLANEX_BUILD_ROOT@",
                                         planex_build_root, line))
Example #15
0
def build_srpm(srpm, srpm_infos, external, deps, use_mock, xs_build_sys):
    cache_dir = get_cache_dir(srpm_infos, external, deps, srpm)

    if (need_to_build(srpm_infos, external, deps, srpm)):
        target = extract_target(srpm_infos, srpm)
        build_number = get_new_number(srpm, cache_dir)
        print_col(bcolours.OKGREEN,
                  "CACHE MISS: Building %s (%d)" % (srpm, build_number))
        createrepo()

        pkgs = do_build(srpm, target, build_number, use_mock, xs_build_sys)
        if cache_dir:
            try:
                os.makedirs(cache_dir + ".tmp")
                print "Archiving result in cache"
                for pkg in pkgs:
                    shutil.copy(pkg, cache_dir + ".tmp")
                os.rename(cache_dir + ".tmp", cache_dir)
            except:
                print bgcolors.WARNING + "FAILED TO PUT BUILD RESULTS INTO CACHE"

    else:
        print_col(bcolours.OKGREEN, "CACHE HIT: Not building %s" % srpm)
        pkgs = glob.glob(os.path.join(cache_dir, "*.rpm"))
        for pkg in pkgs:
            shutil.copy(pkg, TMP_RPM_PATH)
        mytime = time.time()
        os.utime(cache_dir, (mytime, mytime))
        pkgs = glob.glob(os.path.join(TMP_RPM_PATH, "*.rpm"))

    if not use_mock:
        result = doexec(["rpm", "-U", "--force", "--nodeps"] + pkgs,
                        check=False)
        if result['rc'] != 0:
            print "Ignoring failure installing rpm batch: %s" % pkgs
            print result['stderr']

    for pkg in pkgs:
        shutil.move(pkg, RPMS_DIR)
Example #16
0
def build_srpm(srpm, srpm_infos, external, deps, use_mock, xs_build_sys):
    cache_dir = get_cache_dir(srpm_infos, external, deps, srpm)

    if need_to_build(srpm_infos, external, deps, srpm):
        target = extract_target(srpm_infos, srpm)
        build_number = get_new_number(srpm, cache_dir)
        print_col(bcolours.OKGREEN,
                  "CACHE MISS: Building %s (%d)" % (srpm, build_number))
        createrepo()

        pkgs = do_build(srpm, target, build_number, use_mock, xs_build_sys)
        if cache_dir:
            try:
                os.makedirs(cache_dir + ".tmp")
                print "Archiving result in cache"
                for pkg in pkgs:
                    shutil.copy(pkg, cache_dir + ".tmp")
                os.rename(cache_dir + ".tmp", cache_dir)
            except (OSError, IOError):
                print bcolours.WARNING + \
                    "FAILED TO PUT BUILD RESULTS INTO CACHE"

    else:
        print_col(bcolours.OKGREEN, "CACHE HIT: Not building %s" % srpm)
        pkgs = glob.glob(os.path.join(cache_dir, "*.rpm"))
        for pkg in pkgs:
            shutil.copy(pkg, TMP_RPM_PATH)
        mytime = time.time()
        os.utime(cache_dir, (mytime, mytime))
        pkgs = glob.glob(os.path.join(TMP_RPM_PATH, "*.rpm"))

    if not use_mock:
        result = run(["rpm", "-U", "--force", "--nodeps"] + pkgs, check=False)
        if result['rc'] != 0:
            print "Ignoring failure installing rpm batch: %s" % pkgs
            print result['stderr']

    for pkg in pkgs:
        shutil.move(pkg, RPMS_DIR)
Example #17
0
def do_build(srpm, target, build_number, use_mock, xs_build_sys):
    if xs_build_sys:
        mock = "/usr/bin/mock"
    else:
        mock = "mock"
    if use_mock:
        cmd = [
            mock,
            "--configdir=mock",
            "--resultdir=%s" % TMP_RPM_PATH,
            "--rebuild",
            "--target",
            target,
            #               "--enable-plugin=tmpfs",
            "--define",
            "extrarelease .%d" % build_number,
            "-v",
            srpm
        ]
        if not xs_build_sys:
            cmd = ["sudo"] + cmd + ["--disable-plugin=package_state"]
    else:
        cmd = [
            "rpmbuild", "--rebuild", "-v",
            "%s" % srpm, "--target", target, "--define",
            "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"
        ]

    doexec(cmd)

    srpms = glob.glob(os.path.join(TMP_RPM_PATH, "*.src.rpm"))
    for srpm in srpms:
        print_col(bcolours.WARNING, "Removing SRPM %s" % srpm)
        os.unlink(srpm)

    return glob.glob(os.path.join(TMP_RPM_PATH, "*.rpm"))
Example #18
0
def copy_specs_to_buildroot(config):
    """Pull in spec files, preprocessing if necessary"""
    config_dir = config.config_dir
    specs = glob.glob(os.path.join(config_dir, "*.spec"))
    spec_ins = glob.glob(os.path.join(config_dir, "*.spec.in"))
    for spec_path in specs + spec_ins:
        check_spec_name(spec_path)
        basename = spec_path.split("/")[-1]
        if spec_path.endswith('.in'):
            print_col(bcolours.OKGREEN,
                      "Configuring and fetching sources for '%s'" % basename)
            scmsources = [
                sources.Source(source, config)
                for source in sources_from_spec(spec_path) if (is_scm(source))
            ]
            mapping = {}
            for source in scmsources:
                source.pin()
                manifest[source.repo_name] = source.scmhash
                mapping[source.orig_url] = source.extendedurl
            preprocess_spec(spec_path, SPECS_DIR, scmsources, mapping)
        else:
            print_col(bcolours.OKGREEN, "Fetching sources for '%s'" % basename)
            shutil.copy(spec_path, SPECS_DIR)