-
Notifications
You must be signed in to change notification settings - Fork 6k
Conversation
c8b15ac
to
0616799
Compare
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 with some nits and suggestions! Mostly just comments about commenting to try to make the script a little less opaque; overall this looks great. The new directory pruning system is definitely a huge improvement, as is the built-in diagnostics (no more having to manually change things and re-run just to have any clue how a specific pattern was fitting in!)
I didn't audit all of the license regexes since I don't think there's any sane way to do all of them in the context of a review.
tools/licenses/lib/filesystem.dart
Outdated
@@ -20,14 +21,14 @@ enum FileType { | |||
tar, // should be parsed as an archive and drilled into | |||
gz, // should be parsed as a single compressed file and exposed | |||
bzip2, // should be parsed as a single compressed file and exposed | |||
metadata, // can be skipped entirely (e.g. Mac OS X ._foo files) | |||
metadata, // can be skipped entirely (e.g. Mac OS X ._foo files, bash scripts) |
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.
Shouldn't bash scripts be their own type with their own handling? I don't think of bash scripts as metadata.
Or maybe this category should just have a different name, like notPartOfBuild
?
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
@@ -390,13 +408,14 @@ mixin Latin1TextFile implements TextFile { | |||
if (isUTF8) { | |||
throw '$fullName contains valid UTF-8 and is probably not actually encoded as Win1252'; | |||
} | |||
return latin1.decode(bytes); | |||
return _normalize(latin1.decode(bytes)); |
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.
Doesn't line 402 need normalizing as well?
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.
if we get past line 402 without throwing, then we discard the results, so there's no need to normalize it.
tools/licenses/lib/formatter.dart
Outdated
|
||
import 'patterns.dart'; | ||
|
||
String reformat(String body) { |
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.
Given the generic name, a documentation comment explaining what exactly this does would be very helpful.
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 this comment:
/// This function takes a block of text potentially decorated with leading
/// prefix indents, horizontal lines, C-style comment blocks, blank lines, etc,
/// and removes all such incidental material leaving only the significant text.
tools/licenses/lib/formatter.dart
Outdated
while (true) { | ||
// Strip full-line decorations, e.g. horizontal lines, and trailing whitespace. | ||
for (int index = 0; index < lines.length; index += 1) { | ||
if (lines[index].endsWith(' ')) { |
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.
Why only space and not other whitespace like tab? Couldn't we just unconditionally trimRight
?
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.
yeah, good point, that test is redundant. removed
tools/licenses/lib/formatter.dart
Outdated
} | ||
while (lines.isNotEmpty && lines.last == '') { | ||
lines.removeLast(); | ||
} |
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.
Wouldn't it be way more efficient for large files to find the first and last non-blank line and then do a single sublist
call?
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 doubt it. in the vast majority of cases this won't find anything; in the few cases where it does it'll probably just remove one line. it'll only rarely remove from the top and bottom.
iirc when i was profiling this i found that basically all the time is spent in regular expression matching for the big patterns, reformat in general is a very minor aspect and the stripping of blank lines is basically not an issue at all.
(also iirc, List.removeLast is O(1) and basically free. I forget how much removeAt(0) costs.)
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.
(also iirc, List.removeLast is O(1) and basically free. I forget how much removeAt(0) costs.)
I was assuming O(n) for head removal, which becomes O(n^2) in pathological cases in the loop, which is why it jumped out at me as a potential issue. But it being a rounding error in actual context makes sense.
License.fromBodyAndType(_dewrap(match.group(14)!), LicenseType.mit, origin: io.fullName), | ||
]; | ||
return result; | ||
static String _fixup(String license) { |
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.
Comment about why this is needed since it seems pretty random?
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.
and yes. ugh. that license.
tools/licenses/lib/paths.dart
Outdated
import 'regexp_debug.dart'; | ||
|
||
final Set<String> skippedPaths = <String>{ | ||
// directories or files that are not included in the final binaries |
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.
These must be full paths relative to the repo root, right? If so that's worth mentioning explicitly.
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 several comments to this file to explain these lists better
tools/licenses/lib/paths.dart
Outdated
}; | ||
|
||
final Set<String> skippedCommonDirectories = <String>{ | ||
// directories that should be skipped anywhere we find them |
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.
Is there a reason you are commenting these inside instead of above? Usually I expect comments describing the whole variable to be the line above, and comments inside the collection to group specific elements.
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.
no particular reason, switched to the other style
final RegExp copyrightMentionPattern = RegExp(r'©| \(c\) (?!{)|copy\s*right\b|copy\s*left', caseSensitive: false); | ||
final RegExp licenseMentionPattern = RegExp(r'license|warrant[iy]', caseSensitive: false); | ||
final RegExp copyrightSanityCheck = RegExp(r'©|copyright|\(c\)', caseSensitive: false); | ||
final RegExp copyrightMentionPattern = RegExp(r'©|copyright [0-9]|\(c\) [0-9]|copyright \(c\)', caseSensitive: false); |
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.
Maybe add comments to distinguish these two from each other?
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 comments for these
}); | ||
test('Indenting blocks', () { | ||
expect(reformat(' a\nb\n c'), 'a\nb\n c'); | ||
expect(reformat(' a\n b\n c'), 'a\nb\nc'); |
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.
Some of these test lines could use comments; I don't know why Adding one space before b
is expected to remove two spaces before c
for instance (same for similar jumps in other tests).
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 comments to all the lines in "Indenting blocks" section.
Feel free to send me any number of small incremental changes to this script any time (hint hint 😉 ) |
Thanks for the review!
Yeah, that'd be preferable in general for sure. Unfortunately these changes were all sort of intertwined and I kept finding more problems that I had to resolve before I could land the previous step and, uh, it sort of got out of control. Sorry. |
Yaks gonna yak :) |
auto label is removed for flutter/engine, pr: 38148, due to - The status or check suite Mac Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label. |
auto label is removed for flutter/engine, pr: 38148, due to - The status or check suite Mac Unopt has failed. Please fix the issues identified (or deflake) before re-applying this label. |
auto label is removed for flutter/engine, pr: 38148, due to - This commit is not mergeable and has conflicts. Please rebase your PR and fix all the conflicts. |
…117148) * df430c4fd Revert "[Impeller] Speculatively attempt to fix Metal PSO construction errors on host targets." (flutter/engine#38292) * 41dd4f5e1 Revert "Revert "[Impeller] Speculatively attempt to fix Metal PSO construction errors on host targets." (#38292)" (flutter/engine#38301) * 8ce9a3f71 Roll Skia from 3171deabd88a to b368746d696a (13 revisions) (flutter/engine#38294) * 4881fe25e Revert "Revert "reland "Migrate darwin common "framework_shared" target to ARC #37049" (#37219)" (#37320)" (flutter/engine#37883) * 3b2302c8d [Impeller] Remove validation log when the pipeline library is collected before pipeline is setup. (flutter/engine#38306) * a04997c81 [Impeller] Disable impeller_unittests. (flutter/engine#38307) * fc71faad0 License script improvements (flutter/engine#38148) * 6a2560c35 [Windows] Synthesize modifier keys events on pointer events (flutter/engine#38138) * b1d407563 Roll Skia from b368746d696a to 3f81f95176ce (11 revisions) (flutter/engine#38312) * b25fcf748 Roll Skia from 3f81f95176ce to 46e8f2a18a3d (3 revisions) (flutter/engine#38314) * 948699bba Collapse bounds calculations into DisplayListBuilder (flutter/engine#34365) * 38367de84 Roll Fuchsia Mac SDK from u-tC0QEGUT4xQ4KOo... to VEOIaacOA75U7PYyz... (flutter/engine#38316) * 29196519c Roll Skia from 46e8f2a18a3d to 9f728d78f10d (1 revision) (flutter/engine#38317)
…lutter#117148) * df430c4fd Revert "[Impeller] Speculatively attempt to fix Metal PSO construction errors on host targets." (flutter/engine#38292) * 41dd4f5e1 Revert "Revert "[Impeller] Speculatively attempt to fix Metal PSO construction errors on host targets." (flutter#38292)" (flutter/engine#38301) * 8ce9a3f71 Roll Skia from 3171deabd88a to b368746d696a (13 revisions) (flutter/engine#38294) * 4881fe25e Revert "Revert "reland "Migrate darwin common "framework_shared" target to ARC flutter#37049" (flutter#37219)" (flutter#37320)" (flutter/engine#37883) * 3b2302c8d [Impeller] Remove validation log when the pipeline library is collected before pipeline is setup. (flutter/engine#38306) * a04997c81 [Impeller] Disable impeller_unittests. (flutter/engine#38307) * fc71faad0 License script improvements (flutter/engine#38148) * 6a2560c35 [Windows] Synthesize modifier keys events on pointer events (flutter/engine#38138) * b1d407563 Roll Skia from b368746d696a to 3f81f95176ce (11 revisions) (flutter/engine#38312) * b25fcf748 Roll Skia from 3f81f95176ce to 46e8f2a18a3d (3 revisions) (flutter/engine#38314) * 948699bba Collapse bounds calculations into DisplayListBuilder (flutter/engine#34365) * 38367de84 Roll Fuchsia Mac SDK from u-tC0QEGUT4xQ4KOo... to VEOIaacOA75U7PYyz... (flutter/engine#38316) * 29196519c Roll Skia from 46e8f2a18a3d to 9f728d78f10d (1 revision) (flutter/engine#38317)
This is a significant revamp of the license script that I've been slowly doing for the past 10+ months so it includes a whole host of things that I'm sure I've forgotten about, but most notably:
--verbose
mode that reports on which RegExp instances were most expensive.paths.dart
rather than a convoluted exercise involving creating a new subclass.This does make the LICENSE file bigger overall (about 10KB compressed), but we may be able to skip shipping the file entirely soon (and download it on demand instead) so I'm not greatly worried about this.
Pre-launch Checklist
///
).