From 580bc31d50be307d0914ee9116d2f7888fd84816 Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Tue, 29 Sep 2020 16:12:00 +0200 Subject: [PATCH] =?UTF-8?q?`%setup`=20=E2=86=92=20`%autosetup=20-N`=20unle?= =?UTF-8?q?ss=20`-aN=20-aM`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #92 Signed-off-by: Tomas Tomecek --- dist2src/core.py | 27 ++++++++++++++++++++++++--- tests/conftest.py | 9 +++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/dist2src/core.py b/dist2src/core.py index c90f5b69..08242964 100644 --- a/dist2src/core.py +++ b/dist2src/core.py @@ -271,6 +271,21 @@ 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 /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") @@ -278,13 +293,19 @@ def _enforce_autosetup(self): # 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]) diff --git a/tests/conftest.py b/tests/conftest.py index f008d282..0dea7aaa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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} ]