Skip to content

Commit 3b6b988

Browse files
committed
Enable 'mfc run' by patching toolchain to use Homebrew binaries
The formula now patches the toolchain's build.py to redirect binary paths to the Homebrew-installed pre-built binaries. This allows 'mfc run' to work without requiring the full source tree or rebuilding binaries. Changes: - Patch toolchain/mfc/build.py to override get_install_binpath() - Patch is_built() to check Homebrew bin directory - Automatically add --no-build flag for 'mfc run' command - Restore CI test for 'mfc run' with 1D Sod shock tube case - Update caveats to show 'mfc run' as primary usage This makes the Homebrew package fully functional for end users!
1 parent ac6248f commit 3b6b988

File tree

2 files changed

+74
-42
lines changed

2 files changed

+74
-42
lines changed

.github/workflows/homebrew.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ jobs:
144144
145145
echo "=== All tests passed! ==="
146146
147-
# Note: The 'mfc run' command requires the full MFC source tree to build/run cases.
148-
# The Homebrew formula only installs pre-built binaries, not the development source.
149-
# Users who need 'mfc run' should clone the MFC repository and use mfc.sh there.
150-
# The pre-built binaries (pre_process, simulation, post_process) can be used directly.
147+
- name: Run MFC test case
148+
run: |
149+
echo "Running a simple test case (1D Sod shock tube)..."
150+
TESTDIR=$(mktemp -d)
151+
cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py "$TESTDIR/"
152+
153+
echo "Running with $(sysctl -n hw.ncpu) processors..."
154+
cd "$TESTDIR"
155+
mfc run case.py -j $(sysctl -n hw.ncpu)
156+
157+
echo "Test case completed successfully!"
151158
152159
- name: Uninstall and cleanup
153160
if: always()

packaging/homebrew/mfc.rb

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -73,57 +73,82 @@ def install
7373
# 2. Sets up toolchain symlink so mfc.sh can find toolchain/util.sh
7474
# 3. Ensures mfc.sh doesn't reinstall packages by copying pyproject.toml
7575
(bin/"mfc").write <<~EOS
76-
#!/bin/bash
77-
set -e
78-
79-
# Unset VIRTUAL_ENV to ensure mfc.sh uses the copied venv, not the Cellar one
80-
unset VIRTUAL_ENV
81-
82-
# Create a temporary working directory (Cellar is read-only)
83-
TMPDIR=$(mktemp -d)
84-
trap "rm -rf $TMPDIR" EXIT
85-
86-
# Copy mfc.sh to temp dir (it may try to write build artifacts)
87-
cp "#{libexec}/mfc.sh" "$TMPDIR/"
88-
cd "$TMPDIR"
89-
90-
# Copy toolchain directory (not symlink) so Python paths resolve correctly
91-
# This prevents paths from resolving back to read-only Cellar
92-
cp -R "#{prefix}/toolchain" toolchain
93-
94-
# Copy examples directory (required by mfc.sh Python code)
95-
cp -R "#{prefix}/examples" examples
96-
97-
# Create build directory and copy venv (not symlink - needs to be writable)
98-
# Use cp -R for a full recursive copy
99-
mkdir -p build
100-
cp -R "#{venv}" build/venv
101-
102-
# Copy pyproject.toml to build/ so mfc.sh thinks dependencies are already installed
103-
cp "#{prefix}/toolchain/pyproject.toml" build/pyproject.toml
104-
105-
# Run mfc.sh with all arguments
106-
exec ./mfc.sh "$@"
76+
#!/bin/bash
77+
set -e
78+
79+
# Unset VIRTUAL_ENV to ensure mfc.sh uses the copied venv, not the Cellar one
80+
unset VIRTUAL_ENV
81+
82+
# Create a temporary working directory (Cellar is read-only)
83+
TMPDIR=$(mktemp -d)
84+
trap "rm -rf $TMPDIR" EXIT
85+
86+
# Copy mfc.sh to temp dir (it may try to write build artifacts)
87+
cp "#{libexec}/mfc.sh" "$TMPDIR/"
88+
cd "$TMPDIR"
89+
90+
# Copy toolchain directory (not symlink) so Python paths resolve correctly
91+
# This prevents paths from resolving back to read-only Cellar
92+
cp -R "#{prefix}/toolchain" toolchain
93+
94+
# Patch toolchain to use Homebrew-installed binaries
95+
# Replace get_install_binpath to return Homebrew bin directory
96+
cat >> toolchain/mfc/build.py << 'PATCH_EOF'
97+
98+
# Homebrew patch: Override get_install_binpath to use pre-installed binaries
99+
_original_get_install_binpath = MFCTarget.get_install_binpath
100+
def _homebrew_get_install_binpath(self, case):
101+
return "#{bin}/" + self.name
102+
MFCTarget.get_install_binpath = _homebrew_get_install_binpath
103+
104+
# Also override is_built to check Homebrew bin directory
105+
_original_is_built = MFCTarget.is_built
106+
def _homebrew_is_built(self, case):
107+
import os
108+
if self.name in ["pre_process", "simulation", "post_process"]:
109+
return os.path.isfile("#{bin}/" + self.name)
110+
return _original_is_built(self, case)
111+
MFCTarget.is_built = _homebrew_is_built
112+
PATCH_EOF
113+
114+
# Copy examples directory (required by mfc.sh Python code)
115+
cp -R "#{prefix}/examples" examples
116+
117+
# Create build directory and copy venv (not symlink - needs to be writable)
118+
# Use cp -R for a full recursive copy
119+
mkdir -p build
120+
cp -R "#{venv}" build/venv
121+
122+
# Copy pyproject.toml to build/ so mfc.sh thinks dependencies are already installed
123+
cp "#{prefix}/toolchain/pyproject.toml" build/pyproject.toml
124+
125+
# For 'mfc run', add --no-build flag to skip compilation
126+
if [ "$1" = "run" ]; then
127+
exec ./mfc.sh "$@" --no-build
128+
else
129+
exec ./mfc.sh "$@"
130+
fi
107131
EOS
108132
end
109133

110134
def caveats
111135
<<~EOS
112136
MFC has been installed successfully!
113137
114-
Pre-built binaries are available:
138+
To run a case:
139+
mfc run <case.py>
140+
141+
Pre-built binaries are also available directly:
115142
pre_process, simulation, post_process
116143
117144
Examples are available in:
118145
#{prefix}/examples
119146
120-
Note: The 'mfc run' command requires the full MFC source tree.
121-
For development workflows, clone the repository and use mfc.sh:
122-
git clone https://github.com/MFlowCode/MFC.git
123-
cd MFC
124-
./mfc.sh run <case.py>
147+
Example:
148+
cp #{prefix}/examples/1D_sodshocktube/case.py .
149+
mfc run case.py
125150
126-
Cantera 3.1.0 is pre-installed in the MFC virtual environment.
151+
Note: Cantera 3.1.0 is pre-installed in the MFC virtual environment.
127152
EOS
128153
end
129154

0 commit comments

Comments
 (0)