Flutter Engine
The Flutter Engine
PRESUBMIT.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5"""_macros package presubmit python script.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into gcl.
9"""
10
11PRESUBMIT_VERSION = '2.0.0'
12USE_PYTHON3 = True
13
14
15# Ensures that the pubspec of `package_name` has been altered.
16#
17# Returns a list of errors if not.
18#
19# TODO(jakemac): Ensure the version was bumped as well.
20def EnsurePubspecAndChangelogAltered(input_api, package_name):
21 errors = []
22 package_path = 'pkg/%s' % package_name
23 pubspec_path = '%s/pubspec.yaml' % package_path
24 pubspec_changed = any(file.LocalPath() == pubspec_path
25 for file in input_api.change.AffectedFiles())
26 if not pubspec_changed:
27 errors.append(
28 ('The pkg/_macros/lib dir was altered but the version of %s was '
29 'not bumped. See pkg/_macros/CONTRIBUTING.md' % package_path))
30
31 changelog_path = '%s/CHANGELOG.md' % package_path
32 changelog_changed = any(file.LocalPath() == changelog_path
33 for file in input_api.change.AffectedFiles())
34 if not changelog_changed:
35 errors.append(
36 ('The pkg/_macros/lib dir was altered but the CHANGELOG.md of %s '
37 'was not edited. See pkg/_macros/CONTRIBUTING.md' % package_path))
38 return errors
39
40# Invoked on upload and commit.
41def CheckChange(input_api, output_api):
42 errors = []
43
44 # If the `lib` dir is altered, we also require a change to the pubspec.yaml
45 # of both this package and the `macros` package.
46 lib_changed = any(file.LocalPath().startswith('pkg/_macros/lib')
47 for file in input_api.AffectedFiles())
48 if lib_changed:
49 errors += EnsurePubspecAndChangelogAltered(input_api, '_macros')
50 errors += EnsurePubspecAndChangelogAltered(input_api, 'macros')
51
52 if errors:
53 return [
54 output_api.PresubmitError(
55 'pkg/_macros presubmit/PRESUBMIT.py failure(s):',
56 long_text='\n\n'.join(errors))
57 ]
58
59 return []
def CheckChange(input_api, output_api)
Definition: PRESUBMIT.py:41
def EnsurePubspecAndChangelogAltered(input_api, package_name)
Definition: PRESUBMIT.py:20
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741