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

Conversation

@zanderso
Copy link
Member

@zanderso zanderso commented Jun 11, 2021

This PR adds a pre-push git hook that runs the checks under ci/lint.sh and ci/format.sh. On my machine the hook adds about 5 seconds to a git push. I should be able to speed that up after refactoring ci/bin/lint.dart and ci/bin/format.dart as proper Dart packages and depending on them directly as libraries. (Then we can add more checks).

@zanderso zanderso added the Work in progress (WIP) Not ready (yet) for review! label Jun 11, 2021
@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.

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.

@google-cla google-cla bot added the cla: yes label Jun 11, 2021
@zanderso zanderso force-pushed the git-hooks branch 2 times, most recently from 3c8ef11 to eb2fffa Compare June 11, 2021 15:52
@zanderso zanderso requested a review from dnfield June 11, 2021 18:22
@zanderso zanderso removed the Work in progress (WIP) Not ready (yet) for review! label Jun 11, 2021

SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter')
DART_BIN = os.path.join(SRC_ROOT, 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin')
Copy link
Contributor

Choose a reason for hiding this comment

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

I have vague memories of this causing subtle problems in the past, but I can't quite remember what. Something about versions being slightly off from what people would normally expect to work with, as well as confusion about which Dart binary was actually getting used and for what. @chinmaygarde may remember.

Overall the code in here looks good, but I'm wondering if we're making things overly complicated here - we have gclient invoke a python script, which tells git to invoke a python script, which invokes a Dart program, which invokes some bash scripts that we'll someday refactor to either python or Dart.

Why not just make everything python?

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 have vague memories of this causing subtle problems in the past, but I can't quite remember what. Something about versions being slightly off from what people would normally expect to work with, as well as confusion about which Dart binary was actually getting used and for what. @chinmaygarde may remember.

Git hooks only work with git version >= 2.9. Is that what you mean?

If you mean the prebuilt Dart SDK from CIPD, we already use it pretty consistently to run standalone Dart programs in the tree.

Overall the code in here looks good, but I'm wondering if we're making things overly complicated here - we have gclient invoke a python script, which tells git to invoke a python script, which invokes a Dart program, which invokes some bash scripts that we'll someday refactor to either python or Dart.

It's not quite that bad. To set the git config, gclient sync invokes a python script. Then separately, on a git push, git invokes the python script, which invokes the Dart program (which invokes a shell script, which invokes another Dart program, which invokes e.g. clang-tidy in the linter case.)

The part in parens can be simplified by refactoring the ci/bin/lint.dart and ci/bin/format.dart scripts into proper Dart packages. I've started doing that here: #26722. Then it's just python -> Dart -> clang-tidy. The python part is kind of mandatory due to the need to have a #! at the top for the git hook.

Why not just make everything python?

My first pass at the pre-push hook was python. There were two problems:

  1. I was thinking about how I was going to extend it to analyze only a minimal set of Dart code on changes to .dart files. I found myself reimplementing in python some logic that we already had implemented in Dart in ci/bin/format.dart and ci/bin/lint.dart. So that didn't seem like the right approach.
  2. I was writing a lot of python, and I wanted to be able to lint the code and write tests for it. Currently that's easy in Dart, but we don't have any setup for that for python. We should add it for python, probably, but given (1) it seemed like the right thing was to just use Dart.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concerns weren't about the hooks setting for git, but more about whether we can trust the Dart binary. It's also possible that I'm mixing something up here - I think the problem may have come from trying to invoke Dart directly as a gclient hook (not a git hook). At any rate, if we're using it successfully elsewhere we should be fine.

This change LGTM

@zanderso zanderso merged commit 1890678 into flutter:master Jun 20, 2021
@zanderso zanderso deleted the git-hooks branch June 20, 2021 23:12
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 21, 2021
@hamad22h

This comment was marked as spam.

fluttergithubbot pushed a commit to flutter/flutter that referenced this pull request Jun 21, 2021
wqyfavor pushed a commit to wqyfavor/engine that referenced this pull request Jun 21, 2021
moffatman pushed a commit to moffatman/engine that referenced this pull request Aug 5, 2021
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants