Skip to content

Commit b61c72d

Browse files
committed
chore: add cmake formatting and linting (#6811)
## Summary πŸš€ ## Test plan Android linting CI
1 parent 3074a09 commit b61c72d

File tree

6 files changed

+120
-160
lines changed

6 files changed

+120
-160
lines changed

β€Žpackages/react-native-reanimated/android/CMakeLists.txtβ€Ž

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,50 @@ project(Reanimated)
22
cmake_minimum_required(VERSION 3.8)
33

44
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS
6+
ON
7+
CACHE INTERNAL "")
68

79
set(CMAKE_CXX_STANDARD 20)
810

9-
# default CMAKE_CXX_FLAGS: "-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-protector-all"
11+
# default CMAKE_CXX_FLAGS: "-g -DANDROID -fdata-sections -ffunction-sections
12+
# -funwind-tables -fstack-protector-strong -no-canonical-prefixes
13+
# -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-protector-all"
1014
include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
1115
add_compile_options(${folly_FLAGS})
1216

13-
string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREANIMATED_VERSION=${REANIMATED_VERSION} -DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}")
17+
string(
18+
APPEND
19+
CMAKE_CXX_FLAGS
20+
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREANIMATED_VERSION=${REANIMATED_VERSION} -DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}"
21+
)
1422

15-
string(APPEND CMAKE_CXX_FLAGS " -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all -std=c++${CMAKE_CXX_STANDARD} -Wall -Werror")
23+
string(
24+
APPEND
25+
CMAKE_CXX_FLAGS
26+
" -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all -std=c++${CMAKE_CXX_STANDARD} -Wall -Werror"
27+
)
1628

1729
if(${IS_NEW_ARCHITECTURE_ENABLED})
18-
string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
30+
string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
1931
endif()
2032

2133
if(${IS_REANIMATED_EXAMPLE_APP})
22-
string(APPEND CMAKE_CXX_FLAGS " -DIS_REANIMATED_EXAMPLE_APP -Wpedantic")
34+
string(APPEND CMAKE_CXX_FLAGS " -DIS_REANIMATED_EXAMPLE_APP -Wpedantic")
2335
endif()
2436

2537
if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
26-
string(APPEND CMAKE_CXX_FLAGS " -DNDEBUG")
38+
string(APPEND CMAKE_CXX_FLAGS " -DNDEBUG")
2739
endif()
2840

2941
if(${JS_RUNTIME} STREQUAL "hermes")
30-
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1")
42+
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1")
3143
elseif(${JS_RUNTIME} STREQUAL "jsc")
32-
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_JSC=1")
44+
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_JSC=1")
3345
elseif(${JS_RUNTIME} STREQUAL "v8")
34-
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_V8=1")
46+
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_V8=1")
3547
else()
36-
message(FATAL_ERROR "Unknown JS runtime ${JS_RUNTIME}.")
48+
message(FATAL_ERROR "Unknown JS runtime ${JS_RUNTIME}.")
3749
endif()
3850

3951
# Resolves "CMake Warning: Manually-specified variables were not used by the
Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,38 @@
11
cmake_minimum_required(VERSION 3.8)
22

