Skip to content

Commit

Permalink
%setup%autosetup -N unless -aN -aM
Browse files Browse the repository at this point in the history
Sometimes packages have multiple sources (= archives) which they unpack
during %prep in different ways. This can be done with `%setup -aN -aM`.
Sadly `%autosetup -aN -aM` does not work: https://bugzilla.redhat.com/show_bug.cgi?id=1881840

So we need to turn back into overwriting %setup unless we detect this
use case.

But the eternal problem with patches applied in a subdir persists.

Fixes some of packit#92

Signed-off-by: Tomas Tomecek <[email protected]>
  • Loading branch information
TomasTomecek committed Oct 8, 2020
1 parent a862366 commit 580bc31
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
27 changes: 24 additions & 3 deletions dist2src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,41 @@ def _enforce_autosetup(self):
"""
We are unable to get a git repo when a packages uses %setup + %patch
so we need to turn %setup into %autosetup -N
this method makes sure there is a git repo in <REPO>/PACKAGE-VERSION/.git
after running %prep, this is how:
1. %autosetup - cool: just "return"
2. %autopatch - it calls to %__scm_apply_%{...} which we override: just "return"
3. %setup and no %patch - we need to turn %setup into %autosetup to create
the git repo
4. %setup + %patch - most common and complicated as hell:
a) %setup -a -a ... - we can't turn it to %autosetup b/c
`%autosetup -a -a` doesn't work https://bugzilla.redhat.com/show_bug.cgi?id=1881840
b) %setup + pushd/cd - we cannot recreate those patches correctly since
they are not applied from root #92
c) no bullshit, just plain %setup and %patch -- in any case, we turn
%setup into %autosetup -N to be sure the .git repo is created correctly
unless `-a -a` is used
"""
prep_lines = self.dist_git_spec.spec_content.section("%prep")

if not prep_lines:
# e.g. appstream-data does not have a %prep section
return

a_a_regex = re.compile(r"-a")
for i, line in enumerate(prep_lines):
if line.startswith(("%autosetup", "%autopatch", "%patch")):
logger.info("This package uses %autosetup or %[auto]patch.")
if line.startswith(("%autosetup", "%autopatch")):
logger.info("This package uses %autosetup or %autopatch.")
# cool, we're good
return
elif line.startswith("%setup"):
# %setup -> %autosetup -p1
if len(a_a_regex.findall(line)) >= 2:
logger.info(
"`%setup -aN -aM` detected, we cannot turn it to %autosetup"
)
continue
# %setup -> %autosetup -N
prep_lines[i] = line.replace("%setup", "%autosetup -N")
# %autosetup does not accept -q, remove it
prep_lines[i] = re.sub(r"\s+-q", r"", prep_lines[i])
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
("gdb", "c8s"), # conditional patching, a ton of if's and addition of more sources
("sqlite", "c8s"), # conditional patching + autoconf
("haproxy", "c8s"), # they ignore our files
# ("openblas", "c8"), # openblas-0.3.3/OpenBLAS-0.3.3/
# ("fuse", "c8"), # 2 libraries being built in a single buildroot, we cannot make
# # a reliable source-git for this
(
"unbound",
"c8",
), # again, another level of directories and patches applied in a subdir
]

# these packages only have a single commit in the respective dist-git branch
Expand All @@ -55,6 +62,8 @@
("acpica-tools", "c8"), # %setup, %patch, unpack %SOURCE1, a ton of operations
("socat", "c8s"), # %setup + %patch # problem with previous commit
("meanwhile", "c8"), # -p0 + -p1 patches
("nss-util", "c8"), # double nested dir: nss-util-3.39/nss/ and `cd nss` in %prep
("metis", "c8"), # %setup -qc && pushd %{name}-%{version}
]


Expand Down

0 comments on commit 580bc31

Please sign in to comment.