Skip to content

Commit c5e111f

Browse files
authored
Add linting workflow (#27)
1 parent 3def3eb commit c5e111f

File tree

24 files changed

+939
-711
lines changed

24 files changed

+939
-711
lines changed

.github/workflows/lint-format.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Lint and Format
2+
3+
on:
4+
# Run on pushes to main and pushed tags, and on pull requests against main
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
validation:
18+
name: "Validation"
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: gradle/actions/wrapper-validation@v4
23+
wpiformat:
24+
name: "wpiformat"
25+
runs-on: ubuntu-22.04
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Fetch all history and metadata
29+
run: |
30+
git fetch --prune --unshallow
31+
git checkout -b pr
32+
git branch -f main origin/main
33+
- name: Set up Python 3.13
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: 3.13
37+
- name: Install wpiformat
38+
run: pip3 install wpiformat==2025.33
39+
- name: Run
40+
run: wpiformat
41+
- name: Check output
42+
run: git --no-pager diff --exit-code HEAD
43+
- name: Generate diff
44+
run: git diff HEAD > wpiformat-fixes.patch
45+
if: ${{ failure() }}
46+
- uses: actions/upload-artifact@v4
47+
with:
48+
name: wpiformat fixes
49+
path: wpiformat-fixes.patch
50+
if: ${{ failure() }}
51+
javaformat:
52+
name: "Java Formatting"
53+
needs: [validation]
54+
runs-on: ubuntu-22.04
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
- uses: actions/setup-java@v4
60+
with:
61+
java-version: 17
62+
distribution: temurin
63+
- run: ./gradlew spotlessCheck
64+
name: Run spotless

.styleguide

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ modifiableFileExclude {
1818
\.dll$
1919
\.webp$
2020
\.ico$
21+
\.rknn$
2122
gradlew
23+
3rdparty*
24+
rknn_api.h
2225
}
2326

2427
includeProject {

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
}
1515
],
1616
"version": 4
17-
}
17+
}

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929
]
3030
},
31-
31+
3232

3333
{
3434
"type": "java",
@@ -37,12 +37,12 @@
3737
"hostName": "localhost",
3838
"port": "5005"
3939
},
40-
40+
4141
{
4242
"type": "java",
4343
"name": "Current File",
4444
"request": "launch",
4545
"mainClass": "${file}"
4646
}
4747
]
48-
}
48+
}

CMakeLists.txt

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ set(CMAKE_CXX_STANDARD 14)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_FLAGS "-pthread")
88

9-
if (ENABLE_ASAN)
10-
message(STATUS "BUILD WITH ADDRESS SANITIZER")
11-
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
12-
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
13-
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined")
14-
endif ()
9+
if(ENABLE_ASAN)
10+
message(STATUS "BUILD WITH ADDRESS SANITIZER")
11+
set(CMAKE_C_FLAGS_DEBUG
12+
"${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined"
13+
)
14+
set(CMAKE_CXX_FLAGS_DEBUG
15+
"${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined"
16+
)
17+
set(CMAKE_LINKER_FLAGS_DEBUG
18+
"${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined"
19+
)
20+
endif()
1521

1622
set(BUILD_SHARED_LIBS ON)
1723

@@ -23,7 +29,9 @@ if(JNI_FOUND)
2329
endif()
2430

2531
# skip 3rd-party lib dependencies
26-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined")
32+
set(CMAKE_EXE_LINKER_FLAGS
33+
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined"
34+
)
2735

2836
# rknn api
2937
set(RKNN_RT_LIB ${CMAKE_SOURCE_DIR}/src/main/native/lib/librknnrt.so)
@@ -33,7 +41,6 @@ set(LIB_ARCH aarch64)
3341
set(RGA_PATH ${CMAKE_SOURCE_DIR}/src/main/native/lib/3rdparty/rga/RK3588)
3442
set(RGA_LIB ${RGA_PATH}/lib/Linux/${LIB_ARCH}/librga.so)
3543

36-
3744
set(OPENCV_YEAR "frc2025")
3845
set(OPENCV_VERSION "4.10.0-3")
3946
# also valid: windowsx86-64
@@ -43,64 +50,63 @@ set(OPENCV_TYPE "")
4350

