Ensures multiple "fake" static libraries are correctly linked. see gh-18295
(tmp_path)
| 10 | @pytest.mark.skipif(IS_WASM, reason="cannot start subprocess in wasm") |
| 11 | @pytest.mark.slow |
| 12 | def test_multi_fortran_libs_link(tmp_path): |
| 13 | ''' |
| 14 | Ensures multiple "fake" static libraries are correctly linked. |
| 15 | see gh-18295 |
| 16 | ''' |
| 17 | |
| 18 | # We need to make sure we actually have an f77 compiler. |
| 19 | # This is nontrivial, so we'll borrow the utilities |
| 20 | # from f2py tests: |
| 21 | from numpy.f2py.tests.util import has_f77_compiler |
| 22 | if not has_f77_compiler(): |
| 23 | pytest.skip('No F77 compiler found') |
| 24 | |
| 25 | # make some dummy sources |
| 26 | with open(tmp_path / '_dummy1.f', 'w') as fid: |
| 27 | fid.write(indent(dedent('''\ |
| 28 | FUNCTION dummy_one() |
| 29 | RETURN |
| 30 | END FUNCTION'''), prefix=' '*6)) |
| 31 | with open(tmp_path / '_dummy2.f', 'w') as fid: |
| 32 | fid.write(indent(dedent('''\ |
| 33 | FUNCTION dummy_two() |
| 34 | RETURN |
| 35 | END FUNCTION'''), prefix=' '*6)) |
| 36 | with open(tmp_path / '_dummy.c', 'w') as fid: |
| 37 | # doesn't need to load - just needs to exist |
| 38 | fid.write('int PyInit_dummyext;') |
| 39 | |
| 40 | # make a setup file |
| 41 | with open(tmp_path / 'setup.py', 'w') as fid: |
| 42 | srctree = os.path.join(os.path.dirname(__file__), '..', '..', '..') |
| 43 | fid.write(dedent(f'''\ |
| 44 | def configuration(parent_package="", top_path=None): |
| 45 | from numpy.distutils.misc_util import Configuration |
| 46 | config = Configuration("", parent_package, top_path) |
| 47 | config.add_library("dummy1", sources=["_dummy1.f"]) |
| 48 | config.add_library("dummy2", sources=["_dummy2.f"]) |
| 49 | config.add_extension("dummyext", sources=["_dummy.c"], libraries=["dummy1", "dummy2"]) |
| 50 | return config |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | import sys |
| 55 | sys.path.insert(0, r"{srctree}") |
| 56 | from numpy.distutils.core import setup |
| 57 | setup(**configuration(top_path="").todict())''')) |
| 58 | |
| 59 | # build the test extensino and "install" into a temporary directory |
| 60 | build_dir = tmp_path |
| 61 | subprocess.check_call([sys.executable, 'setup.py', 'build', 'install', |
| 62 | '--prefix', str(tmp_path / 'installdir'), |
| 63 | '--record', str(tmp_path / 'tmp_install_log.txt'), |
| 64 | ], |
| 65 | cwd=str(build_dir), |
| 66 | ) |
| 67 | # get the path to the so |
| 68 | so = None |
| 69 | with open(tmp_path /'tmp_install_log.txt') as fid: |