diff --git a/benchpress/cli/commands/run.py b/benchpress/cli/commands/run.py index 199fc5bb..b82415a8 100644 --- a/benchpress/cli/commands/run.py +++ b/benchpress/cli/commands/run.py @@ -27,7 +27,12 @@ from benchpress import PROJECT, VERSION # @manual except ImportError: from benchpress.version import __PROJECT__ as PROJECT, __VERSION__ as VERSION -from benchpress.lib.util import BENCHPRESS_ROOT, get_artifacts_dir, verify_install +from benchpress.lib.util import ( + BENCHPRESS_ROOT, + get_artifacts_dir, + get_fixed_benchmark_version, + verify_install, +) try: from diagnosis_utils import DiagnosisRecorder # pyre-ignore[21] @@ -258,11 +263,12 @@ def get_version_info(self, benchmarks_arg=None): except (subprocess.SubprocessError, FileNotFoundError): pass - # Check if current directory is under v1 folder - cwd = os.getcwd() - if "/v1/" in cwd or cwd.endswith("/v1"): + # A `VERSION` marker file colocated with the CLI (e.g. the fbpkg's v1/ + # folder) pins this install to a fixed benchmark version. + fixed_version = get_fixed_benchmark_version() + if fixed_version: version_info["source"] = "fixed" - version_info["version"] = "v1" + version_info["version"] = fixed_version return version_info return version_info diff --git a/benchpress/cli/main.py b/benchpress/cli/main.py index db67fab8..86445a5b 100644 --- a/benchpress/cli/main.py +++ b/benchpress/cli/main.py @@ -25,7 +25,12 @@ from benchpress.lib.job_listing import create_job_listing from benchpress.lib.reporter import JSONFileReporter, ScoreReporter, StdoutReporter from benchpress.lib.reporter_factory import ReporterFactory -from benchpress.lib.util import generate_run_id, generate_timestamp, set_artifacts_dir +from benchpress.lib.util import ( + generate_run_id, + generate_timestamp, + get_fixed_benchmark_version, + set_artifacts_dir, +) from benchpress.plugins.hooks import user_script from .commands.clean import CleanCommand @@ -233,11 +238,12 @@ def setup_parser(): ) parser.add_argument("--verbose", "-v", action="count", default=0) version_str = f"{PROJECT} {VERSION}" - # When invoked from the v1 folder the harness ships the frozen v1.0 - # benchmark packages, so flag that explicitly in --version output. - cwd = os.getcwd() - if "/v1/" in cwd or cwd.endswith("/v1"): - version_str += " (v1.0 benchmark packages)" + # A `VERSION` marker file colocated with the CLI (e.g. the fbpkg's v1/ + # folder) pins the harness to a frozen benchmark package set; flag that + # explicitly in --version output. + fixed_version = get_fixed_benchmark_version() + if fixed_version: + version_str += f" ({fixed_version}.0 benchmark packages)" parser.add_argument("--version", action="version", version=version_str) return parser diff --git a/benchpress/lib/util.py b/benchpress/lib/util.py index 40eea597..270bd721 100644 --- a/benchpress/lib/util.py +++ b/benchpress/lib/util.py @@ -78,6 +78,35 @@ def resolve_script_path(script_path: str) -> str: return os.path.join(BENCHPRESS_ROOT, script_path) +# Name of the marker file that pins an install to a fixed benchmark version. +VERSION_MARKER_FILE = "VERSION" + + +def get_fixed_benchmark_version() -> typing.Optional[str]: + """Return the fixed benchmark-version label pinned by a colocated marker. + + The DCPerf fbpkg lays down a ``v1/`` folder holding the frozen v1.0 + benchmark packages alongside a ``benchpress`` CLI symlink. A ``VERSION`` + file sitting next to that CLI (i.e. directly under ``BENCHPRESS_ROOT``) + marks the install as shipping a fixed benchmark package set, with the + release label (e.g. ``"v1"``) as its contents. + + Anchoring to ``BENCHPRESS_ROOT`` -- the directory of the CLI executable + itself -- rather than the current working directory avoids false positives + for unrelated paths that merely contain a ``v1`` component (e.g. running the + harness from ``/home/user/projects/v1/tmp``). + + Returns the marker's stripped contents, or ``None`` when the marker is + absent or empty. + """ + marker_path = os.path.join(BENCHPRESS_ROOT, VERSION_MARKER_FILE) + try: + with open(marker_path, "r") as f: + return f.read().strip() or None + except OSError: + return None + + def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)