4451
# Download opencv, and save the path
4552
include(FetchContent)
46-
FetchContent_Declare(
53+
fetchcontent_declare(
4754
opencv_lib
48-
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-${OPENCV_ARCH}${OPENCV_TYPE}.zip
55+
URL
56+
https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-${OPENCV_ARCH}${OPENCV_TYPE}.zip
4957
)
50-
FetchContent_MakeAvailable(opencv_lib)
58+
fetchcontent_makeavailable(opencv_lib)
5159

5260
# download OpenCV headers
53-
FetchContent_Declare(
61+
fetchcontent_declare(
5462
opencv_header
55-
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip
63+
URL
64+
https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip
5665
)
57-
FetchContent_MakeAvailable(opencv_header)
66+
fetchcontent_makeavailable(opencv_header)
5867

5968
# This probably doesn't work great with shared libraries, but I don't care about those right now
60-
file(GLOB_RECURSE OPENCV_LIB_PATH
61-
"${opencv_lib_SOURCE_DIR}/**/*.lib"
62-
"${opencv_lib_SOURCE_DIR}/**/*.so*"
69+
file(
70+
GLOB_RECURSE OPENCV_LIB_PATH
71+
"${opencv_lib_SOURCE_DIR}/**/*.lib"
72+
"${opencv_lib_SOURCE_DIR}/**/*.so*"
6373
)
64-
SET(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
74+
set(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
6575
message("Depending on opencv ${OPENCV_LIB_PATH}")
6676

67-
6877
set(CMAKE_INSTALL_RPATH "lib")
6978

7079
set(THREADS_PREFER_PTHREAD_FLAG ON)
7180
find_package(Threads REQUIRED)
7281

73-
add_library(${PROJECT_NAME}
82+
add_library(
83+
${PROJECT_NAME}
7484
src/main/native/cpp/rknn_jni.cpp
7585
src/main/native/cpp/yolo_common.cpp
7686
src/main/native/cpp/preprocess.cc
7787
src/main/native/cpp/postprocess_v5.cc
7888
src/main/native/cpp/postprocess_v8_11.cc
7989
)
8090

81-
82-
target_link_libraries(${PROJECT_NAME} PUBLIC
83-
Threads::Threads
84-
${RKNN_RT_LIB}
85-
${OPENCV_LIB_PATH}
86-
${RGA_LIB}
87-
)
88-
89-
target_include_directories(${PROJECT_NAME} PRIVATE
90-
${CMAKE_CURRENT_SOURCE_DIR}
91-
${LIBRKNNRT_INCLUDES}
92-
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include
93-
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include/model_zoo
94-
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include/3rdparty/rga/RK3588/include
95-
${JNI_INCLUDE_DIRS}
96-
${OPENCV_INCLUDE_PATH}
91+
target_link_libraries(
92+
${PROJECT_NAME}
93+
PUBLIC Threads::Threads ${RKNN_RT_LIB} ${OPENCV_LIB_PATH} ${RGA_LIB}
9794
)
9895

99-
set_target_properties(${PROJECT_NAME}
100-
PROPERTIES
101-
INSTALL_RPATH "\\\$ORIGIN/"
96+
target_include_directories(
97+
${PROJECT_NAME}
98+
PRIVATE
99+
${CMAKE_CURRENT_SOURCE_DIR}
100+
${LIBRKNNRT_INCLUDES}
101+
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include
102+
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include/model_zoo
103+
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include/3rdparty/rga/RK3588/include
104+
${JNI_INCLUDE_DIRS}
105+
${OPENCV_INCLUDE_PATH}
102106
)
103107

108+
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "\\\$ORIGIN/")
109+
104110
include(GNUInstallDirs)
105111
install(TARGETS ${PROJECT_NAME})
106112
install(FILES ${RKNN_RT_LIB} ${RGA_LIB} TYPE LIB)
@@ -109,8 +115,10 @@ message("RGA is ${RGA_LIB}")
109115

110116
add_executable(main_test src/main/native/cpp/main_test.cc)
111117
target_link_libraries(main_test ${PROJECT_NAME} ${RGA_LIB})
112-
target_include_directories(main_test PRIVATE
113-
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include
114-
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include/model_zoo
115-
${OPENCV_INCLUDE_PATH}
118+
target_include_directories(
119+
main_test
120+
PRIVATE
121+
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include
122+
${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include/model_zoo
123+
${OPENCV_INCLUDE_PATH}
116124
)

build.gradle

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ tasks.register('copyNativeLibrary', Sync) {
8585

8686
// And flatten, since windows is stupid
8787
eachFile {
88-
println "Copying shared lib: $name"
89-
path = name
88+
println "Copying shared lib: $name"
89+
path = name
9090
}
9191
includeEmptyDirs = false
9292

@@ -101,6 +101,41 @@ def nativeTasks = wpilibTools.createExtractionTasks {
101101
configurationName = nativeConfigName
102102
}
103103

104+
spotless {
105+
java {
106+
target fileTree('.') {
107+
include '**/*.java'
108+
exclude '**/build/**', '**/build-*/**', '**/src/generated/**'
109+
}
110+
toggleOffOn()
111+
googleJavaFormat()
112+
indentWithTabs(2)
113+
indentWithSpaces(4)
114+
removeUnusedImports()
115+
trimTrailingWhitespace()
116+
endWithNewline()
117+
}
118+
groovyGradle {
119+
target fileTree('.') {
120+
include '**/*.gradle'
121+
exclude '**/build/**', '**/build-*/**'
122+
}
123+
greclipse()
124+
indentWithSpaces(4)
125+
trimTrailingWhitespace()
126+
endWithNewline()
127+
}
128+
format 'misc', {
129+
target fileTree('.') {
130+
include '**/*.md', '**/.gitignore'
131+
exclude '**/build/**', '**/build-*/**'
132+
}
133+
trimTrailingWhitespace()
134+
indentWithSpaces(2)
135+
endWithNewline()
136+
}
137+
}
138+
104139
nativeTasks.addToSourceSetResources(sourceSets.test)
105140

106141
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet")

0 commit comments

Comments
 (0)