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

clang-tidy: Added an environment variable that allows fix to print the generated diff. #37024

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

gaaclarke
Copy link
Member

This helps with migrating new linter checks that have fixes implemented. Turning this on allows the bots to print out the diff that can be patched locally across all platform CI checks.

issue: flutter/flutter#113848

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.

@gaaclarke gaaclarke force-pushed the linter-print-diff branch 2 times, most recently from 1b32c5d to 08f1f58 Compare October 26, 2022 00:06
# FLUTTER_LINT_PRINT_FIX will make it so that fix is executed and the generated
# diff is printed to stdout if clang-tidy fails. This is helpful for enabling
# new lints.
if [[ -z "${FLUTTER_LINT_PRINT_FIX}" ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using an environment variable, I think it would be simpler to just test for the presence of --fix in $@.

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 did that at first, but that makes it hard to use with the bots since $@ is changed in the bot configuration. This way you can just edit lint.sh file temporarily with FLUTTER_LINT_PRINT_FIX=1

Copy link
Member

Choose a reason for hiding this comment

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

Oh, okay, I get it (I think). So the workflow is to modify the script on a PR branch to get the presubmit checks to generate the diff?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that's the best I could come up with for now. Alternatively we could always execute with --fix but I worry about execution time.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we'd have something like flutter/flutter#114085, to pass the --fix flag only in presubmit. In the meantime, I think this change is okay. Would you mind adding a TODO in the code for me that links to that issue?

Copy link
Member

Choose a reason for hiding this comment

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

We definitely care about postsubmit cycle time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I wouldn't say they have equal weight though. Given that if there is a failure, turning this on and running again takes ~1hr to get results, it might be worth running it always. So the calculus as-to wether this should be turned on always or not should be: (likelihood of violation * 1hr) - ((1 - likelihood of violation) * 5min).

Let me run some tests locally since that 5 minute I just pulled out of my butt. Maybe it isn't so bad to always have it on. Also, maybe the real solution to performance isn't turning off something that is helpful and saves time but to do better sharding. I discuss this in the post-mortem I just sent. Now that I talk about this I think it's better to having this turn on always, assuming it doesn't add a crazy amount of time. I'll measure it.

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 just ran it locally with a diff that was checking 47 files, there was a 12.5% increase in execution time so ~7.5 minutes longer to execute for one that takes ~1 hr.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, here is my suggestion:

  1. We add a new builder that runs only in pre-submit.
  2. It passes the --fix flag
  3. It only runs when .clang-tidy or engine tree source files have changed.

The new builder definition (one example) would looks something like this: #37082

The missing piece is a new parameter to the engine_lint.py recipe to trigger the logic in this PR around the --fix flag, which would go here:

https://flutter.googlesource.com/recipes/+/refs/heads/main/recipes/engine/engine_lint.proto#8

and here

https://flutter.googlesource.com/recipes/+/refs/heads/main/recipes/engine/engine_lint.py#55

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 think we should land this as is for now. This was helpful for me for now. Let's see about turning it on by default if we get feedback from the team that addressing the lints across multiple platforms is a pain. In normal usage this might not be a big deal and more for when migrating new lint flags. Once we land sharding we'll have some more breathing room to do the fix if we want since it is reducing the number of files linted from ~800 to ~600 that should still leave us ahead.

@zanderso
Copy link
Member

Another consideration that I just thought about is that the bots do some caching of the engine checkout to make the setup step for each run go faster. @godofredoc is there anything that could go wrong if a test step modifies the engine source checkout? Presumably, the test step should at least restore the repo to its original state, but is that sufficient?

@godofredoc
Copy link
Contributor

d at least restore the repo to its original state, but is that sufficient?

Another consideration that I just thought about is that the bots do some caching of the engine checkout to make the setup step for each run go faster. @godofredoc is there anything that could go wrong if a test step modifies the engine source checkout? Presumably, the test step should at least restore the repo to its original state, but is that sufficient?

Git caches are maintained in [cache]/git and copied to [cache]/builder/src during the bot_update step. Changes to [cache]/builder/src are discarded at the end of the build execution with no impact to [cache]/git.

The changes that impact git caches are changes to the DEPS file where repositories with different commit histories are cloned using the same name. E.g. changing github.com/flutter/buildroot to github.com/godofredoc/buildroot and using commits that only exist on the godofredo's fork to run presubmits.

@gaaclarke gaaclarke requested a review from zanderso November 7, 2022 22:09
@gaaclarke gaaclarke merged commit e7d7eda into flutter:main Nov 7, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 7, 2022
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 8, 2022
…114855)

* 55ed37fb4 Roll Skia from dec7a930c0b7 to aef6d301c0b5 (4 revisions) (flutter/engine#37393)

* e7d7edab9 clang-tidy: Added an environment variable that allows fix to print the (flutter/engine#37024)
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Nov 9, 2022
schwa423 pushed a commit to schwa423/engine that referenced this pull request Nov 16, 2022
shogohida pushed a commit to shogohida/flutter that referenced this pull request Dec 7, 2022
…lutter#114855)

* 55ed37fb4 Roll Skia from dec7a930c0b7 to aef6d301c0b5 (4 revisions) (flutter/engine#37393)

* e7d7edab9 clang-tidy: Added an environment variable that allows fix to print the (flutter/engine#37024)
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jan 19, 2023
…lutter#114855)

* 55ed37fb4 Roll Skia from dec7a930c0b7 to aef6d301c0b5 (4 revisions) (flutter/engine#37393)

* e7d7edab9 clang-tidy: Added an environment variable that allows fix to print the (flutter/engine#37024)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants