forked from microsoft/react-native-macos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add macro to detect circular dependencies on Cmake
Summary: This is a prototype to add circular dependencies detection on CMake for ReactCommon and ReactAndroid. It can be enabled per module and works as follows: ``` set(ALLOWED_HEADER_IMPORT_PATHS react/renderer/graphics react/debug) check_for_circular_dependencies("${ALLOWED_HEADER_IMPORT_PATHS}") ``` The allowed header import path must be manually specified as libraries are exposing wrong header search paths (so can't be reused). The CI will be red till the circular dependency on `graphics` is resolved. Changelog: [Internal] [Changed] - Add macro to detect circular dependencies on Cmake Reviewed By: cipolleschi Differential Revision: D42927036 fbshipit-source-id: b1393dfd43fd042e2ebf1d5b46b24bd9f5e20d58
- Loading branch information
1 parent
37171ec
commit 147a1f6
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
|
||
# Util function that help us verify that you're not including a header file | ||
# which has an invalid import path. Most of the time this is causing a C++ circular dependency. | ||
function(check_for_circular_dependencies allowed_imports_paths) | ||
file(GLOB headers CONFIGURE_DEPENDS *.h) | ||
foreach(file ${headers}) | ||
file(STRINGS ${file} header_file) | ||
while(header_file) | ||
list(POP_FRONT header_file line) | ||
if (line MATCHES "^#include <react") | ||
set(matched_import false) | ||
foreach(allowed_import ${allowed_imports_paths}) | ||
if (line MATCHES "^#include <${allowed_import}") | ||
set(matched_import true) | ||
continue() | ||
endif() | ||
endforeach() | ||
if (NOT matched_import) | ||
message(FATAL_ERROR "!!!!!\nDiscovered an invalid include on file\n${file}\nfor include\n${line}\n") | ||
break() | ||
endif() | ||
endif() | ||
endwhile() | ||
endforeach() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters