From ae3b65819de3ec10976b2ee52d440a25fb855826 Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Thu, 16 Jan 2025 15:20:37 +0100 Subject: [PATCH 1/6] fix: Honor the ${pcfiledir} entries in pkgconfig The ${pcfiledir} tag allows to make .pc files relocatables, by being replaced with the path where the .pc file is stored. In these cases, the "prefix=" entry must be left as-is, to ensure that it continues to work as expected. Fix #5158 --- craft_parts/packages/normalize.py | 4 ++++ tests/unit/packages/test_normalize.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/craft_parts/packages/normalize.py b/craft_parts/packages/normalize.py index 4a33a6de7..6fbed6af2 100644 --- a/craft_parts/packages/normalize.py +++ b/craft_parts/packages/normalize.py @@ -185,10 +185,14 @@ def fix_pkg_config( f"^prefix=(?P{'|'.join(prefixes_to_trim)})(?P.*)" ) pattern = re.compile("^prefix=(?P.*)") + pattern_pcfiledir = re.compile("^prefix *= *[$]{pcfiledir}.*") # process .pc file with fileinput.input(pkg_config_file, inplace=True) as input_file: for line in input_file: + if pattern_pcfiledir.search(line) is not None: + print(line, end="") + continue match = pattern.search(line) match_trim = pattern_trim.search(line) diff --git a/tests/unit/packages/test_normalize.py b/tests/unit/packages/test_normalize.py index 3a469ee25..44a2ef401 100644 --- a/tests/unit/packages/test_normalize.py +++ b/tests/unit/packages/test_normalize.py @@ -365,6 +365,18 @@ def test_normalize_fix_pkg_config( f"{tmpdir}/usr" ) + def test_normalize_fix_pkg_config_with_pcfiledir( + self, tmpdir, pkg_config_file, expected_pkg_config_content + ): + """Verify normalization fixes pkg-config files.""" + pc_file = tmpdir / "my-file.pc" + pkg_config_file(pc_file, "${pcfiledir}/../../..") + normalize(tmpdir, repository=DummyRepository) + + assert pc_file.read_text(encoding="utf-8") == expected_pkg_config_content( + "${pcfiledir}/../../.." + ) + def test_fix_pkg_config_is_dir(self, tmpdir): """Verify directories ending in .pc do not raise an error.""" pc_file = tmpdir / "granite.pc" From 0ff56bfc65241b00f8bb0ec6c876c41de09e0ba6 Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Thu, 16 Jan 2025 15:23:45 +0100 Subject: [PATCH 2/6] Add changelog entry --- docs/reference/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 6647304a7..2f1ee8b25 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -9,6 +9,7 @@ Bug fixes: - Make sure the :ref:`uv plugin` is re-entrant on source changes. +- Honor the ${pcfiledir} entries in pkgconfig 2.2.1 (2024-12-19) ------------------ From 5820d958ac36e56090798f27aafe04fb8aee5c62 Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Thu, 16 Jan 2025 16:10:26 +0100 Subject: [PATCH 3/6] Fix rst file --- docs/reference/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 2f1ee8b25..453178c82 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -9,7 +9,7 @@ Bug fixes: - Make sure the :ref:`uv plugin` is re-entrant on source changes. -- Honor the ${pcfiledir} entries in pkgconfig +- Honor the `\${pcfiledir}` entries in `pkgconfig` files. 2.2.1 (2024-12-19) ------------------ From 8ce1202d53b3cb6c01245386363070615109b8f0 Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Thu, 16 Jan 2025 16:19:56 +0100 Subject: [PATCH 4/6] Another try --- docs/reference/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 453178c82..944c96d2c 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -9,7 +9,7 @@ Bug fixes: - Make sure the :ref:`uv plugin` is re-entrant on source changes. -- Honor the `\${pcfiledir}` entries in `pkgconfig` files. +- Honor the \${pcfiledir} entries in pkgconfig files. 2.2.1 (2024-12-19) ------------------ From 11115906bdc5005f9803bbaf9b0069682dae6d7e Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Thu, 16 Jan 2025 16:26:21 +0100 Subject: [PATCH 5/6] Should fully fix documentation --- docs/reference/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 944c96d2c..8899066e8 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -9,7 +9,7 @@ Bug fixes: - Make sure the :ref:`uv plugin` is re-entrant on source changes. -- Honor the \${pcfiledir} entries in pkgconfig files. +- Honor the ``pcfiledir`` tag in ``pkgconfig`` files. 2.2.1 (2024-12-19) ------------------ From 726bcbd0f3d2f26104c434ef4e2fcddfec5a0944 Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Thu, 16 Jan 2025 16:53:39 +0100 Subject: [PATCH 6/6] Fix changelog --- docs/reference/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 8899066e8..e8f28228c 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -9,7 +9,7 @@ Bug fixes: - Make sure the :ref:`uv plugin` is re-entrant on source changes. -- Honor the ``pcfiledir`` tag in ``pkgconfig`` files. +- Preserve the ``pcfiledir`` tag in ``pkgconfig`` files. 2.2.1 (2024-12-19) ------------------