If running on MacOS, patches `library` so that all references to items in `sublibraries` are changed to `@rpath/{leafname}`. Does nothing on other platforms. library: Path of shared library. sublibraries: List of paths of shared libraries; these have typically b
( library, *sublibraries)
| 2609 | |
| 2610 | |
| 2611 | def macos_patch( library, *sublibraries): |
| 2612 | ''' |
| 2613 | If running on MacOS, patches `library` so that all references to items in |
| 2614 | `sublibraries` are changed to `@rpath/{leafname}`. Does nothing on other |
| 2615 | platforms. |
| 2616 | |
| 2617 | library: |
| 2618 | Path of shared library. |
| 2619 | sublibraries: |
| 2620 | List of paths of shared libraries; these have typically been |
| 2621 | specified with `-l` when `library` was created. |
| 2622 | ''' |
| 2623 | log2( f'macos_patch(): library={library} sublibraries={sublibraries}') |
| 2624 | if not darwin(): |
| 2625 | return |
| 2626 | if not sublibraries: |
| 2627 | return |
| 2628 | subprocess.run( f'otool -L {library}', shell=1, check=1) |
| 2629 | command = 'install_name_tool' |
| 2630 | names = [] |
| 2631 | for sublibrary in sublibraries: |
| 2632 | name = subprocess.run( |
| 2633 | f'otool -D {sublibrary}', |
| 2634 | shell=1, |
| 2635 | check=1, |
| 2636 | capture_output=1, |
| 2637 | encoding='utf8', |
| 2638 | ).stdout.strip() |
| 2639 | name = name.split('\n') |
| 2640 | assert len(name) == 2 and name[0] == f'{sublibrary}:', f'{name=}' |
| 2641 | name = name[1] |
| 2642 | # strip trailing so_name. |
| 2643 | leaf = os.path.basename(name) |
| 2644 | m = re.match('^(.+[.]((so)|(dylib)))[0-9.]*$', leaf) |
| 2645 | assert m |
| 2646 | log2(f'Changing {leaf=} to {m.group(1)}') |
| 2647 | leaf = m.group(1) |
| 2648 | command += f' -change {name} @rpath/{leaf}' |
| 2649 | command += f' {library}' |
| 2650 | log2( f'Running: {command}') |
| 2651 | subprocess.run( command, shell=1, check=1) |
| 2652 | subprocess.run( f'otool -L {library}', shell=1, check=1) |
| 2653 | |
| 2654 | |
| 2655 | def _macos_fixup_platform_tag(tag): |
no test coverage detected
searching dependent graphs…