| # Copyright 2021 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Compiles platform specific executables for the scripts in dart_ci/builder |
| # and uploads them as CIPD package 'dart/ci/builder_scripts/${platform}'. |
| |
| import re |
| from recipe_engine.config_types import Path |
| |
| from PB.recipes.dart.dart.package_dart_ci import PackageDartCiOptions |
| |
| DEPS = [ |
| 'dart', |
| 'depot_tools/git', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/bcid_reporter', |
| 'recipe_engine/cipd', |
| 'recipe_engine/context', |
| 'recipe_engine/file', |
| 'recipe_engine/path', |
| 'recipe_engine/platform', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| 'safe_cipd', |
| ] |
| |
| PROPERTIES = PackageDartCiOptions |
| |
| PYTHON_VERSION_COMPATIBILITY = "PY3" |
| |
| |
| def RunSteps(api, properties): |
| # Checkout dart_ci version to build. |
| revision = api.buildbucket.gitiles_commit.id or 'HEAD' |
| got_revision = api.git.checkout( |
| url='https://dart.googlesource.com/dart_ci', |
| ref=revision, |
| set_got_revision=True) |
| target_cipd_platform = properties.target_cipd_platform |
| source_path = api.path.start_dir / 'dart_ci/builder' |
| bin_path = source_path / 'bin' |
| dart = api.dart.download_dart_sdk( |
| source_path / 'pubspec.yaml', |
| pubspec_name='builder/pubspec.yaml', |
| cipd_platform=target_cipd_platform) |
| |
| def _build_and_upload_package(package_name) -> None: |
| # Setup build |
| output_root = api.path.mkdtemp() |
| pub_cache = api.path.mkdtemp() |
| pkg = api.cipd.PackageDefinition(package_name, output_root, 'copy') |
| |
| # Compile scripts. |
| def _compile_script(input_file: Path) -> None: |
| name = input_file.pieces[-1][:-len('.dart')] |
| executable_name = (f'{name}.exe' if api.platform.is_win else name) |
| output_file = output_root / executable_name |
| api.step('compile script', |
| [dart, 'compile', 'exe', input_file, '-o', output_file]) |
| pkg.add_file(output_file) |
| |
| with api.context(cwd=source_path, env={'PUB_CACHE': pub_cache}): |
| api.step('dart pub get', [dart, 'pub', 'get']) |
| for path in api.file.glob_paths( |
| 'list dart scripts', |
| bin_path, |
| '*.dart', |
| test_data=[bin_path / 'a.dart', bin_path / 'b.dart']): |
| _compile_script(path) |
| |
| # Create CIPD package from scripts. |
| cipd_file = api.path.cleanup_dir / 'builder_scripts.zip' |
| api.safe_cipd.register( |
| package_name, |
| pkg, |
| cipd_file, |
| unique_tags={'git_revision': got_revision}, |
| refs=['latest']) |
| |
| _build_and_upload_package(f'dart/ci/builder_scripts/{target_cipd_platform}') |
| if api.platform.is_win: |
| # This will create a windows-amd64 binary, but windows-arm64 can run it. |
| _build_and_upload_package('dart/ci/builder_scripts/windows-arm64') |
| |
| |
| def GenTests(api): |
| yield api.test( |
| 'basic', |
| api.buildbucket.ci_build(builder='dart-ci-scripts-linux') + |
| api.platform('linux', 64), |
| api.properties(PackageDartCiOptions(target_cipd_platform='linux-amd64')), |
| ) |
| |
| yield api.test( |
| 'basic-win', |
| api.buildbucket.ci_build(builder='dart-ci-scripts-win') + |
| api.platform('win', 64), |
| api.properties( |
| PackageDartCiOptions(target_cipd_platform='windows-amd64')), |
| ) |
| |
| yield api.test( |
| 'basic-with-revision', |
| api.buildbucket.ci_build( |
| builder='dart-ci-scripts', revision='refs/changes/20/203220/9'), |
| api.properties(PackageDartCiOptions(target_cipd_platform='linux-amd64')), |
| ) |