Repository navigation
Build PETSc on macOS without the Homebrew library path #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3eb8603
Stop adding the Homebrew library path when building PETSc on macOS
timlichtenberg 7e0566e
Check that the PETSc build passes no library path
timlichtenberg 837501c
Test the arguments PETSc configure gets on macOS
timlichtenberg 66243d3
Check the environment and strict mode of the macOS configure test
timlichtenberg 53d87d0
Check named build variables and document the SUNDIALS clash
timlichtenberg 411a7a6
Test the macOS PETSc setup without mpicc and without xcrun
timlichtenberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Tests for the macOS configure arguments of ``tools/get_petsc.sh``. | ||
|
|
||
| The platform and configure steps are read from the shipped script and run with stub tools | ||
| and a stub ``configure``: no build and no network. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| pytestmark = [pytest.mark.unit, pytest.mark.timeout(30)] | ||
|
|
||
| SCRIPT = Path(__file__).resolve().parents[1] / 'tools' / 'get_petsc.sh' | ||
|
|
||
|
|
||
| # A stub configure: records its arguments, its environment and four named variables. | ||
| CONFIGURE_STUB = """#!/bin/bash | ||
| printf "%s\\n" "$@" > args | ||
| export -p > env | ||
| for v in LDFLAGS LIBRARY_PATH LIBS CPATH; do printf "%s=%s\\n" "$v" "${!v-unset}"; done > named | ||
| """ | ||
|
|
||
|
|
||
| def _run_macos(tmp_path, tools, path_extra=':/usr/bin:/bin'): | ||
| """Run the shipped platform and configure steps as macOS with stub ``tools``.""" | ||
| text = SCRIPT.read_text() | ||
| start = text.index('current_step="Determining platform-specific flags"') | ||
| block = text[start : text.index('# 9. Build PETSc')] | ||
| for name in tools: | ||
| (tmp_path / name).write_text('#!/bin/bash\necho /sdk\n') | ||
| (tmp_path / 'configure').write_text(CONFIGURE_STUB) | ||
| for stub in tmp_path.iterdir(): | ||
| stub.chmod(0o755) | ||
| snippet = 'set -euo pipefail\nannounce() { :; }\nOSTYPE=darwin24\nworkpath=.\n' + block | ||
| return subprocess.run( | ||
| ['/bin/bash', '-c', snippet], | ||
| capture_output=True, | ||
| text=True, | ||
| cwd=tmp_path, | ||
| env={'PATH': f'{tmp_path}{path_extra}'}, | ||
| ) | ||
|
|
||
|
|
||
| def _configure_args(tmp_path) -> list[str]: | ||
| """Return the configure arguments, after checking no build variable names a library path.""" | ||
| named = (tmp_path / 'named').read_text().split() | ||
| assert named == [f'{v}=unset' for v in ('LDFLAGS', 'LIBRARY_PATH', 'LIBS', 'CPATH')] | ||
| assert 'homebrew/lib' not in (tmp_path / 'env').read_text() | ||
| args = (tmp_path / 'args').read_text().splitlines() | ||
| assert [a for a in args if '-L' in a] == [] | ||
| return args | ||
|
|
||
|
|
||
| def test_configure_on_macos_gets_no_library_path(tmp_path): | ||
| """On macOS with a system MPI, PETSc configure gets LDFLAGS=-Wl,-w and no -L in any | ||
| argument or build variable, so no library directory comes ahead of the SUNDIALS 2.5 it | ||
| downloads.""" | ||
| result = _run_macos(tmp_path, ('xcrun', 'mpicc', 'mpirun')) | ||
| assert result.returncode == 0, result.stderr | ||
| args = _configure_args(tmp_path) | ||
| assert {'LDFLAGS=-Wl,-w', '--download-sundials2'} <= set(args) | ||
| assert '--download-mpich' not in args | ||
|
|
||
|
|
||
| def test_configure_on_macos_without_mpicc_downloads_mpich(tmp_path): | ||
| """Without mpicc on PATH, PETSc downloads MPICH and still gets only LDFLAGS=-Wl,-w.""" | ||
| result = _run_macos(tmp_path, ('xcrun',), path_extra='') | ||
| assert result.returncode == 0, result.stderr | ||
| args = _configure_args(tmp_path) | ||
| assert {'LDFLAGS=-Wl,-w', '--download-sundials2', '--download-mpich'} <= set(args) | ||
|
|
||
|
|
||
| def test_macos_without_xcrun_stops_before_configure(tmp_path): | ||
| """Without xcrun the script stops with its install hint and never runs configure.""" | ||
| result = _run_macos(tmp_path, ('mpicc', 'mpirun'), path_extra='') | ||
| assert result.returncode == 1 | ||
| assert 'xcrun not found' in result.stderr and 'xcode-select --install' in result.stderr | ||
| assert not (tmp_path / 'args').exists() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.