-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathprincipia_make.sh
More file actions
142 lines (122 loc) 路 4.56 KB
/
Copy pathprincipia_make.sh
File metadata and controls
142 lines (122 loc) 路 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! /bin/bash
readonly SQUIRREL_EXTENSION='.squirrel'
if [[ "${PRINCIPIA_PLATFORM?}" != "x64" &&
"${PRINCIPIA_PLATFORM?}" != "x64_AVX_FMA" ]]; then
echo "PRINCIPIA_PLATFORM must be x64 or x64_AVX_FMA."
exit 1
fi
if [[ "${PRINCIPIA_PLATFORM?}" == "x64_AVX_FMA" ]]; then
platform_golden_suffix="_fma"
fi
if [[ "${AGENT_OS?}" == "Darwin" ]]; then
os_golden_suffix="_macos"
parallelism=$(sysctl -n hw.ncpu)
target="each_test"
elif [[ "${AGENT_OS?}" == "Linux" ]]; then
os_golden_suffix="_linux"
# It seems that protoc really wants its dependencies to be in /usr/local/lib.
# In some setups, e.g., Azure pipelines, this does not work, so we need to
# help it find its dynamic libraries.
export LD_LIBRARY_PATH="./deps/protobuf/src/.libs:$LD_LIBRARY_PATH"
parallelism=$(nproc --all)
target="each_package_test"
fi
echo "Parallelism is ${parallelism}."
make clean
# Build the target, catching errors and grabbing the status.
set +e
make -j ${parallelism} \
--keep-going \
bin/${PRINCIPIA_PLATFORM}/benchmark \
bin/${PRINCIPIA_PLATFORM}/nanobenchmark \
${target}
make_exit_status=$?
set -e
echo "Make finished with status ${make_exit_status}."
# Add all PNG files so new files are tracked.
git add *.png
if git diff --quiet HEAD; then
echo "No files changed."
else
# `git diff --name-status --no-renames` outputs something like:
# A path/to/new.file
# D path/to/deleted.file
# M path/to/modified.file
git config core.quotePath false
git diff --name-status --no-renames HEAD \
| awk '/\.png/ {
if ($1 == "D") {
print("(deleted) " $2)
} else {
system("shasum -b " $2)
}
}' \
> /tmp/golden_hashes.txt
cat /tmp/golden_hashes.txt
final_hash=$(shasum /tmp/golden_hashes.txt | awk '{print($1)}')
branch_name="goldens-${final_hash}-${AGENT_OS}-${PRINCIPIA_PLATFORM}"
echo "Looking for branch ${branch_name}."
# `ls-remote` fails if the branch does not exist, so we need to handle errors.
set +e
git ls-remote --exit-code \
--heads https://github.com/enrico-dandolo/Principia.git \
refs/heads/${branch_name}
ls_remote_exit_status=$?
set -e
if (( ls_remote_exit_status == 2 )); then
# The branch does not exists. Configure git and find the changed files.
git config user.email "enrico.dandolo@mockingbirdnest.com"
git config user.name "Enrico Dandolo"
git checkout -b ${branch_name}
golden_suffix="${os_golden_suffix}${platform_golden_suffix}"
files_changed=$(git diff --name-only HEAD | grep '\.png')
# For each changed file, squirrel away the updated file (if any) and copy
# the default (Windows) golden in its place.
for file in ${files_changed}; do
if [[ -f ${file} ]]; then
mv "${file}" "${file}${SQUIRREL_EXTENSION}"
fi
cp $(echo "${file}" | sed "s/${golden_suffix}\.png/.png/") "${file}"
done
# Create a commit where the default goldens were copied over the existing,
# platform-specific, goldens.
git reset
git add *.png
git commit \
-m "Copy default goldens over ${AGENT_OS} ${PRINCIPIA_PLATFORM} goldens"
# For each changed file, copy the squirrelled-away (updated) file on top of
# the default golden.
for file in ${files_changed}; do
if [[ -f "${file}${SQUIRREL_EXTENSION}" ]]; then
mv -f "${file}${SQUIRREL_EXTENSION}" "${file}"
else
git rm "${file}"
fi
done
# Create a commit where the updated files were copied over the default
# goldens. Together, the two commits make it possible to figure out (1)
# how the platform-specific goldens changed (2) how they differ from the
# Windows golden.
git add *.png
git commit -m "Update goldens for ${AGENT_OS} ${PRINCIPIA_PLATFORM}"
# Create a PR with the two commits.
git push --set-upstream \
"https://${GH_TOKEN}@github.com/enrico-dandolo/Principia.git" \
${branch_name}
gh pr create --fill --head enrico-dandolo:${branch_name} \
--title "Update goldens for ${AGENT_OS} ${PRINCIPIA_PLATFORM}"
else
echo "Branch ${branch_name} already exists."
echo "Merge the following PR to update these goldens:"
gh pr list --head ${branch_name}
fi
fi
if (( make_exit_status != 0 )); then
exit ${make_exit_status}
fi
if [[ "${AGENT_OS?}" == "Darwin" ]]; then
# See https://github.com/actions/virtual-environments/issues/2619#issuecomment-788397841
# for why this is needed.
sudo /usr/sbin/purge
fi
make release