3-
file(GLOB_RECURSE REANIMATED_COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR}/reanimated/*.cpp")
4-
file(GLOB_RECURSE REANIMATED_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR}/reanimated/*.cpp")
3+
file(GLOB_RECURSE REANIMATED_COMMON_CPP_SOURCES CONFIGURE_DEPENDS
4+
"${COMMON_CPP_DIR}/reanimated/*.cpp")
5+
file(GLOB_RECURSE REANIMATED_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS
6+
"${ANDROID_CPP_DIR}/reanimated/*.cpp")
57

68
find_package(ReactAndroid REQUIRED CONFIG)
79

8-
add_library(
9-
reanimated
10-
SHARED
11-
${REANIMATED_COMMON_CPP_SOURCES}
12-
${REANIMATED_ANDROID_CPP_SOURCES}
13-
)
10+
add_library(reanimated SHARED ${REANIMATED_COMMON_CPP_SOURCES}
11+
${REANIMATED_ANDROID_CPP_SOURCES})
1412

1513
target_include_directories(
16-
reanimated
17-
PRIVATE
18-
"${COMMON_CPP_DIR}"
19-
"${ANDROID_CPP_DIR}"
20-
"${REACT_NATIVE_DIR}/ReactCommon"
21-
"${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule"
22-
"${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
23-
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor"
24-
)
14+
reanimated
15+
PRIVATE "${COMMON_CPP_DIR}"
16+
"${ANDROID_CPP_DIR}"
17+
"${REACT_NATIVE_DIR}/ReactCommon"
18+
"${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule"
19+
"${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
20+
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor")
2521

2622
if(${IS_NEW_ARCHITECTURE_ENABLED})
27-
target_include_directories(
28-
reanimated
29-
PRIVATE
30-
"${REACT_NATIVE_DIR}/ReactCommon/yoga"
31-
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx"
32-
)
23+
target_include_directories(
24+
reanimated
25+
PRIVATE
26+
"${REACT_NATIVE_DIR}/ReactCommon/yoga"
27+
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx")
3328
endif()
3429

35-
set_target_properties(
36-
reanimated
37-
PROPERTIES
38-
LINKER_LANGUAGE
39-
CXX
40-
)
30+
set_target_properties(reanimated PROPERTIES LINKER_LANGUAGE CXX)
4131

42-
target_link_libraries(
43-
reanimated
44-
worklets
45-
)
32+
target_link_libraries(reanimated worklets)
4633

4734
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
48-
target_link_libraries(
49-
reanimated
50-
ReactAndroid::reactnative
51-
)
35+
target_link_libraries(reanimated ReactAndroid::reactnative)
5236
else()
53-
target_link_libraries(
54-
reanimated
55-
ReactAndroid::react_nativemodule_core
56-
)
37+
target_link_libraries(reanimated ReactAndroid::react_nativemodule_core)
5738
endif()
Lines changed: 55 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,88 @@
11
cmake_minimum_required(VERSION 3.8)
22

3-
file(GLOB_RECURSE WORKLETS_COMMON_CPP_SOURCES CONFIGURE_DEPENDS "${COMMON_CPP_DIR}/worklets/*.cpp")
4-
file(GLOB_RECURSE WORKLETS_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS "${ANDROID_CPP_DIR}/worklets/*.cpp")
3+
file(GLOB_RECURSE WORKLETS_COMMON_CPP_SOURCES CONFIGURE_DEPENDS
4+
"${COMMON_CPP_DIR}/worklets/*.cpp")
5+
file(GLOB_RECURSE WORKLETS_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS
6+
"${ANDROID_CPP_DIR}/worklets/*.cpp")
57

68
# Consume shared libraries and headers from prefabs
79
find_package(fbjni REQUIRED CONFIG)
810
find_package(ReactAndroid REQUIRED CONFIG)
911

1012
if(${JS_RUNTIME} STREQUAL "hermes")
11-
find_package(hermes-engine REQUIRED CONFIG)
13+
find_package(hermes-engine REQUIRED CONFIG)
1214
endif()
1315

14-
add_library(
15-
worklets
16-
SHARED
17-
${WORKLETS_COMMON_CPP_SOURCES}
18-
${WORKLETS_ANDROID_CPP_SOURCES}
19-
)
16+
add_library(worklets SHARED ${WORKLETS_COMMON_CPP_SOURCES}
17+
${WORKLETS_ANDROID_CPP_SOURCES})
2018

2119
# includes
22-
target_include_directories(
23-
worklets
24-
PUBLIC
25-
"${COMMON_CPP_DIR}"
26-
"${ANDROID_CPP_DIR}"
27-
)
20+
target_include_directories(worklets PUBLIC "${COMMON_CPP_DIR}"
21+
"${ANDROID_CPP_DIR}")
2822

2923
target_include_directories(
30-
worklets
31-
PRIVATE
32-
"${REACT_NATIVE_DIR}/ReactCommon"
33-
"${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule"
34-
"${REACT_NATIVE_DIR}/ReactCommon/react/nativemodule/core/ReactCommon"
35-
"${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
36-
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor"
37-
)
24+
worklets
25+
PRIVATE "${REACT_NATIVE_DIR}/ReactCommon"
26+
"${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule"
27+
"${REACT_NATIVE_DIR}/ReactCommon/react/nativemodule/core/ReactCommon"
28+
"${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
29+
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor")
3830

3931
if(${IS_NEW_ARCHITECTURE_ENABLED})
40-
target_include_directories(
41-
worklets
42-
PRIVATE
43-
"${REACT_NATIVE_DIR}/ReactCommon/yoga"
44-
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx"
45-
)
32+
target_include_directories(
33+
worklets
34+
PRIVATE
35+
"${REACT_NATIVE_DIR}/ReactCommon/yoga"
36+
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx")
4637

47-
if(ReactAndroid_VERSION_MINOR LESS 76)
48-
target_link_libraries(
49-
worklets
50-
ReactAndroid::fabricjni
51-
ReactAndroid::react_debug
52-
ReactAndroid::react_render_core
53-
ReactAndroid::react_render_componentregistry
54-
ReactAndroid::rrc_view
55-
)
56-
endif()
38+
if(ReactAndroid_VERSION_MINOR LESS 76)
39+
target_link_libraries(
40+
worklets ReactAndroid::fabricjni ReactAndroid::react_debug
41+
ReactAndroid::react_render_core
42+
ReactAndroid::react_render_componentregistry ReactAndroid::rrc_view)
43+
endif()
5744
endif()
5845

5946
# build shared lib
60-
set_target_properties(
61-
worklets
62-
PROPERTIES
63-
LINKER_LANGUAGE
64-
CXX
65-
)
47+
set_target_properties(worklets PROPERTIES LINKER_LANGUAGE CXX)
6648

67-
target_link_libraries(
68-
worklets
69-
log
70-
ReactAndroid::jsi
71-
fbjni::fbjni
72-
)
49+
target_link_libraries(worklets log ReactAndroid::jsi fbjni::fbjni)
7350

7451
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
75-
target_link_libraries(
76-
worklets
77-
ReactAndroid::reactnative
78-
)
52+
target_link_libraries(worklets ReactAndroid::reactnative)
7953
else()
80-
target_link_libraries(
81-
worklets
82-
ReactAndroid::react_nativemodule_core
83-
ReactAndroid::folly_runtime
84-
ReactAndroid::glog
85-
ReactAndroid::reactnativejni
86-
)
54+
target_link_libraries(
55+
worklets ReactAndroid::react_nativemodule_core ReactAndroid::folly_runtime
56+
ReactAndroid::glog ReactAndroid::reactnativejni)
8757
endif()
8858

8959
if(${JS_RUNTIME} STREQUAL "hermes")
90-
target_link_libraries(
91-
worklets
92-
hermes-engine::libhermes
93-
)
60+
target_link_libraries(worklets hermes-engine::libhermes)
9461

95-
if(${HERMES_ENABLE_DEBUGGER})
96-
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
97-
target_link_libraries(
98-
worklets
99-
ReactAndroid::hermestooling
100-
)
101-
else()
102-
target_link_libraries(
103-
worklets
104-
ReactAndroid::hermes_executor
105-
)
106-
endif()
107-
endif()
108-
elseif(${JS_RUNTIME} STREQUAL "jsc")
62+
if(${HERMES_ENABLE_DEBUGGER})
10963
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
110-
target_link_libraries(
111-
worklets
112-
ReactAndroid::jsctooling
113-
)
64+
target_link_libraries(worklets ReactAndroid::hermestooling)
11465
else()
115-
target_link_libraries(
116-
worklets
117-
ReactAndroid::jscexecutor
118-
)
66+
target_link_libraries(worklets ReactAndroid::hermes_executor)
11967
endif()
68+
endif()
69+
elseif(${JS_RUNTIME} STREQUAL "jsc")
70+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
71+
target_link_libraries(worklets ReactAndroid::jsctooling)
72+
else()
73+
target_link_libraries(worklets ReactAndroid::jscexecutor)
74+
endif()
12075
elseif(${JS_RUNTIME} STREQUAL "v8")
121-
# TODO: Refactor this when adding support for newest V8
122-
target_include_directories(
123-
worklets
124-
PRIVATE
125-
"${JS_RUNTIME_DIR}/src"
126-
)
127-
file(GLOB V8_SO_DIR "${JS_RUNTIME_DIR}/android/build/intermediates/library_jni/**/jni/${ANDROID_ABI}")
128-
find_library(
129-
V8EXECUTOR_LIB
130-
v8executor
131-
PATHS ${V8_SO_DIR}
132-
NO_DEFAULT_PATH
133-
NO_CMAKE_FIND_ROOT_PATH
134-
)
135-
target_link_libraries(
136-
worklets
137-
${V8EXECUTOR_LIB}
138-
)
76+
# TODO: Refactor this when adding support for newest V8
77+
target_include_directories(worklets PRIVATE "${JS_RUNTIME_DIR}/src")
78+
file(
79+
GLOB
80+
V8_SO_DIR
81+
"${JS_RUNTIME_DIR}/android/build/intermediates/library_jni/**/jni/${ANDROID_ABI}"
82+
)
83+
find_library(
84+
V8EXECUTOR_LIB v8executor
85+
PATHS ${V8_SO_DIR}
86+
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
87+
target_link_libraries(worklets ${V8EXECUTOR_LIB})
13988
endif()

β€Žpackages/react-native-reanimated/package.jsonβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
"lint": "yarn lint:js && yarn lint:plugin && yarn lint:common && yarn lint:android && yarn lint:apple",
88
"lint:js": "eslint --ext '.js,.ts,.tsx' src __tests__ __typetests__ && yarn prettier --check src __tests__ __typetests__",
99
"lint:plugin": "cd plugin && yarn lint",
10-
"lint:android": "./scripts/validate-android.sh && ./android/gradlew -p android spotlessCheck -q && ./scripts/cpplint.sh android/src && yarn format:android:cpp --dry-run -Werror",
10+
"lint:android": "./scripts/validate-android.sh && ./android/gradlew -p android spotlessCheck -q && ./scripts/cpplint.sh android/src && yarn format:android:cpp --dry-run -Werror && yarn lint:cmake",
1111
"lint:common": "./scripts/validate-common.sh && ./scripts/cpplint.sh Common && yarn format:common --dry-run -Werror",
1212
"lint:apple": "./scripts/validate-apple.sh && yarn format:apple --dry-run -Werror",
13-
"format": "yarn format:js && yarn format:plugin && yarn format:apple && yarn format:android:java && yarn format:android:cpp && yarn format:common",
13+
"lint:cmake": "find ./android -type d \\( -name build -o -name .cxx \\) -prune -o -type f -name 'CMakeLists.txt' -print | xargs ./scripts/lint-cmake.sh",
14+
"format": "yarn format:js && yarn format:plugin && yarn format:apple && yarn format:android:java && yarn format:android:cpp && yarn format:android:cmake && yarn format:common",
1415
"format:js": "prettier --write --list-different src __tests__ __typetests__",
1516
"format:plugin": "cd plugin && yarn format",
1617
"format:apple": "find apple -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.mm\" -o -iname \"*.cpp\" | xargs clang-format -i",
1718
"format:android:java": "node ./scripts/format-java.js",
1819
"format:android:cpp": "find android/src -iname \"*.h\" -o -iname \"*.cpp\" | xargs clang-format -i",
20+
"format:android:cmake": "find ./android -type d \\( -name build -o -name .cxx \\) -prune -o -type f -name 'CMakeLists.txt' -print | xargs ./scripts/format-cmake.sh",
1921
"format:common": "find Common -iname \"*.h\" -o -iname \"*.cpp\" | xargs clang-format -i",
2022
"find-unused-code:js": "yarn ts-prune --ignore \"index|.web.\" --error",
2123
"type:check": "yarn type:check:src && yarn type:check:plugin && ./scripts/test-ts.sh ../../apps/common-app/src/App.tsx __typetests__/common",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if ! which cmake-format >/dev/null; then
4+
echo "error: cmake-format is not installed"
5+
exit 1
6+
fi
7+
8+
cmake-format -i "$@"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if ! which cmake-lint >/dev/null; then
4+
echo "error: cmake-lint is not installed"
5+
exit 1
6+
fi
7+
8+
cmake-lint "$@"

0 commit comments

Comments
Β (0)