8000 [pigeon] Deduces the package name for dart test file imports. by gaaclarke · Pull Request #2467 · flutter/packages · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pigeon] Deduces the package name for dart test file imports. #2467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 22, 2022

Conversation

gaaclarke
Copy link
Member

fixes flutter/flutter#97744

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 relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@gaaclarke gaaclarke force-pushed the pigeon-deduce-package-name branch 7 times, most recently from cd4e44d to ebebcd8 Compare August 16, 2022 00:10
@gaaclarke gaaclarke marked this pull request as ready for review August 16, 2022 00:11
@gaaclarke gaaclarke force-pushed the pigeon-deduce-package-name branch from ebebcd8 to 77a01d9 Compare August 16, 2022 21:46
}

final String text = File(pubspecPath).readAsStringSync();
final RegExp nameFinder = RegExp(r'^name:\s*(.*)');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use https://pub.dev/packages/yaml to extract this robustly. This won't handle all valid YAML correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

return match.group(1);
}

String _posixify(String input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This definitely needs a comment. input is very vague—in fact, nothing about this function signature indicates its about paths at all—and the fact that this would convert a relative path to an absolute path is non-obvious.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

'import \'${_escapeForDartSingleQuotedString(relativeDartPath)}\';');
} else {
final String path = relativeDartPath.replaceFirstMapped(
RegExp(r'.*/lib/(.*?)'), (Match match) => match.group(1).toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't (.*?) always be empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

You know what, you might be right in theory. In practice it's doing the (relatively) correct operation. It's asserted to work in the unit test. It's almost like there is an implied $ at the end of the regex for some reason. I added explicit ^ and $ characters to avoid confusion. I'll file a dart bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's a Dart bug here, what you wrote is just a weird way of writing an empty replacement. Replacing .*/lib/(.*)$ with '$1' and replacing .*/lib/ with '' are the same thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yea, weird, I see now. Funny how that worked out.

@gaaclarke gaaclarke force-pushed the pigeon-deduce-package-name branch from c4cd52e to 31ee52f Compare August 22, 2022 17:29
@gaaclarke gaaclarke force-pushed the pigeon-deduce-package-name branch from 31ee52f to a923dfc Compare August 22, 2022 17:35
'import \'${_escapeForDartSingleQuotedString(relativeDartPath)}\';');
} else {
final String path = relativeDartPath.replaceFirstMapped(
RegExp(r'^.*/lib/(.*?)$'), (Match match) => match.group(1).toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

This still seems like a really complicated way of writing it. Why not just replaceFirst(RegExp(r'^.*/lib/'), '')

Copy link
Member Author

Choose a reason for hiding this comment

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

That should work. It's a different way than I was looking at it. Done.

Copy link
Contributor
@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@gaaclarke gaaclarke merged commit eb15788 into flutter:main Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pigeon] convert relative paths to URIs in dart test out
2 participants
0