Skip to content

Commit 2874c19

Browse files
committed
mfc.sh: add --prebuilt-prefix for running against prebuilt binaries (#1444)
1 parent b136724 commit 2874c19

5 files changed

Lines changed: 46 additions & 4 deletions

File tree

mfc.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ if [ $code -ne 0 ]; then
102102
error "main.py finished with a $code exit code."
103103
fi
104104

105-
# Deactivate the Python virtualenv in case the user "source"'d this script
106-
log "(venv) Exiting the$MAGENTA Python$COLOR_RESET virtual environment."
107-
deactivate
105+
# Deactivate the Python virtualenv in case the user "source"'d this script.
106+
# In prebuilt/spack mode the venv was never created, so there's nothing to deactivate.
107+
if type deactivate > /dev/null 2>&1; then
108+
log "(venv) Exiting the$MAGENTA Python$COLOR_RESET virtual environment."
109+
deactivate
110+
fi
108111

109112
# Exit with proper exit code
110113
exit $code

toolchain/bootstrap/python.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ MFC_PYTHON_MIN_MAJOR=3
44
MFC_PYTHON_MIN_MINOR=9
55
MFC_PYTHON_MIN_STR="$MFC_PYTHON_MIN_MAJOR.$MFC_PYTHON_MIN_MINOR"
66

7+
# Prebuilt/spack mode: skip the venv entirely. The caller must already have
8+
# python3 + the MFC toolchain deps + the `mfc` package importable on PYTHONPATH.
9+
if [ -n "${MFC_PREBUILT_PREFIX:-}" ]; then
10+
return 0
11+
fi
12+
713
is_python_compatible() {
814
if ! ${1:-python3} -c "import sys; exit(int(not (sys.version_info[0]==$MFC_PYTHON_MIN_MAJOR and sys.version_info[1] >= $MFC_PYTHON_MIN_MINOR)))"; then
915
return 1

toolchain/mfc/build.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from rich.text import Text
1515

1616
from .case import Case
17-
from .common import MFCException, create_directory, debug, delete_directory, format_list_to_string, system
17+
from .common import MFCException, create_directory, debug, delete_directory, format_list_to_string, get_prebuilt_prefix, system
1818
from .printer import cons
1919
from .run import input
2020
from .state import ARG, CFG, gpuConfigOptions
@@ -336,6 +336,9 @@ def get_home_dirpath(self) -> str:
336336
return os.sep.join([os.getcwd()])
337337

338338
def get_install_binpath(self, case: Case) -> str:
339+
prebuilt = get_prebuilt_prefix()
340+
if prebuilt:
341+
return os.sep.join([prebuilt, "bin", self.name])
339342
# <root>/install/<slug>/bin/<target>
340343
return os.sep.join([self.get_install_dirpath(case), "bin", self.name])
341344

@@ -359,6 +362,9 @@ def is_buildable(self) -> bool:
359362
if ARG("no_build"):
360363
return False
361364

365+
if get_prebuilt_prefix():
366+
return False
367+
362368
if self.isDependency and ARG(f"sys_{self.name}", False):
363369
return False
364370

toolchain/mfc/cli/commands.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@
274274
default=False,
275275
dest="no_build",
276276
),
277+
Argument(
278+
name="prebuilt-prefix",
279+
help="Use prebuilt MFC binaries from <PREFIX>/bin (e.g. a Spack install prefix). Implies --no-build. Also settable via MFC_PREBUILT_PREFIX.",
280+
type=str,
281+
default=None,
282+
metavar="PREFIX",
283+
dest="prebuilt_prefix",
284+
),
277285
Argument(
278286
name="wait",
279287
help="(Batch) Wait for the job to finish.",
@@ -437,6 +445,14 @@
437445
default=False,
438446
dest="no_build",
439447
),
448+
Argument(
449+
name="prebuilt-prefix",
450+
help="Use prebuilt MFC binaries from <PREFIX>/bin (e.g. a Spack install prefix). Implies --no-build. Also settable via MFC_PREBUILT_PREFIX.",
451+
type=str,
452+
default=None,
453+
metavar="PREFIX",
454+
dest="prebuilt_prefix",
455+
),
440456
Argument(
441457
name="no-examples",
442458
help="Do not test example cases.",

toolchain/mfc/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ def debug(msg: str):
4242
MFC_BENCH_FILEPATH = abspath(join(MFC_TOOLCHAIN_DIR, "bench.yaml"))
4343
MFC_MECHANISMS_DIR = abspath(join(MFC_TOOLCHAIN_DIR, "mechanisms"))
4444

45+
46+
def get_prebuilt_prefix() -> typing.Optional[str]:
47+
# Returns the prebuilt install prefix when MFC is run against pre-built binaries
48+
# (e.g. a Spack install). The CLI flag --prebuilt-prefix takes precedence over the
49+
# MFC_PREBUILT_PREFIX environment variable. Returns None when running normally.
50+
from .state import ARG
51+
52+
cli = ARG("prebuilt_prefix", "") or None
53+
return cli or os.environ.get("MFC_PREBUILT_PREFIX") or None
54+
55+
4556
MFC_LOGO = """\
4657
.=++*: -+*+=.
4758
:+ -*- == =* .

0 commit comments

Comments
 (0)