def test_autosetup_present(self): """Patchqueue application succeeds if %autosetup is present""" spec = Spec("tests/data/branding-xenserver.spec", check_package_name=False) spec.add_patch(0, Blob(spec, "first.patch", "dummy")) rewritten = spec.rewrite_spec() self.assertIn("Patch0: first.patch\n", rewritten)
def main(argv=None): """ Entry point """ args = parse_args_or_exit(argv) util.setup_logging(args) link = Link(args.link) # Repo and ending tag are specified in the link file repo = link.url end_tag = link.commitish if end_tag is None: end_tag = "HEAD" # If the repository URL in the link is remote, look for a # local clone in repos (without a .git suffix) url = urlparse(repo) if url.scheme: reponame = os.path.basename(url.path).rsplit(".git")[0] repo = os.path.join(args.repos, reponame) util.makedirs(os.path.dirname(args.tarball)) with open('{0}.origin'.format(args.tarball), 'w') as origin_file: origin_file.write('{0}\n'.format(git.origin_url(repo))) if repo.endswith(".pg"): with FileUpdate(args.tarball) as outfile: git.archive(repo, end_tag, outfile) sys.exit(0) # Start tag is based on the version specified in the spec file, # but the tag name may be slightly different (v1.2.3 rather than 1.2.3) # If the link file does not list a spec file, assume that there is one in # the usual place basename = os.path.splitext(os.path.basename(args.link))[0] spec_path = os.path.join("SPECS", "%s.spec" % basename) spec = Spec(spec_path) start_tag = link.base_commitish if start_tag is None: start_tag = spec.version() if start_tag not in git.tags(repo): start_tag = "v%s" % start_tag try: tmpdir = tempfile.mkdtemp(prefix="px-pq-") assemble_patchqueue(tmpdir, link, repo, start_tag, end_tag) assemble_extra_sources(tmpdir, repo, spec, link) with FileUpdate(args.tarball) as outfile: tarball.make(tmpdir, outfile) finally: if args.keeptmp: print("Working directory retained at %s" % tmpdir) else: shutil.rmtree(tmpdir)
def test_overridden_patch_in_spec(self): """Patches with the same index override each other""" spec = Spec("tests/data/branding-xenserver.spec", check_package_name=False) spec.add_patch(0, Blob(spec, "first.patch", "dummy")) spec.add_patch(1, Blob(spec, "second.patch", "dummy")) spec.add_patch(0, Blob(spec, "third.patch", "dummy")) rewritten = spec.rewrite_spec() self.assertNotIn("Patch0: first.patch\n", rewritten) self.assertIn("Patch1: second.patch\n", rewritten) self.assertIn("Patch0: third.patch\n", rewritten)
def test_rewrite_spec(self): """Patches are inserted into rewritten spec file""" spec = Spec("tests/data/branding-xenserver.spec", check_package_name=False) spec.add_patch(0, Blob(spec, "first.patch", "dummy")) spec.add_patch(1, Blob(spec, "second.patch", "dummy")) spec.add_patch(2, Blob(spec, "third.patch", "dummy")) rewritten = spec.rewrite_spec() self.assertIn("Patch0: first.patch\n", rewritten) self.assertIn("Patch1: second.patch\n", rewritten) self.assertIn("Patch2: third.patch\n", rewritten)
def test_autosetup_present(self): """Patchqueue application succeeds if %autosetup is present""" spec = Spec("tests/data/manifest/branding-xenserver.spec", check_package_name=False) patches = ["first.patch"] rewritten = planex.patchqueue.expand_patchqueue(spec, patches) self.assertIn("Patch0: first.patch\n", rewritten)
def test_rewrite_spec(self): spec = Spec("tests/data/ocaml-uri.spec", check_package_name=False) patches = ["first.patch", "second.patch", "third.patch"] rewritten = planex.patchqueue.expand_patchqueue(spec, patches) self.assertIn("Patch0: first.patch\n", rewritten) self.assertIn("Patch1: second.patch\n", rewritten) self.assertIn("Patch2: third.patch\n", rewritten)
def test_autosetup_disabled(self): """Patchqueue application fails if %autosetup is not present""" spec = Spec("tests/data/ocaml-uri.spec", check_package_name=False) spec.add_patch(0, Blob(spec, "first.patch", "dummy")) spec.disable_autosetup() rewritten = spec.rewrite_spec() self.assertIn("Patch0: first.patch\n", rewritten)
def test_rewrite_spec(self): """Patches are inserted into rewritten spec file""" spec = Spec("tests/data/manifest/branding-xenserver.spec", check_package_name=False) patches = ["first.patch", "second.patch", "third.patch"] rewritten = planex.patchqueue.expand_patchqueue(spec, patches) self.assertIn("Patch0: first.patch\n", rewritten) self.assertIn("Patch1: second.patch\n", rewritten) self.assertIn("Patch2: third.patch\n", rewritten)
def populate_working_directory(tmpdir, spec, link, sources, patchqueue): """ Build a working directory containing everything needed to build the SRPM. """ # Copy spec to working area tmp_specfile = os.path.join(tmpdir, os.path.basename(spec)) shutil.copyfile(spec, tmp_specfile) manifests = {} # Copy sources to working area for source in sources: extract_commit(source, manifests) shutil.copy(source, tmpdir) if manifests: add_manifest_entry(manifests, tmp_specfile) else: print("No .gitarchive-info found for {0}".format(spec)) spec = Spec(tmp_specfile, check_package_name=False) # Expand patchqueue to working area, rewriting spec as needed if link and patchqueue: # Extract patches if link.patchqueue is not None: with Patchqueue(patchqueue, branch=link.patchqueue) as patches: patches.extract_all(tmpdir) patches.add_to_spec(spec, tmp_specfile) # Extract non-patchqueue sources with Tarball(patchqueue) as tarball: if link.sources is not None: for source in spec.local_sources(): path = os.path.join(link.sources, source) tarball.extract(path, tmpdir) if link.patches is not None: for patch in spec.local_patches(): path = os.path.join(link.patches, patch) tarball.extract(path, tmpdir) return tmp_specfile
def populate_working_directory(tmpdir, spec, link, sources, patchqueue): """ Build a working directory containing everything needed to build the SRPM. """ # Copy spec to working area tmp_specfile = os.path.join(tmpdir, os.path.basename(spec)) shutil.copyfile(spec, tmp_specfile) # Copy sources to working area, rewriting spec as needed tarball_filters = ['.tar.gz', '.tar.bz2'] for source in sources: if any([ext in source for ext in tarball_filters]): extract_topdir(tmp_specfile, source) shutil.copy(source, tmpdir) spec = Spec(tmp_specfile, check_package_name=False) # Expand patchqueue to working area, rewriting spec as needed if link and patchqueue: # Extract patches if link.patchqueue is not None: with Patchqueue(patchqueue, branch=link.patchqueue) as patches: patches.extract_all(tmpdir) patches.add_to_spec(spec, tmp_specfile) # Extract non-patchqueue sources with Tarball(patchqueue) as tarball: if link.sources is not None: for source in spec.local_sources(): path = os.path.join(link.sources, source) tarball.extract(path, tmpdir) if link.patches is not None: for patch in spec.local_patches(): path = os.path.join(link.patches, patch) tarball.extract(path, tmpdir) return tmp_specfile
def spec_and_lnk(repo_path, package_name): """ Return the Spec and Link object for repo_path/SPECS/package_name. Link can be None if not present. Exception("package not present") otherwise """ partial_file_path = "%s/SPECS/%s" % (repo_path, package_name) specname = "%s.spec" % partial_file_path if not os.path.isfile(specname): print("Spec file for %s not present in %s/SPECS" % (package_name, repo_path)) sys.exit(1) spec = Spec(specname) linkname = "%s.lnk" % partial_file_path link = Link(linkname) if os.path.isfile(linkname) else None return spec, link
def main(argv=None): """Entry point.""" args = parse_args_or_exit(argv) setup_logging(args) spec = Spec(args.specfile_path) link = None if args.lnkfile_path is not None: link = Link(args.lnkfile_path) pin = None pinfile = "{}/{}.pin".format( args.pinsdir, get_name(args.specfile_path, args.lnkfile_path) ) if os.path.exists(pinfile): pin = pinfile manifest = generate_manifest(spec, link, pin) print(json.dumps(manifest, indent=4))
def test_autosetup_missing(self): """Patchqueue application fails if %autosetup is not present""" spec = Spec("tests/data/ocaml-uri.spec", check_package_name=False) patches = ["first.patch"] with self.assertRaises(planex.patchqueue.SpecMissingAutosetup): planex.patchqueue.expand_patchqueue(spec, patches)
def test_autosetup_present(self): spec = Spec("tests/data/manifest/branding-xenserver.spec", check_package_name=False) patches = ["first.patch"] planex.patchqueue.expand_patchqueue(spec, patches)
def test_autosetup_missing(self): spec = Spec("tests/data/ocaml-uri.spec", check_package_name=False) patches = ["first.patch"] with self.assertRaises(planex.patchqueue.SpecMissingAutosetup): planex.patchqueue.expand_patchqueue(spec, patches)
def test_autosetup_missing(self): """Patchqueue application fails if %autosetup is not present""" spec = Spec("tests/data/ocaml-uri.spec", check_package_name=False) spec.add_patch(0, Blob(spec, "first.patch", "dummy")) with self.assertRaises(planex.patchqueue.SpecMissingAutosetup): spec.rewrite_spec()
def main(argv=None): """ Entry point """ # pylint: disable=R0914 setup_sigint_handler() args = parse_args_or_exit(argv) allspecs = dedupe(args.specs, dedupe_key) try: specs = { pkgname(path): Spec(path, defines=args.define) for path in allspecs if path.endswith(".spec") } except SpecNameMismatch as exn: sys.stderr.write("error: %s\n" % exn.message) sys.exit(1) links = { pkgname(path): Link(path) for path in allspecs if path.endswith(".lnk") or path.endswith(".pin") } provides_to_rpm = package_to_rpm_map(specs.values()) print("# -*- makefile -*-") print("# vim:ft=make:") if args.verbose: print("# inputs: %s" % " ".join(allspecs)) for spec in specs.itervalues(): build_srpm_from_spec(spec, links.get(spec.name())) # Manifest dependencies must come after spec dependencies # otherwise manifest.json will be the SRPM's first dependency # and will be passed to rpmbuild in the spec position. create_manifest_deps(spec) if spec.name() in links: srpmpath = spec.source_package_path() patchpath = spec.expand_macro("%_sourcedir/patches.tar") print('%s: %s' % (srpmpath, patchpath)) print('%s: %s' % (srpmpath, links[spec.name()].linkpath)) print('%s: %s' % (patchpath, links[spec.name()].linkpath)) download_rpm_sources(spec) build_rpm_from_srpm(spec) if args.buildrequires: buildrequires_for_rpm(spec, provides_to_rpm) print() # Generate targets to build all srpms and all rpms all_rpms = [] all_srpms = [] for spec in specs.itervalues(): rpm_path = spec.binary_package_paths()[-1] all_rpms.append(rpm_path) all_srpms.append(spec.source_package_path()) print("%s: %s" % (spec.name(), rpm_path)) print("%s.srpm: %s" % (spec.name(), spec.source_package_path())) print() print("RPMS := " + " \\\n\t".join(all_rpms)) print() print("SRPMS := " + " \\\n\t".join(all_srpms))