From 4f7ae6dde87a57d25e3b86e5453fe73e01ea1a43 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 25 Aug 2024 11:56:27 -0700 Subject: [PATCH] clangd_check: write .clangd as part of test 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 --- .clangd | 10 ---------- ci/licenses_golden/licenses_flutter | 1 - tools/clangd_check/bin/main.dart | 18 +++++++++++++++++- 3 files changed, 17 insertions(+), 12 deletions(-) delete mode 100644 .clangd diff --git a/.clangd b/.clangd deleted file mode 100644 index c36b4792d750c..0000000000000 --- a/.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/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 1f2f795bef59c..8cee3d263b758 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -45160,7 +45160,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/tools/clangd_check/bin/main.dart b/tools/clangd_check/bin/main.dart index d2e19dbb5c7dd..d5badb009dc34 100644 --- a/tools/clangd_check/bin/main.dart +++ b/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(); } }