Files
2026-07-13 13:04:25 +08:00

79 lines
3.1 KiB
Python

# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
"""Patch the generated Build system v2 build child pipeline in place.
The buildv2 build child pipeline is generated by ``idf-ci gitlab build-child-pipeline``
from the same manifest as the default pipeline. This script post-processes that
generated YAML so the cmakev2 path is exercised end to end:
1. Inject ``IDF_BUILD_V2`` into each child build job so cmake activates the
cmakev2 shim.
2. Inject ``PIPELINE_COMMIT_SHA: ${PIPELINE_COMMIT_SHA}_buildv2`` into each child
build job. idf-ci reads ``PIPELINE_COMMIT_SHA`` when computing the s3
upload/download prefix (``project/<sha>/...``). Suffixing it for v2 jobs only
routes v2 binaries to a distinct s3 key namespace without renaming build_dir.
3. Redefine ``generate_pytest_child_pipeline`` so its script also runs
``patch_buildv2_target_test_pipeline.py`` against the emitted
``target_test_child_pipeline.yml`` and injects the same
``PIPELINE_COMMIT_SHA`` override into each target_test job. Without this, the
v2 target_test pipeline would still download from the default pipeline's s3
keys (race-determined, mostly cmakev1 binaries).
"""
import argparse
import yaml
PIPELINE_COMMIT_SHA_V2 = '${PIPELINE_COMMIT_SHA}_buildv2'
def patch(path: str) -> None:
with open(path) as f:
d = yaml.safe_load(f)
injected = []
for k, v in d.items():
if isinstance(v, dict) and 'extends' in v:
v.setdefault('variables', {})['IDF_BUILD_V2'] = '1'
v['variables']['PIPELINE_COMMIT_SHA'] = PIPELINE_COMMIT_SHA_V2
injected.append(k)
# Redefine generate_pytest_child_pipeline (included from
# tools/ci/dynamic_pipelines/templates/test_child_pipeline.yml) so its script
# also rewrites target_test_child_pipeline.yml. GitLab CI merges values at the
# keyword level, so only `script` is overridden; `needs`, `artifacts`,
# `image`, etc. come from the included version.
d['generate_pytest_child_pipeline'] = {
# Set IDF_BUILD_V2 so test-case collection honors `if IDF_BUILD_V2 == "1"`
'variables': {'IDF_BUILD_V2': '1'},
'script': [
'python tools/ci/dynamic_pipelines/scripts/generate_target_test_child_pipeline.py',
'python tools/ci/dynamic_pipelines/scripts/patch_buildv2_target_test_pipeline.py '
'target_test_child_pipeline.yml',
],
}
with open(path, 'w') as f:
yaml.safe_dump(d, f, sort_keys=False)
print('Injected IDF_BUILD_V2 + PIPELINE_COMMIT_SHA into build jobs:', injected)
print('Redefined generate_pytest_child_pipeline with post-processing step')
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'pipeline_yaml',
nargs='?',
default='buildv2_child_pipeline.yml',
help='Path to the generated buildv2 build child pipeline YAML to patch in place.',
)
args = parser.parse_args()
patch(args.pipeline_yaml)
if __name__ == '__main__':
main()