Skip to content

Commit 5953d4c

Browse files
committed
Fix the linking test case
Now python3-config defaults to shared linking, so perform that part of the test first. Then remove the shared libraries to force static linking. Signed-off-by: Michał Górny <[email protected]>
1 parent e09a046 commit 5953d4c

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

recipe/tests/prefix-replacement/build-and-test.sh

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,7 @@
22

33
set -ex
44

5-
if [[ "$PKG_NAME" == "libpython-static" ]]; then
6-
# see bpo44182 for why -L${CONDA_PREFIX}/lib is added
7-
${CC} a.c $(python3-config --cflags) $(python3-config --embed --ldflags) -L${CONDA_PREFIX}/lib -o ${CONDA_PREFIX}/bin/embedded-python-static
8-
if [[ "$target_platform" == linux-* ]]; then
9-
if ${READELF} -d ${CONDA_PREFIX}/bin/embedded-python-static | rg libpython; then
10-
echo "ERROR :: Embedded python linked to shared python library. It is expected to link to the static library."
11-
fi
12-
elif [[ "$target_platform" == osx-* ]]; then
13-
if ${OTOOL} -l ${CONDA_PREFIX}/bin/embedded-python-static | rg libpython; then
14-
echo "ERROR :: Embedded python linked to shared python library. It is expected to link to the static library."
15-
fi
16-
fi
17-
${CONDA_PREFIX}/bin/embedded-python-static
18-
19-
# I thought this would prefer the shared library for Python. I was wrong:
20-
# EMBED_LDFLAGS=$(python3-config --ldflags)
21-
# re='^(.*)(-lpython[^ ]*)(.*)$'
22-
# if [[ ${EMBED_LDFLAGS} =~ $re ]]; then
23-
# EMBED_LDFLAGS="${BASH_REMATCH[1]} ${BASH_REMATCH[3]} -Wl,-Bdynamic ${BASH_REMATCH[2]}"
24-
# fi
25-
# ${CC} a.c $(python3-config --cflags) ${EMBED_LDFLAGS} -o ${CONDA_PREFIX}/bin/embedded-python-shared
26-
27-
# Brute-force way of linking to the shared library, sorry!
28-
rm -rf ${CONDA_PREFIX}/lib/libpython*.a
29-
fi
30-
5+
# see bpo44182 for why -L${CONDA_PREFIX}/lib is added
316
${CC} a.c $(python3-config --cflags) \
327
$(python3-config --embed --ldflags) \
338
-L${CONDA_PREFIX}/lib -Wl,-rpath,${CONDA_PREFIX}/lib \
@@ -44,4 +19,24 @@ elif [[ "$target_platform" == osx-* ]]; then
4419
fi
4520
${CONDA_PREFIX}/bin/embedded-python-shared
4621

22+
if [[ "$PKG_NAME" == "libpython-static" ]]; then
23+
# remove the shared library to force static linking
24+
rm -f ${CONDA_PREFIX}/lib/libpython*.{so,dylib}
25+
26+
${CC} a.c $(python3-config --cflags) \
27+
$(python3-config --embed --ldflags) \
28+
-L${CONDA_PREFIX}/lib -Wl,-rpath,${CONDA_PREFIX}/lib \
29+
-o ${CONDA_PREFIX}/bin/embedded-python-static
30+
if [[ "$target_platform" == linux-* ]]; then
31+
if ${READELF} -d ${CONDA_PREFIX}/bin/embedded-python-static | rg libpython; then
32+
echo "ERROR :: Embedded python linked to shared python library. It is expected to link to the static library."
33+
fi
34+
elif [[ "$target_platform" == osx-* ]]; then
35+
if ${OTOOL} -l ${CONDA_PREFIX}/bin/embedded-python-static | rg libpython; then
36+
echo "ERROR :: Embedded python linked to shared python library. It is expected to link to the static library."
37+
fi
38+
fi
39+
${CONDA_PREFIX}/bin/embedded-python-static
40+
fi
41+
4742
set +x

0 commit comments

Comments
 (0)