Package: dh-debputy
Version: 0.1.60
Severity: important
Tags: patch

Hi again :)

There's still one issue preventing CMake builds. I've attached a patch, which describes the issue and fix.

Bye!
From 4b9a8c05fc8862289aaa58f390eff444c2425145 Mon Sep 17 00:00:00 2001
From: Andrea Pappacoda <and...@pappacoda.it>
Date: Sun, 12 Jan 2025 18:07:11 +0100
Subject: [PATCH] cmake: fix lstrip of CFLAGS and CPPFLAGS concatenation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Before this change, lstrip() was applied on the " {cppflags}" string,
which always resulted in a string equal to the contents of the cppflags
variable. This variable, without leading whitespace, would lead to an
improper concatenation of a non-empty CFLAGS (or CXXFLAGS) to some other
flags, which would lead to build failures. For example:

    c++: error: unrecognized command-line option ‘-fcf-protection-Wdate-time’; did you mean ‘-fcf-protection=return’?

As you can see, `-fcf-protection` from CFLAGS gets concatenated to
`-Wdate-time` from CPPFLAGS without spaces, creating an invalid option.

This is solved by creating the whole string result as a single f-string
and executing lstrip() at the end, so to remove the extra space when
CFLAGS is empty.
---
 src/debputy/plugin/debputy/build_system_rules.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/debputy/plugin/debputy/build_system_rules.py b/src/debputy/plugin/debputy/build_system_rules.py
index eccda70..e379103 100644
--- a/src/debputy/plugin/debputy/build_system_rules.py
+++ b/src/debputy/plugin/debputy/build_system_rules.py
@@ -1363,8 +1363,8 @@ class CMakeBuildSystemRule(StepBasedBuildSystemRule):
         if "CPPFLAGS" in os.environ:
             # CMake doesn't respect CPPFLAGS, see #653916.
             cppflags = os.environ["CPPFLAGS"]
-            cflags = os.environ.get("CFLAGS", "") + f" {cppflags}".lstrip()
-            cxxflags = os.environ.get("CXXFLAGS", "") + f" {cppflags}".lstrip()
+            cflags = f"{os.environ.get('CFLAGS', '')} {cppflags}".lstrip()
+            cxxflags = f"{os.environ.get('CXXFLAGS', '')} {cppflags}".lstrip()
             env_mod = env_mod.combine(
                 # The debhelper build system never showed this delta, so people might find it annoying.
                 EnvironmentModification(
-- 
2.45.2

Attachment: signature.asc
Description: PGP signature

Reply via email to