| # 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 |
| |
| DEPS = [ |
| 'depot_tools/git', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/cipd', |
| 'recipe_engine/context', |
| 'recipe_engine/file', |
| 'recipe_engine/path', |
| 'recipe_engine/platform', |
| 'recipe_engine/step', |
| ] |
| |
| PYTHON_VERSION_COMPATIBILITY = "PY3" |
| |
| _TEST_PUBSPEC = ''' |
| name: builder |
| description: Scripts run on Dart CQ/CI builders |
| publish_to: none |
| version: 0.1.0 |
| |
| environment: |
| sdk: 2.17.6-1.2.beta # Pinned, the recipe will use this exact version. |
| |
| dependencies: |
| args: ^2.3.0 |
| ''' |
| _SDK_VERSION = r'''^\s+sdk:\s+[\"\']?(?P<sdk>[0-9]+\.[0-9]+\.[0-9]+[\w.\-\+]*)''' |
| |
| |
| def _read_dart_version_from_pubspec(api, source_path: Path) -> str: |
| pubspec_path = source_path.join('pubspec.yaml') |
| pubspec = api.file.read_text( |
| 'read pubspec.yaml', pubspec_path, test_data=_TEST_PUBSPEC) |
| return re.search(_SDK_VERSION, pubspec, flags=re.MULTILINE).group('sdk') |
| |
| |
| def RunSteps(api): |
| # 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) |
| source_path = api.path['start_dir'].join('dart_ci', 'builder') |
| bin_path = source_path.join('bin') |
| # Get the Dart SDK to be used to compile the scripts. |
| packages_path = api.path['cache'].join('cipd_packages') |
| ensure_file = api.cipd.EnsureFile() |
| # Cannot use ensure_tool here because of dartbug.com/46364 |
| dart_version = _read_dart_version_from_pubspec(api, source_path) |
| ensure_file.add_package('dart/dart-sdk/${platform}', |
| f'version:{dart_version}') |
| api.cipd.ensure(packages_path, ensure_file) |
| dart = packages_path.join('dart-sdk', 'bin', 'dart') |
| |
| # Setup build |
| output_root = api.path.mkdtemp() |
| pub_cache = api.path.mkdtemp() |
| package_name = 'dart/ci/builder_scripts/${platform}' |
| 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.join(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.join('a.dart'), |
| bin_path.join('b.dart')]): |
| _compile_script(path) |
| |
| # Create CIPD package from scripts. |
| api.cipd.create_from_pkg( |
| pkg, tags={'git_revision': got_revision}, refs=['latest']) |
| |
| |
| def GenTests(api): |
| yield api.test( |
| 'basic', |
| api.buildbucket.ci_build(builder='dart-ci-scripts-linux') + |
| api.platform('linux', 64), |
| ) |
| |
| yield api.test( |
| 'basic-win', |
| api.buildbucket.ci_build(builder='dart-ci-scripts-win') + |
| api.platform('win', 64), |
| ) |
| |
| yield api.test( |
| 'basic-with-revision', |
| api.buildbucket.ci_build( |
| builder='dart-ci-scripts', revision='refs/changes/20/203220/9'), |
| ) |