Closed lukehoffmann closed 2 weeks ago
@hiker please let me know if I've misunderstood what you had in mind, or if not can you review please?
Looks perfect. Bring it up to the link_exe (and link_shared_object), and this is ready to go.
I've merged bom_masters into this and resolved the conflicts. I detected one test failure only triggered when the tests were executed in a certain order (in steps/archive) - I switched this test to use mock_c_compiler (which is always available), instead of the default in the tool box (which somehow changed when things were executed in a certain oder).
I also noticed that linesn66 and 147 are not covered by a test in test_linker
:
~/work/fab/tests/unit_tests/tools$ pytest --cov-report term-missing --cov fab.tools.linker ./test_linker.py
/home/joerg/.local/lib/python3.10/site-packages/pep8.py:110: FutureWarning: Possible nested set at position 1
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
============================================================================== test session starts ===============================================================================
platform linux -- Python 3.10.12, pytest-7.4.4, pluggy-1.0.0
rootdir: /home/joerg/work/fab
configfile: pyproject.toml
plugins: pylint-0.21.0, pep8-1.0.6, flakes-4.0.5, xdist-3.2.1, anyio-3.6.2, cov-4.0.0
collected 15 items
test_linker.py ............... [100%]
---------- coverage: platform linux, python 3.10.12-final-0 ----------
Name Stmts Miss Cover Missing
-------------------------------------------------------------------------------
/home/joerg/work/fab/source/fab/tools/linker.py 59 2 97% 66, 147
-------------------------------------------------------------------------------
TOTAL 59 2 97%
I don't think this is an official requirement (line 66 is covered if we run all tests in unit_tests/tools, and line 147 somewhere from unit_tests/steps), but imho this is quite useful.
Now, line 66 is actually my fault I think (unless it was a side-effect of conflicts when merging??), and looking at it, this code is actually wrong (it relies on linker._compiler to exist, which atm does not have to be the case ... though de-facto it is). With #20 this will actually be fixed, so ... just ignore line 66 for now, but covering 147 looks useful
I think we need two extensions:
@hiker
- We need to have a list of flags that are always added before the library names
- Similarly, it might be good to have a list of flags to be added after the libraries
Currently the libs
part of the link()
function call.
Do you want to also put these pre/post flags into the link()
function call, e.g.
linker.link(..., prelib_flags=[..], libs=[..], postlib_flags[..], ...)
Or should the be properties of the linker,
linker.prelib_flags = [ ... ]
linker.postlib_flags = [ ... ]
...
linker.link(..., libs=[..], ...)
Or do you want both options?
Currently we can technically do both with
linker.flags
- always goes before libs
(but also before the source files)add_flags
argument - these flags always go after the libs
flags But the first is configured on the linker object, while the second is passed into link()
.
I decided to go with the option of adding both arguments to the link
function. So these will be in addition to linker.flags
. See what you think.
I decided to go with the option of adding both arguments to the
link
function. So these will be in addition tolinker.flags
. See what you think.
I admit I can't decide, and am happy with either (as long as these flags are all optional, since typically you won't need them). The only thing I did notice: flags that go before the source code (linker.flags) seems pretty useless. Any 'generic' linker flag can go anywhere (e.g. to ask for a symbol map file or so, or adding a search path), but any library must come after the .o files.
Yeah the linker.flags is just built-in behaviour of the Tool
baseclass, which adds them in the run
method. We will probably not use them, but I thought I'd better add a test for them since they exist
No problem, as I said I was weighing up both options, and just picked one option to implement for you to review. I've switched to configure the additional flags on the Linker itself now.
That looks good now, thanks. I'll port our lfric build to see if any other issue pops up :)
Add support for libraries in the
Linker
class. As per issue #7: