Skip to content

Commit 8df8de8

Browse files
jakemac53Commit Queue
authored and
Commit Queue
committed
Ensure that the pubspecs of both _macros and macros packages are updated whenever the lib/ dir of _macros is edited.
Related to https://dart-review.googlesource.com/c/sdk/+/359040 Change-Id: Iab3cfa89e0492282c348c6a72f3032191fa4998f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359580 Auto-Submit: Jake Macdonald <[email protected]> Commit-Queue: Jake Macdonald <[email protected]> Reviewed-by: Bob Nystrom <[email protected]>
1 parent d1a949a commit 8df8de8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

pkg/_macros/PRESUBMIT.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
7+
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8+
for more details about the presubmit API built into gcl.
9+
"""
10+
11+
PRESUBMIT_VERSION = '2.0.0'
12+
USE_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.
20+
def EnsurePubspecAltered(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+
return errors
31+
32+
33+
# Invoked on upload and commit.
34+
def CheckChange(input_api, output_api):
35+
errors = []
36+
37+
# If the `lib` dir is altered, we also require a change to the pubspec.yaml
38+
# of both this package and the `macros` package.
39+
lib_changed = any(file.LocalPath().startswith('pkg/_macros/lib')
40+
for file in input_api.AffectedFiles())
41+
if lib_changed:
42+
errors += EnsurePubspecAltered(input_api, '_macros')
43+
errors += EnsurePubspecAltered(input_api, 'macros')
44+
45+
if errors:
46+
return [
47+
output_api.PresubmitError(
48+
'pkg/_macros presubmit/PRESUBMIT.py failure(s):',
49+
long_text='\n\n'.join(errors))
50+
]
51+
52+
return []

0 commit comments

Comments
 (0)