-
Notifications
You must be signed in to change notification settings - Fork 6k
Introduce a prototype of a "header guard enforcement" tool #48903
Conversation
Automatically generated by #48903. Progress towards flutter/flutter#133415.
test-exempt: tested by #48903 |
Ok, I think I'm ready to land the tool (without enforcing it on CI - that will be another PR). PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a couple of suggestions. There were a few places where there may be false positives, but we'll get those sorted out easy if this is running on ci.
|
||
// Recursive search for header files. | ||
final io.Directory dir = source.flutterDir; | ||
await for (final io.FileSystemEntity entity in dir.list(recursive: true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend pulling this out to a generator, this method is long and probably looks really familiar to something you've written dozens of times before =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Or I misunderstood your comment, so please feel free to add more.
|
||
// Check each file. | ||
final List<HeaderFile> badFiles = <HeaderFile>[]; | ||
for (final io.File file in files) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be split into a generator too, then you don't have all of these continue
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
/// Returns the expected header guard for this file, relative to [engineRoot]. | ||
/// | ||
/// For example, if the file is `foo/bar/baz.h`, this will return `FLUTTER_FOO_BAR_BAZ_H_`. | ||
String expectedName({required String engineRoot}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a method name should have a verb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
return 'FLUTTER_${underscoredRelativePath.toUpperCase()}_H_'; | ||
} | ||
|
||
/// Updates the file at [path] to have the expected header guard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the return value bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs an entry in https://github.com/flutter/engine/blob/main/testing/run_tests.py#L975 to run the tests on CI.
Done. |
#50069) Generated by #48903 (`dart ./tools/header_guard_check/bin/main.dart --fix`). As discussed with @cbracken and @jmagman, the guards are not technically needed on the Mac/iOS code, but they (a) do not hurt and (b) still provide value if for some reason `#include` is used instead of `#import` (though I suspect we could try to add that to the tool in the future as well).
auto label is removed for flutter/engine/48903, due to - The status or check suite Mac mac_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label. |
final List<String> exclude; | ||
|
||
/// Runs the header guard check. | ||
Future<int> run() async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
auto label is removed for flutter/engine/48903, due to - The status or check suite Linux linux_fuchsia has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…142347) flutter/engine@525bd7d...a65a1b5 2024-01-26 [email protected] Roll Skia from c32aa37effcc to 6279c88b9e29 (1 revision) (flutter/engine#50098) 2024-01-26 [email protected] [Impeller] add compute pass API for memory barriers, re-enable for Vulkan. (flutter/engine#49946) 2024-01-26 [email protected] Introduce a prototype of a "header guard enforcement" tool (flutter/engine#48903) 2024-01-26 [email protected] Roll Skia from e24124912cc3 to c32aa37effcc (1 revision) (flutter/engine#50094) 2024-01-26 [email protected] [web] Do not wipe the PlatformViewManager when disposing of a view. (flutter/engine#49991) 2024-01-26 [email protected] Finish landing missing/incorrect header guards across `flutter/engine` (flutter/engine#50069) 2024-01-26 [email protected] Roll Skia from 32f6bff0f193 to e24124912cc3 (2 revisions) (flutter/engine#50093) 2024-01-26 [email protected] Roll Skia from cbdf09d69efc to 32f6bff0f193 (3 revisions) (flutter/engine#50092) 2024-01-26 [email protected] Roll Dart SDK from 5636e338e0b9 to 7337995bc851 (1 revision) (flutter/engine#50087) 2024-01-26 [email protected] Fix Shell::Screenshot for Impeller (flutter/engine#50072) 2024-01-26 [email protected] Roll Skia from ae73baacb793 to cbdf09d69efc (1 revision) (flutter/engine#50085) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Closes flutter/flutter#133415.
This is a prototype I threw together in about 1-2 hours. It enforces and automatically fixes header guards that don't match the the Google C++ style guide. For example, here is (trimmed) output at HEAD: