diff --git a/requirements-devel.txt b/requirements-devel.txt index fef6e3a9a8..7880a30c26 100644 --- a/requirements-devel.txt +++ b/requirements-devel.txt @@ -59,7 +59,7 @@ craft-grammar==2.0.1 # via # craft-application # snapcraft (setup.py) -craft-parts==2.3.0 +craft-parts==2.4.1 # via # craft-application # snapcraft (setup.py) diff --git a/requirements-docs.txt b/requirements-docs.txt index 24faa7c7f8..9f311008c2 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -73,7 +73,7 @@ craft-grammar==2.0.1 # via # craft-application # snapcraft (setup.py) -craft-parts==2.3.0 +craft-parts==2.4.1 # via # craft-application # snapcraft (setup.py) diff --git a/requirements.txt b/requirements.txt index a586bcdd41..932ff5a8e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -41,7 +41,7 @@ craft-grammar==2.0.1 # via # craft-application # snapcraft (setup.py) -craft-parts==2.3.0 +craft-parts==2.4.1 # via # craft-application # snapcraft (setup.py) diff --git a/setup.py b/setup.py index 13eb7ca3f4..87cec33c05 100755 --- a/setup.py +++ b/setup.py @@ -102,7 +102,7 @@ def recursive_data_files(directory, install_directory): "craft-archives~=2.0", "craft-cli>=2.15.0", "craft-grammar>=2.0.1,<3.0.0", - "craft-parts==2.3.0", + "craft-parts==2.4.1", "craft-platforms~=0.4", "craft-providers>=2.0.4,<3.0.0", "craft-store>=3.0.2,<4.0.0", diff --git a/snapcraft_legacy/internal/repo/_base.py b/snapcraft_legacy/internal/repo/_base.py index 6f7c2b432a..e5ebbafc15 100644 --- a/snapcraft_legacy/internal/repo/_base.py +++ b/snapcraft_legacy/internal/repo/_base.py @@ -346,6 +346,10 @@ def fix_pkg_config( - From snaps built locally: `/stage` - Built during the build stage: the install directory + But if the prefix begins with `pcfiledir` variable, it must be kept as-is, + because that variable refers to the current location of the .pc file. It + allows to create "relocatable" pkgconfig files, so no changes are required. + :param pkg_config_file: pkg-config (.pc) file to modify :param prefix_prepend: directory to prepend to the prefix :param prefix_trim: directory to remove from prefix @@ -358,10 +362,17 @@ 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 the prefix begins with ${pcfiledir} statement, this is + # a position-independent (thus, "relocatable") .pc file, so + # no changes are required. + 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/legacy/unit/repo/test_base.py b/tests/legacy/unit/repo/test_base.py index d4607c12d7..c9634a879c 100644 --- a/tests/legacy/unit/repo/test_base.py +++ b/tests/legacy/unit/repo/test_base.py @@ -369,6 +369,22 @@ def test_fix_pkg_config_trim_prefix( ) +def test_fix_pkg_config_with_pcfiledir( + tmpdir, + pkg_config_file, + expected_pkg_config_content, +): + """Verify prefixes that begin with ${pcfiledir} aren't modified.""" + pc_file = tmpdir / "my-file.pc" + pkg_config_file(pc_file, "${pcfiledir}/../../..") + + fix_pkg_config(tmpdir, pc_file) + + assert pc_file.read_text(encoding="utf-8") == expected_pkg_config_content( + "${pcfiledir}/../../.." + ) + + def test_normalize_fix_pkg_config(tmpdir, pkg_config_file, expected_pkg_config_content): """Verify normalization fixes pkg-config files.""" pc_file = tmpdir / "my-file.pc"