Skip to content

Commit b9cc62e

Browse files
committed
generate cache operations in place
1 parent bd27a46 commit b9cc62e

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

scripts/gen_ext_cache_scripts.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pathlib import Path
2+
import subprocess
3+
import sys
4+
5+
6+
HERE = Path(__file__).resolve().parent
7+
ROOT = HERE.parent
8+
9+
# Get extension information from setup.py
10+
output = subprocess.check_output([sys.executable, ROOT / "setup.py", "ext_hashes", "--inplace"])
11+
cached_files = []
12+
for line in output.decode().splitlines():
13+
if not line.startswith("#EXTHASH:"):
14+
continue
15+
ext_name, ext_hash, ext_target = eval(line.split(":", 1)[-1].strip())
16+
cached_files.append((f".ext_cache/{ext_name}/{ext_hash}/{Path(ext_target).name}", ext_target))
17+
18+
# Generate the restore script
19+
(HERE / "restore_ext_cache.sh").write_text(
20+
"\n".join(
21+
[
22+
f" test -f {cached_file} && (cp {cached_file} {dest} && touch {dest} "
23+
f"&& echo 'Restored {cached_file} -> {dest}') || true"
24+
for cached_file, dest in cached_files
25+
]
26+
)
27+
)
28+
29+
# Generate the save script
30+
(HERE / "save_ext_cache.sh").write_text(
31+
"\n".join(
32+
[
33+
f" test -f {cached_file} || mkdir -p {Path(cached_file).parent} && (cp {dest} {cached_file} "
34+
f"&& echo 'Saved {dest} -> {cached_file}' || true)"
35+
for cached_file, dest in cached_files
36+
]
37+
)
38+
)

scripts/gen_gitlab_config.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -251,29 +251,6 @@ def check(name: str, command: str, paths: t.Set[str]) -> None:
251251

252252
def gen_build_base_venvs() -> None:
253253
"""Generate the list of base jobs for building virtual environments."""
254-
output = subprocess.check_output([sys.executable, ROOT / "setup.py", "ext_hashes", "--inplace"])
255-
cached_files = []
256-
for line in output.decode().splitlines():
257-
if not line.startswith("#EXTHASH:"):
258-
continue
259-
ext_name, ext_hash, ext_target = eval(line.split(":", 1)[-1].strip())
260-
cached_files.append((f".ext_cache/{ext_name}/{ext_hash}/{Path(ext_target).name}", ext_target))
261-
262-
restore_ext_cache = "\n".join(
263-
[
264-
f" test -f {cached_file} && (cp {cached_file} {dest} && touch {dest} "
265-
f"&& echo 'Restored {cached_file} -> {dest}') || true"
266-
for cached_file, dest in cached_files
267-
]
268-
)
269-
270-
save_ext_cache = "\n".join(
271-
[
272-
f" test -f {cached_file} || mkdir -p {Path(cached_file).parent} && (cp {dest} {cached_file} "
273-
f"&& echo 'Saved {dest} -> {cached_file}' || true)"
274-
for cached_file, dest in cached_files
275-
]
276-
)
277254

278255
current_month = datetime.datetime.now().month
279256

@@ -297,6 +274,7 @@ def gen_build_base_venvs() -> None:
297274
DD_FAST_BUILD: '1'
298275
DD_CMAKE_INCREMENTAL_BUILD: '1'
299276
DD_SETUP_CACHE_DOWNLOADS: '1'
277+
EXT_CACHE_VENV: '${{CI_PROJECT_DIR}}/.cache/ext_cache_venv'
300278
rules:
301279
- if: '$CI_COMMIT_REF_NAME == "main"'
302280
variables:
@@ -306,11 +284,20 @@ def gen_build_base_venvs() -> None:
306284
set -e -o pipefail
307285
apt update && apt install -y sccache
308286
pip install riot==0.20.1
309-
{restore_ext_cache}
287+
if [ ! -d $EXT_CACHE_VENV ]; then
288+
python$PYTHON_VERSION -m venv $EXT_CACHE_VENV
289+
source $EXT_CACHE_VENV/bin/activate
290+
pip install cmake setuptools_rust Cython
291+
else
292+
source $EXT_CACHE_VENV/bin/activate
293+
fi
294+
python scripts/gen_ext_cache_scripts.py
295+
deactivate
296+
$SHELL scripts/restore-ext-cache.sh
310297
riot -P -v generate --python=$PYTHON_VERSION
311298
echo "Running smoke tests"
312299
riot -v run -s --python=$PYTHON_VERSION smoke_test
313-
{save_ext_cache}
300+
$SHELL scripts/save-ext-cache.sh
314301
cache:
315302
# Share pip/sccache between jobs of the same Python version
316303
- key: v1-build_base_venvs-${{PYTHON_VERSION}}-cache-{current_month}
@@ -325,6 +312,8 @@ def gen_build_base_venvs() -> None:
325312
artifacts:
326313
name: venv_$PYTHON_VERSION
327314
paths:
315+
- scripts/restore-ext-cache.sh
316+
- scripts/save-ext-cache.sh
328317
- ddtrace/**/*.so*
329318
- ddtrace/internal/datadog/profiling/crashtracker/crashtracker_exe*
330319
- ddtrace/internal/datadog/profiling/test/test_*

0 commit comments

Comments
 (0)