Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@mit-mit
Copy link
Member

@mit-mit mit-mit commented Sep 2, 2022

Migrate src/flutter/tools/licenses to null safety.

Contributes to flutter/flutter#110020

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@mit-mit mit-mit changed the title Migrate tools/licenses to null safety [WIP] Migrate tools/licenses to null safety Sep 2, 2022
@zanderso zanderso added the Work in progress (WIP) Not ready (yet) for review! label Sep 8, 2022
@zanderso
Copy link
Member

zanderso commented Sep 8, 2022

From PR triage: Adding the WIP label.

@mit-mit mit-mit changed the title [WIP] Migrate tools/licenses to null safety Migrate tools/licenses to null safety Sep 12, 2022
@mit-mit
Copy link
Member Author

mit-mit commented Sep 12, 2022

I believe this is ready for a review.

There is one test failure, but I'm a bit puzzled as I don't think I changed anything in the logic of _findLicenseBlocks.

And the test output actually looks legit; it's triggered by the file third_party/libjpeg-turbo/simd/jsimd_mips_dspr2.S that has several copyright statements... @Hixie @goderbauer looks you both worked on this tool, so wondering if you can comment if that failure is actually valid?

@Hixie
Copy link
Contributor

Hixie commented Sep 12, 2022

There is one test failure, but I'm a bit puzzled as I don't think I changed anything in the logic of _findLicenseBlocks.

Looking at the goldens, it seems we used to do this one correctly, so something in this patch must have affected it...

final _RepositorySourceFile main = parent.getChildByName('turbojpeg.c') as _RepositorySourceFile;
final _RepositoryDirectory simd = parent.getChildByName('simd') as _RepositoryDirectory;
List<License>? get licenses {
if (_licenses == null && parent != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the && parent != null should not be necessary

Copy link
Member Author

@mit-mit mit-mit Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

I'm a bit puzzled why that works given parent is nullable. I guess there is an invariant that get isn't called when parent is null?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the root case is special in various ways such that the code never gets called when parent is null.

This code was designed for a nullable world. I would write it quite differently now with null safety.

Comment on lines 650 to 658
bool hadMoreLines;
while (hadMoreLines = lines.moveNext() && lines.current.value.startsWith(prefix)) {
final String nextAuthor = lines.current.value.substring(prefix.length);
if (nextAuthor == '' || nextAuthor[0] == ' ' || nextAuthor[0] == '\t') {
throw 'unexpectedly ragged author list when looking for copyright';
}
end = lines.current.end;
}
if (lines.current == null) {
if (!hadMoreLines) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if this is somehow not 100% exactly semantically equivalent and is causing the bug you ran into

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was missing a set of parenthesis :-)

-      while (hadMoreLines = lines.moveNext() && lines.current.value.startsWith(prefix)) {
+      while ((hadMoreLines = lines.moveNext()) && lines.current.value.startsWith(prefix)) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha, glad i pinned down the section if not the reason :-)

@mit-mit
Copy link
Member Author

mit-mit commented Sep 13, 2022

@mit-mit
Copy link
Member Author

mit-mit commented Sep 13, 2022

Golden updated:

mit@mit-gbuntu:~/dev/flutter_engine/src/flutter/tools/licenses$ rm -rf ../../../out/licenses
dart lib/main.dart --src ../../.. --out ../../../out/licenses --golden ../../ci/licenses_golden
Finding files...

Computing signature for license tool
    Detected changes to license tool. Forcing license collection for all components.
Collecting licenses for flutter
      2918 of 2918 ██████████ 100% (0 missing licenses)  Done.
Collecting licenses for fuchsia
      1831 of 1831 ██████████ 100% (0 missing licenses)  Done.
Collecting licenses for gpu
         2 of 2 ██████████ 100% (0 missing licenses)  Done.
Collecting licenses for third_party
     11611 of 11611 ██████████ 100% (0 missing licenses)  Done.
Collecting licenses for skia
      5296 of 5296 ██████████ 100% (0 missing licenses)  Done.
mit@mit-gbuntu:~/dev/flutter_engine/src/flutter/tools/licenses$
mit@mit-gbuntu:~/dev/flutter_engine/src/flutter/tools/licenses$ cp ../../../out/licenses/* ../../ci/licenses_golden
git diff
diff --git a/ci/licenses_golden/tool_signature b/ci/licenses_golden/tool_signature
index 74aacad982..6ae74cafe6 100644
--- a/ci/licenses_golden/tool_signature
+++ b/ci/licenses_golden/tool_signature
@@ -1,2 +1,2 @@
-Signature: d232ec47cb6d61b7385bf1ef936a93c4
+Signature: 647326c44237e255694c24deb9896c68

@mit-mit mit-mit requested a review from Hixie September 13, 2022 14:28
Copy link
Contributor

@Hixie Hixie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Hixie
Copy link
Contributor

Hixie commented Sep 13, 2022

This PR reminds me that I have a big patch (which is going to conflict up the wazoo now, oops! oh well) that was waiting for https://dart-review.googlesource.com/c/sdk/+/250792 to get reviewed and landed, but I was trying to follow the non-Googler path to contributing to Dart and didn't figure out how to get a review and then forgot about it.

@Hixie
Copy link
Contributor

Hixie commented Sep 13, 2022

test-exempt: code refactor with no semantic change

@mit-mit mit-mit merged commit 81bbee8 into flutter:main Sep 14, 2022
@mit-mit mit-mit deleted the nullsafelicenses branch September 14, 2022 08:58
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 14, 2022
Oleh-Sv pushed a commit to Oleh-Sv/engine that referenced this pull request Sep 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs tests Work in progress (WIP) Not ready (yet) for review!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants