Skip to content

Commit 2cb5ae4

Browse files
authored
[engine_tool] Allow a dot in GN target names (flutter#192423)
`Label._checkTarget` validated target names with `_identifier`, the same pattern used for package components, which allows no dot. `testing/dart/BUILD.gn` derives a compile target from each test file name, so all 55 of them - `compile_gpu_test.dart` and friends - were rejected, along with the `:dart` group that depends on them. Building or running any Dart test through `et` was impossible; ninja was the only way in. `_identifier` gains `.` here, for both halves of a label. Target names need it for `compile_gpu_test.dart`, and package components need it too: `DEPS` brings `third_party/swiftshader/third_party/llvm-16.0` into the checkout, and its `BUILD.gn` defines `swiftshader_llvm`. An identifier still has to start with a letter or underscore, so `.`, `..` and `...` remain invalid as a package name component, which is what keeps a label from walking out of the source tree. Fixes flutter#192422 Verified on macOS, `host_debug_unopt_arm64`. Both commands from the issue fail on master and succeed with this change: ``` $ et build -c host_debug_unopt_arm64 //flutter/testing/dart:compile_gpu_test.dart 100.0% (1/1) ACTION //flutter/testing/dart:compile_gpu_test.dart $ et build -c host_debug_unopt_arm64 //flutter/testing/dart:dart 100.0% (53/53) ACTION //flutter/testing/dart:compile_text_test.dart ``` `dart test test/label_test.dart` in `engine_tool`: 20 passed. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
1 parent fa78ae3 commit 2cb5ae4

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

‎engine/src/flutter/tools/engine_tool/lib/src/label.dart‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import 'package:meta/meta.dart';
1515
///
1616
/// Unlike counterparts in Bazel and GN:
1717
/// - The package name is always a source-absolute path (i.e. starts with `//`).
18-
/// - Valid identifier characters are `a-zA-Z0-9_-`, not starting with a digit.
18+
/// - Valid identifier characters are `a-zA-Z0-9_-.`, not starting with a digit
19+
/// or a dot.
1920
/// - The target name is never empty, even when it is a default target.
2021
@immutable
2122
final class Label {
@@ -118,7 +119,7 @@ final class Label {
118119
final int j = package.indexOf('/', i);
119120
final String component = j == -1 ? package.substring(i) : package.substring(i, j);
120121
if (!_identifier.hasMatch(component)) {
121-
return FormatException('Package name component must be a valid identifier.', package, i);
122+
return FormatException('Package name component $_identifierRule', package, i);
122123
}
123124
if (j == -1) {
124125
return null;
@@ -129,12 +130,25 @@ final class Label {
129130

130131
static FormatException? _checkTarget(String target) {
131132
if (!_identifier.hasMatch(target)) {
132-
return FormatException('Target name must be a valid identifier.', target);
133+
return FormatException('Target name $_identifierRule', target);
133134
}
134135
return null;
135136
}
136137

137-
static final RegExp _identifier = RegExp(r'^[a-zA-Z_][a-zA-Z0-9_-]*$');
138+
static const String _identifierRule =
139+
'must start with a letter or underscore and contain only letters, '
140+
'digits, "_", "-", or ".".';
141+
142+
/// Identifiers allow a dot, which both halves of a label need.
143+
///
144+
/// `testing/dart/BUILD.gn` derives a compile target from each test file name,
145+
/// giving target names like `compile_gpu_test.dart`, and directories brought
146+
/// in by `DEPS` carry a dot as well, as in
147+
/// `//flutter/third_party/swiftshader/third_party/llvm-16.0:swiftshader_llvm`.
148+
///
149+
/// The leading letter or underscore keeps `.`, `..` and `...` from passing as
150+
/// a package name component.
151+
static final RegExp _identifier = RegExp(r'^[a-zA-Z_][a-zA-Z0-9_.-]*$');
138152
}
139153

140154
/// A generic target pattern that can be used to match multiple targets.

‎engine/src/flutter/tools/engine_tool/test/label_test.dart‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ void main() {
2323
expect(() => Label.parse('//foo/bar:baz!'), throwsFormatException);
2424
});
2525

26+
test('parses a target name containing a dot', () {
27+
expect(
28+
Label.parse('//flutter/testing/dart:compile_gpu_test.dart'),
29+
Label('//flutter/testing/dart', 'compile_gpu_test.dart'),
30+
);
31+
});
32+
33+
test('parses a package component containing a dot', () {
34+
expect(
35+
Label.parse('//flutter/third_party/swiftshader/third_party/llvm-16.0:swiftshader_llvm'),
36+
Label('//flutter/third_party/swiftshader/third_party/llvm-16.0', 'swiftshader_llvm'),
37+
);
38+
});
39+
40+
test('rejects a component that is only dots', () {
41+
expect(() => Label.parse('//foo/../bar'), throwsFormatException);
42+
expect(() => Label.parse('//foo/./bar'), throwsFormatException);
43+
expect(() => Label.parse('//foo/bar:.'), throwsFormatException);
44+
});
45+
2646
test('rejects ending with a slash', () {
2747
expect(() => Label.parse('//foo/bar/'), throwsFormatException);
2848
expect(() => Label.parse('//foo/bar:baz/'), throwsFormatException);

0 commit comments

Comments
 (0)