Skip to content

Conversation

@bc-lee
Copy link
Contributor

@bc-lee bc-lee commented Jan 2, 2025

It seems that not all files in the Flutter repository are compatible with clangd. This change improves the clangd invocation in CI to choose files that are known to work with clangd.

Reason for the change:

In #161012, I'm trying to update GN to the latest version. However, this change made the order of files in the compile_commands.json. This caused the clangd check to fail because engine/src/flutter/tools/clangd_check/bin/main.dart currently chooses the first file in the compile_commands.json, and the newly chosen file (engine/src/flutter/third_party/skia/modules/skparagraph/src/Decorations.cpp) is not compatible with clangd. To fix this, I'm making the test choose the file that is known to work with clangd. (gen/flutter/assets/_fl__fl_assets_fixtures.cc)

Pre-launch Checklist

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

@github-actions github-actions bot added the engine flutter/engine related. See also e: labels. label Jan 2, 2025
It seems that not all files in the Flutter repository are compatible with
clangd. This change improves the clangd invocation in CI to choose
files that are known to work with clangd.
@bc-lee bc-lee force-pushed the feature/check-clangd-better-determinism branch from 8570c18 to f09e364 Compare January 2, 2025 23:57
@bc-lee bc-lee marked this pull request as ready for review January 3, 2025 01:08
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me, thanks. LGTM.

@matanlurey matanlurey added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 3, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 3, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Jan 3, 2025

auto label is removed for flutter/flutter/161072, due to This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@matanlurey
Copy link
Contributor

@gaaclarke Can you give this a second look (and LGTM/auto-submit if LGTY)? Thanks!

@matanlurey matanlurey requested a review from gaaclarke January 6, 2025 21:24
for (final Object? entry in compileCommands) {
if (entry is Map<String, Object?>) {
final String? file = entry['file'] as String?;
if (file != null && file.endsWith('_fl__fl_assets_fixtures.cc')) {
Copy link
Member

Choose a reason for hiding this comment

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

This is fragile. What is the compile_commands.json look like for you? Instead can we check that the entry has 'command' 'directory' and 'file' keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are invoking clangd in this code, and previously, we had no verification at all. While adding more verification is a good idea in general, I don't think it's necessary in this case. Here's why:

  1. GN emits directory, file, and command keys, and we are using GN to generate compile_commands.json.
  2. LLVM explicitly emits an error if any of these keys (file, command, or directory) are missing.

I don't think anyone would break such a well-known format. Given this, I believe the current implementation is sufficient, and additional verification would be redundant. Furthermore, we pin all dependencies, including GN and LLVM, so if anything goes wrong, our CI is designed to catch it.

Copy link
Member

Choose a reason for hiding this comment

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

There are 3 assumptions baked into this:

  1. gn's output won't change -- You've mentioned this is unlikely to change, except this changing has predicated this whole PR.
  2. _fl__fl_assets_fixtures.cc continues to be compiled.
  3. No file is added that is sorted before _fl__fl_assets_fixtures.cc.

We should be able to eliminate these, there's no reason to bury a landmine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for raising these points. Let me clarify:

  1. The fields (file, command, directory) in compile_commands.json are specified in the standard and are unlikely to change. Even if something does change, our CI pipeline is designed to detect such issues.
  2. The order of files in compile_commands.json is irrelevant for this implementation because it is an array of objects, and the code explicitly selects the first occurrence of _fl__fl_assets_fixtures.cc. This ensures that file order won't cause issues, which is the primary goal of this PR.
  3. _fl__fl_assets_fixtures.cc was chosen because it has been implicitly used in prior implementations, making it a reasonable default.

That said, if you believe _fl__fl_assets_fixtures.cc is not the best choice, I'd appreciate your suggestions for an alternative file that:

  1. is guaranteed to compile, and
  2. is stable enough to avoid being renamed or removed in the future.

If you don't have a preference, I can switch to using flutter/fml/thread.cc as an alternative, which I believe meets the criteria.

I hope this clarifies things. Let me know if you have additional thoughts!

Copy link
Member

Choose a reason for hiding this comment

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

My recommendation is to not look for any name. If you show me what your compile_commands.json looks like in a gist I can make a recommendation. I am suggesting looking for the entry that has file command and directory instead of looking for something with a specific filename.

Copy link
Contributor Author

@bc-lee bc-lee Jan 7, 2025

Choose a reason for hiding this comment

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

Thank you for your suggestion. Here are two examples of compile_commands.json files generated by GN:

These files differ only in their order but are otherwise identical. Please note that they are approximately 17MB each and can be automatically generated if you're building the Flutter engine from source.

My goal remains the same: to select a file that is stable enough to be tested with clangd, ensuring the test doesn’t block progress. Does this clarify my intention? If not, I’d be happy to elaborate further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, note that the order of entries might vary depending on the operating system, STL, or compiler version used.

Copy link
Member

Choose a reason for hiding this comment

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

Those gist links give me a 404, can you fix them please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

Needs more work. See Aaron's comment.

@bc-lee bc-lee requested review from gaaclarke and matanlurey January 7, 2025 12:54
@chinmaygarde
Copy link
Contributor

@gaaclarke Can you please take another look at the updated gist links please?

@chinmaygarde
Copy link
Contributor

This looks like it is stalled on a resolution to how we should deal with the compile_commands.json format. Is there any guidance on unblocking this since we are stuck on an old version of GN.

@chinmaygarde
Copy link
Contributor

Ping @jonahwilliams

This is blocking the GN roll which is stuck on an ancient version of GN that lacks many debugging tools.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

I think this is a reasonable change for us to unblock gn rolls. We can continue the discssion on the fragility of the clangd check in an issue (if its important).

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Feb 3, 2025

autosubmit label was removed for flutter/flutter/161072, because - The status or check suite Linux linux_fuchsia_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Feb 3, 2025
Merged via the queue into flutter:master with commit b8fd23c Feb 4, 2025
176 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 4, 2025
@bc-lee bc-lee deleted the feature/check-clangd-better-determinism branch February 4, 2025 01:43
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants