Skip to content

Commit f3c56c4

Browse files
mpagemeta-codesync[bot]
authored andcommitted
Add a convenience wrapper script for updating HIR fixtures
Summary: Add a script that automates updating our HIR fixtures for all supported Python versions Reviewed By: alexmalyshev Differential Revision: D109868164 fbshipit-source-id: 3af4f46267d6d5bc3ad0063a40d40548ddbce35c
1 parent 3ed69a2 commit f3c56c4

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# Regenerate the JIT HIR test fixtures for one or more supported Python versions.
5+
#
6+
# Usage:
7+
# ./update_hir_fixtures.sh # update all supported versions
8+
# ./update_hir_fixtures.sh 3.14 3.16 # update only the given versions
9+
#
10+
# With no arguments the set of versions is discovered from buck: every enabled
11+
# RuntimeTests_<ver> target (i.e. those PY_VERSION_MAP entries with the C++
12+
# unittest feature). This means a newly supported Python version is picked up
13+
# automatically with no change to this script.
14+
15+
set -xeuo pipefail
16+
17+
script_dir="$(dirname "$(readlink -f "$0")")"
18+
19+
# buck resolves the project root from the working directory, so its invocations
20+
# run in a subshell that cd's into the repo. This keeps the script's own working
21+
# directory unchanged.
22+
function discover_versions() {
23+
( cd "$script_dir" && buck2 uquery \
24+
"fbcode//cinderx/RuntimeTests: except attrfilter(labels, disabled, fbcode//cinderx/RuntimeTests:)" \
25+
2>/dev/null ) \
26+
| sed -n 's#^fbcode//cinderx/RuntimeTests:RuntimeTests_\([0-9]\+\.[0-9]\+t\?\)$#\1#p'
27+
}
28+
29+
function update_for_version() {
30+
local v="$1"
31+
local tmp
32+
tmp="$(mktemp)"
33+
# A non-zero exit just means some tests failed, which is how the updater
34+
# discovers what to rewrite. buck's own logging goes to stderr.
35+
( cd "$script_dir" && buck2 run @fbcode//mode/opt \
36+
"fbcode//cinderx/RuntimeTests:RuntimeTests_$v" -- --gtest_color=no \
37+
> "$tmp" 2>/dev/null ) || true
38+
fbpython "$script_dir/update_hir_expected.py" -t "$tmp"
39+
rm -f "$tmp"
40+
}
41+
42+
versions=("$@")
43+
if [ "${#versions[@]}" -eq 0 ]; then
44+
mapfile -t versions < <(discover_versions)
45+
fi
46+
47+
for v in "${versions[@]}"; do
48+
update_for_version "$v"
49+
done

0 commit comments

Comments
 (0)