From d49826f5d2d1363cc3628b65523dae52531b1456 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 26 Aug 2024 10:16:20 -0700 Subject: [PATCH] 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 --- engine/src/flutter/.clangd | 10 ---------- .../ci/licenses_golden/licenses_flutter | 1 - .../flutter/tools/clangd_check/bin/main.dart | 18 +++++++++++++++++- 3 files changed, 17 insertions(+), 12 deletions(-) delete mode 100644 engine/src/flutter/.clangd diff --git a/engine/src/flutter/.clangd b/engine/src/flutter/.clangd deleted file mode 100644 index c36b4792d7..0000000000 --- a/engine/src/flutter/.clangd +++ /dev/null @@ -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*] diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index ba18f9549f..e3bba96226 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/engine/src/flutter/tools/clangd_check/bin/main.dart b/engine/src/flutter/tools/clangd_check/bin/main.dart index d2e19dbb5c..d5badb009d 100644 --- a/engine/src/flutter/tools/clangd_check/bin/main.dart +++ b/engine/src/flutter/tools/clangd_check/bin/main.dart @@ -106,8 +106,21 @@ void main(List 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, [ '--compile-commands-dir', compileCommandsDir, @@ -128,5 +141,8 @@ void main(List 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(); } }