Skip to content

Commit

Permalink
Add test for rpath patcher not called for symlinks
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Bargull <marcel.bargull@udo.edu>
  • Loading branch information
mbargull committed Feb 12, 2024
1 parent bd79925 commit fc984b1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tests/test-recipes/metadata/_rpath_symlink/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% set lib_file = "libthing.so.1.0.0" %} # [linux]
{% set lib_file = "libthing.1.0.0.dylib" %} # [osx]

package:
name: rpath_symlink
version: 1.0.0

build:
skip: true # [not (linux or osx)]
rpaths_patcher: {{ rpaths_patcher }}
script:
- mkdir -p "${PREFIX}/lib"
- >
< /dev/null ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS}
-x c - -nostdlib -s -o "${PREFIX}/lib/{{ lib_file }}" "-Wl,-rpath,${PREFIX}/lib"
-shared -Wl,-soname,libthing.so.1 # [linux]
-dynamiclib -install_name libthing.1.dylib # [osx]
- ln -s "${PREFIX}/lib/{{ lib_file }}" "${PREFIX}/lib/libthing.so.1" # [linux]
- ln -s "${PREFIX}/lib/{{ lib_file }}" "${PREFIX}/lib/libthing.1.dylib" # [osx]
- mkdir -p "${PREFIX}/lib/subfolder"
- ln -s "${PREFIX}/lib/{{ lib_file }}" "${PREFIX}/lib/subfolder/libthing-link.so" # [linux]
- ln -s "${PREFIX}/lib/{{ lib_file }}" "${PREFIX}/lib/subfolder/libthing-link.dylib" # [osx]

requirements:
build:
- {{ compiler("c") }}

test:
requires:
- py-lief
commands:
# Test that we get only a single entry that is the library's own directory.
- |
python -c '
import os, lief
lib = lief.parse(os.environ["PREFIX"] + "/lib/{{ lib_file }}")
assert {"$ORIGIN/."} == {e.rpath for e in lib.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH} # [linux]
assert {"@loader_path/"} == {command.path for command in lib.commands if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH} # [osx]
'
31 changes: 30 additions & 1 deletion tests/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
import pytest

from conda_build import api, post
from conda_build.utils import get_site_packages, on_win, package_has_file
from conda_build.utils import (
get_site_packages,
on_linux,
on_mac,
on_win,
package_has_file,
)

from .utils import add_mangling, metadata_dir

Expand Down Expand Up @@ -148,3 +154,26 @@ def test_menuinst_validation_fails_bad_json(testing_config, caplog, tmp_path):
assert "Found 'Menu/*.json' files but couldn't validate:" not in captured_text
assert "not a valid menuinst JSON document" in captured_text
assert "JSONDecodeError" in captured_text


@pytest.mark.skipif(on_win, reason="rpath fixup not done on Windows.")
def test_rpath_symlink(mocker, testing_config, variants_conda_build_sysroot):
if on_linux:
func_name = "mk_relative_linux"
elif on_mac:
func_name = "mk_relative_osx"
mk_relative = mocker.patch(
f"conda_build.post.{func_name}",
side_effect=getattr(post, func_name),
)
api.build(
os.path.join(metadata_dir, "_rpath_symlink"),
config=testing_config,
variants={
"rpaths_patcher": ["patchelf", "LIEF"],
**variants_conda_build_sysroot,
},
activate=True,
)
# Should only be called on the actual binary, not its symlinks. (once per variant)
assert mk_relative.call_count == 2

0 comments on commit fc984b1

Please sign in to comment.