clangd_check: write .clangd as part of test (flutter/engine#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: https://github.com/flutter/flutter/issues/154064
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
# Used to allow clangd to run on CI platforms as part of //tools/clangd_check.
|
||||
#
|
||||
# Intended to have no effect elsewhere.
|
||||
#
|
||||
# See also:
|
||||
# - https://clangd.llvm.org/config#compileflags
|
||||
# - https://github.com/clangd/clangd/issues/662
|
||||
CompileFlags:
|
||||
Add: -Wno-unknown-warning-option
|
||||
Remove: [-m*, -f*]
|
||||
@@ -45158,7 +45158,6 @@ ORIGIN: ../../../flutter/vulkan/vulkan_utilities.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/vulkan/vulkan_window.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/vulkan/vulkan_window.h + ../../../flutter/LICENSE
|
||||
TYPE: LicenseType.bsd
|
||||
FILE: ../../../flutter/.clangd
|
||||
FILE: ../../../flutter/.engine-release.version
|
||||
FILE: ../../../flutter/.pylintrc
|
||||
FILE: ../../../flutter/assets/asset_manager.cc
|
||||
|
||||
@@ -106,8 +106,21 @@ void main(List<String> args) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run clangd.
|
||||
final Engine engineRoot = Engine.findWithin(p.canonicalize(compileCommandsDir));
|
||||
final io.File clangdConfig = io.File(p.join(engineRoot.flutterDir.path, '.clangd'));
|
||||
try {
|
||||
// Write a .clangd file to the engine root directory.
|
||||
//
|
||||
// See:
|
||||
// - https://clangd.llvm.org/config#compileflags
|
||||
// - https://github.com/clangd/clangd/issues/662
|
||||
clangdConfig.writeAsStringSync(
|
||||
'CompileFlags:\n'
|
||||
' Add: -Wno-unknown-warning-option\n'
|
||||
' Remove: [-m*, -f*]\n'
|
||||
);
|
||||
|
||||
// Run clangd.
|
||||
final io.ProcessResult result = io.Process.runSync(clangd, <String>[
|
||||
'--compile-commands-dir',
|
||||
compileCommandsDir,
|
||||
@@ -128,5 +141,8 @@ void main(List<String> args) {
|
||||
io.stderr.writeln('Failed to run clangd: $e');
|
||||
io.stderr.writeln(const JsonEncoder.withIndent(' ').convert(entry));
|
||||
io.exitCode = 1;
|
||||
} finally {
|
||||
// Remove the copied .clangd file from the engine root directory.
|
||||
clangdConfig.deleteSync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user