|
1 | 1 | import os |
2 | 2 | import pathlib |
3 | 3 | import platform |
| 4 | +import re |
4 | 5 | import textwrap |
5 | 6 |
|
6 | 7 | import pytest |
@@ -1347,3 +1348,48 @@ def package_info(self): |
1347 | 1348 | ) |
1348 | 1349 | """) |
1349 | 1350 | assert build_file_expected in build_content |
| 1351 | + |
| 1352 | + |
| 1353 | +def test_shared_libs_and_unix_includes_rpath(): |
| 1354 | + """ |
| 1355 | + Testing the RPATH flag is added to the BUILD.bazel file if these conditions |
| 1356 | + are given: shared library and UNIX systems. |
| 1357 | +
|
| 1358 | + Issue: https://github.com/conan-io/conan/issues/19190 |
| 1359 | + Issue: https://github.com/conan-io/conan/issues/19135 |
| 1360 | + """ |
| 1361 | + client = TestClient() |
| 1362 | + csm = textwrap.dedent(""" |
| 1363 | + import os |
| 1364 | + from conan import ConanFile |
| 1365 | + from conan.tools.files import save |
| 1366 | + class Pkg(ConanFile): |
| 1367 | + name = "csm" |
| 1368 | + version = "1.0" |
| 1369 | + settings = "os" |
| 1370 | + options = {"shared": [True, False]} |
| 1371 | + default_options = {"shared": False} |
| 1372 | + def package(self): |
| 1373 | + if self.settings.os == "Windows": |
| 1374 | + save(self, os.path.join(self.package_folder, "bin", "csmapi.dll"), "") |
| 1375 | + save(self, os.path.join(self.package_folder, "lib", "csmapi.lib"), "") |
| 1376 | + else: |
| 1377 | + save(self, os.path.join(self.package_folder, "lib", "libcsmapi.so"), "") |
| 1378 | + def package_info(self): |
| 1379 | + self.cpp_info.libs = ["csmapi"] |
| 1380 | + """) |
| 1381 | + consumer = textwrap.dedent(""" |
| 1382 | + [requires] |
| 1383 | + csm/1.0 |
| 1384 | + [options] |
| 1385 | + *:shared=True |
| 1386 | + """) |
| 1387 | + client.save({"conanfile.txt": consumer, "csm/conanfile.py": csm}) |
| 1388 | + client.run("export-pkg csm -o '*:shared=True' -s 'os=Windows'") |
| 1389 | + client.run("export-pkg csm -o '*:shared=True' -s 'os=Linux'") |
| 1390 | + client.run("install . -g BazelDeps -s 'os=Windows'") |
| 1391 | + build_content = load(None, os.path.join(client.current_folder, "csm", "BUILD.bazel")) |
| 1392 | + assert '"-Wl,-rpath,' not in build_content |
| 1393 | + client.run("install . -g BazelDeps -s 'os=Linux'") |
| 1394 | + build_content = load(None, os.path.join(client.current_folder, "csm", "BUILD.bazel")) |
| 1395 | + assert re.search('"-Wl,-rpath,.*/p/lib"', build_content.replace("\\", "/")) |
0 commit comments