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

Commit e708809

Browse files
authored
clangd_check: write .clangd as part of test (#54766)
This eliminates the checked-in `.clangd` file at the root of the engine repository, which gets picked up by editors that rely on `clangd`. In particular, the `Remove: [-m*, -f*]` is problematic for iOS/macOS embedder developers since it removes the `-fobjc-arc` flag, which causes `clangd` to emit errors when using ARC features. Example: Cannot create __weak reference in file using manual reference counting This removes the checked-in file, and instead writes the file before running the test, then cleans it up afterwards. Unfortunately, `clangd` does not appear to have a mechanism to point to a config file elsewhere and run as though it were present in a specified directory. Fixes: flutter/flutter#154064 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 3441fc7 commit e708809

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.clangd

Lines changed: 0 additions & 10 deletions
This file was deleted.

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45158,7 +45158,6 @@ ORIGIN: ../../../flutter/vulkan/vulkan_utilities.h + ../../../flutter/LICENSE
4515845158
ORIGIN: ../../../flutter/vulkan/vulkan_window.cc + ../../../flutter/LICENSE
4515945159
ORIGIN: ../../../flutter/vulkan/vulkan_window.h + ../../../flutter/LICENSE
4516045160
TYPE: LicenseType.bsd
45161-
FILE: ../../../flutter/.clangd
4516245161
FILE: ../../../flutter/.engine-release.version
4516345162
FILE: ../../../flutter/.pylintrc
4516445163
FILE: ../../../flutter/assets/asset_manager.cc

tools/clangd_check/bin/main.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,21 @@ void main(List<String> args) {
106106
return;
107107
}
108108

109-
// Run clangd.
109+
final Engine engineRoot = Engine.findWithin(p.canonicalize(compileCommandsDir));
110+
final io.File clangdConfig = io.File(p.join(engineRoot.flutterDir.path, '.clangd'));
110111
try {
112+
// Write a .clangd file to the engine root directory.
113+
//
114+
// See:
115+
// - https://clangd.llvm.org/config#compileflags
116+
// - https://github.com/clangd/clangd/issues/662
117+
clangdConfig.writeAsStringSync(
118+
'CompileFlags:\n'
119+
' Add: -Wno-unknown-warning-option\n'
120+
' Remove: [-m*, -f*]\n'
121+
);
122+
123+
// Run clangd.
111124
final io.ProcessResult result = io.Process.runSync(clangd, <String>[
112125
'--compile-commands-dir',
113126
compileCommandsDir,
@@ -128,5 +141,8 @@ void main(List<String> args) {
128141
io.stderr.writeln('Failed to run clangd: $e');
129142
io.stderr.writeln(const JsonEncoder.withIndent(' ').convert(entry));
130143
io.exitCode = 1;
144+
} finally {
145+
// Remove the copied .clangd file from the engine root directory.
146+
clangdConfig.deleteSync();
131147
}
132148
}

0 commit comments

Comments
 (0)