diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml new file mode 100644 index 0000000..c122c5d --- /dev/null +++ b/.github/workflows/lint-format.yml @@ -0,0 +1,46 @@ +name: Lint and Format + +on: + # Run on pushes to main and pushed tags, and on pull requests against main + push: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + wpiformat: + name: "wpiformat" + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Fetch all history and metadata + run: | + git fetch --prune --unshallow + git checkout -b pr + git branch -f main origin/main + - uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Install wpiformat + run: pip3 install wpiformat==2025.79 + - name: Run + run: wpiformat + - name: Check output + run: | + set +e + git --no-pager diff --exit-code HEAD + exit_code=$? + if test "$exit_code" -ne "0"; then + echo "::error ::Linting failed. See https://docs.photonvision.org/en/latest/docs/contributing/linting.html" + exit $exit_code + fi + - name: Generate diff + run: git diff HEAD > wpiformat-fixes.patch + if: ${{ failure() }} + - uses: actions/upload-artifact@v4 + with: + name: wpiformat fixes + path: wpiformat-fixes.patch + if: ${{ failure() }} diff --git a/.styleguide b/.wpiformat similarity index 90% rename from .styleguide rename to .wpiformat index ff0e63b..364ed3f 100644 --- a/.styleguide +++ b/.wpiformat @@ -19,6 +19,9 @@ modifiableFileExclude { \.webp$ \.ico$ gradlew + mrcal/ + libdogleg/ + vnlog/ } includeProject { diff --git a/.styleguide-license b/.wpiformat-license similarity index 100% rename from .styleguide-license rename to .wpiformat-license diff --git a/CMakeLists.txt b/CMakeLists.txt index d5bda09..2f7f16b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,10 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set (WITH_ASAN OFF) -if (WITH_ASAN) +set(WITH_ASAN OFF) +if(WITH_ASAN) add_compile_options(-fsanitize=address -g -Wall -fsanitize=undefined) -endif () +endif() # Keep this in sync with build.gradle and with # https://github.com/PhotonVision/photonvision/blob/main/build.gradle @@ -26,23 +26,26 @@ set(OPENCV_TYPE "") include(FetchContent) FetchContent_Declare( opencv_lib - 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 + 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 ) FetchContent_MakeAvailable(opencv_lib) # download OpenCV headers FetchContent_Declare( opencv_header - URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip + URL + https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip ) FetchContent_MakeAvailable(opencv_header) # This probably doesn't work great with shared libraries, but I don't care about those right now -file(GLOB_RECURSE OPENCV_LIB_PATH - "${opencv_lib_SOURCE_DIR}/**/*.lib" - "${opencv_lib_SOURCE_DIR}/**/*.so*" +file( + GLOB_RECURSE OPENCV_LIB_PATH + "${opencv_lib_SOURCE_DIR}/**/*.lib" + "${opencv_lib_SOURCE_DIR}/**/*.so*" ) -SET(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR}) +set(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR}) message("Depending on opencv ${OPENCV_LIB_PATH}") # Openblas/suitesparse/friends @@ -64,13 +67,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Silence OpenBLAS/LAPACK warnings set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") set(BLA_VENDOR OpenBLAS) -fetchcontent_declare( +FetchContent_Declare( BLAS GIT_REPOSITORY https://github.com/OpenMathLib/OpenBLAS.git GIT_TAG v0.3.30 OVERRIDE_FIND_PACKAGE ) -fetchcontent_makeavailable(BLAS) +FetchContent_MakeAvailable(BLAS) if(TARGET openblas) set(OPENBLAS_TARGET openblas) @@ -83,9 +86,10 @@ elseif(TARGET libopenblas) message(STATUS "Using libopenblas target") else() # Fallback: find the library file manually - find_library(OPENBLAS_LIB + find_library( + OPENBLAS_LIB NAMES openblas libopenblas - PATHS + PATHS ${openblas_external_BINARY_DIR} ${openblas_external_BINARY_DIR}/lib ${openblas_external_BINARY_DIR}/lib/Release @@ -94,7 +98,10 @@ else() ) message(STATUS "Using OpenBLAS library file: ${OPENBLAS_LIB}") add_library(openblas_imported STATIC IMPORTED) - set_target_properties(openblas_imported PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB}) + set_target_properties( + openblas_imported + PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB} + ) set(OPENBLAS_TARGET openblas_imported) endif() @@ -107,67 +114,80 @@ set(SUITESPARSE_USE_PYTHON OFF) set(CHOLMOD_GPL OFF) set(SUITESPARSE_USE_BLAS ON) -fetchcontent_declare( +FetchContent_Declare( SuiteSparse GIT_REPOSITORY https://github.com/DrTimothyAldenDavis/SuiteSparse.git GIT_TAG v7.11.0 OVERRIDE_FIND_PACKAGE ) -fetchcontent_makeavailable(SuiteSparse) +FetchContent_MakeAvailable(SuiteSparse) -get_target_property(CHOLMOD_LIBS SuiteSparse::CHOLMOD_static INTERFACE_LINK_LIBRARIES) +get_target_property( + CHOLMOD_LIBS + SuiteSparse::CHOLMOD_static + INTERFACE_LINK_LIBRARIES +) message(STATUS "CHOLMOD links to: ${CHOLMOD_LIBS}") message(STATUS "BLAS is at: ${OPENBLAS_TARGET}") # And pull in JNI find_package(JNI) -if (JNI_FOUND) +if(JNI_FOUND) # Fixes odd AWT dependency - set (JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) - message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}") + set(JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) + message(STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}") endif() # headers and sources -set( - INCLUDE_HPP -) +set(INCLUDE_HPP) -set( - SRC_HPP -) -set( - SRC_CPP +set(SRC_HPP) +set(SRC_CPP src/mrcal_jni.h src/mrcal_wrapper.cpp src/mrcal_jni.cpp libdogleg/dogleg.c - mrcal/mrcal.c mrcal/cahvore.cc mrcal/poseutils-opencv.c mrcal/poseutils-uses-autodiff.cc mrcal/poseutils.c mrcal/poseutils-opencv.c mrcal/mrcal-opencv.c mrcal/triangulation.cc + mrcal/mrcal.c + mrcal/cahvore.cc + mrcal/poseutils-opencv.c + mrcal/poseutils-uses-autodiff.cc + mrcal/poseutils.c + mrcal/poseutils-opencv.c + mrcal/mrcal-opencv.c + mrcal/triangulation.cc ) - # ignore opencv spam # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-deprecated-enum-enum-conversion") - # Gennerate minimath -find_package( Perl REQUIRED ) +find_package(Perl REQUIRED) add_custom_target( - generate_minimath ALL - COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generate.pl > ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h - COMMENT "Generating minimath" + generate_minimath + ALL + COMMAND + ${PERL_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generate.pl > + ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h + COMMENT "Generating minimath" ) -set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # Create shared library add_library(mrcal_jni SHARED ${INCLUDE_HPP} ${SRC_HPP} ${SRC_CPP}) -target_include_directories(mrcal_jni SYSTEM PUBLIC ${JNI_INCLUDE_DIRS} ${OPENCV_INCLUDE_PATH} mrcal libdogleg) +target_include_directories( + mrcal_jni + SYSTEM + PUBLIC ${JNI_INCLUDE_DIRS} ${OPENCV_INCLUDE_PATH} mrcal libdogleg +) add_dependencies(mrcal_jni generate_minimath) -target_link_libraries(mrcal_jni +target_link_libraries( + mrcal_jni ${OPENCV_LIB_PATH} SuiteSparse::CHOLMOD_static SuiteSparse::SuiteSparseConfig_static @@ -178,15 +198,22 @@ target_link_libraries(mrcal_jni # Test script for checking our linker add_executable(mrcal_jni_test src/mrcal_test.cpp) target_link_libraries(mrcal_jni_test PUBLIC mrcal_jni) -target_include_directories(mrcal_jni_test SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/vnlog) +target_include_directories( + mrcal_jni_test + SYSTEM + PRIVATE ${PROJECT_SOURCE_DIR}/vnlog +) # add_dependencies(mrcal_jni_test ) -target_link_libraries(mrcal_jni_test PRIVATE - ${OpenCV_LIBS} - ${PROJECT_SOURCE_DIR}/vnlog/libvnlog.so +target_link_libraries( + mrcal_jni_test + PRIVATE ${OpenCV_LIBS} ${PROJECT_SOURCE_DIR}/vnlog/libvnlog.so ) -if (WITH_ASAN) - target_link_libraries(mrcal_jni_test PRIVATE -fsanitize=address -fsanitize=undefined) -endif () +if(WITH_ASAN) + target_link_libraries( + mrcal_jni_test + PRIVATE -fsanitize=address -fsanitize=undefined + ) +endif() unset(OPENCV_ARCH CACHE) # Set by Actions usually diff --git a/src/mrcal_jni.cpp b/src/mrcal_jni.cpp index 8512168..4ecf150 100644 --- a/src/mrcal_jni.cpp +++ b/src/mrcal_jni.cpp @@ -20,9 +20,11 @@ #include #include #include +#include #include #include #include +#include #include #include "mrcal_wrapper.h" @@ -54,10 +56,12 @@ static constexpr std::string_view JNI_DOUBLE{"D"}; static constexpr std::string_view JNI_DOUBLEARR{"[D"}; static constexpr std::string_view JNI_BOOLARR{"[Z"}; -template -constexpr std::string jni_make_method_sig(std::string_view retval, Args&&... args) { +template +constexpr std::string jni_make_method_sig(std::string_view retval, + Args &&...args) { std::string result = "("; - ((result += std::string_view(args)), ...); // Ensure args are converted to string_view + ((result += std::string_view(args)), + ...); // Ensure args are converted to string_view result += ")"; result += retval; return result; diff --git a/src/mrcal_test.cpp b/src/mrcal_test.cpp index 0c70686..d20ee56 100644 --- a/src/mrcal_test.cpp +++ b/src/mrcal_test.cpp @@ -21,8 +21,11 @@ #include #include #include +#include +#include #include #include +#include #include #include "mrcal_jni.h" diff --git a/src/mrcal_wrapper.cpp b/src/mrcal_wrapper.cpp index 2be5add..3ee40bb 100644 --- a/src/mrcal_wrapper.cpp +++ b/src/mrcal_wrapper.cpp @@ -1,3 +1,20 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + /* * Copyright (C) Photon Vision. * @@ -21,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -338,9 +357,7 @@ mrcal_pose_t getSeedPose(const mrcal_point3_t *c_observations_board_pool, .t = {.x = tvec(0), .y = tvec(1), .z = tvec(2)}}; } -mrcal_result::~mrcal_result() { - return; -} +mrcal_result::~mrcal_result() { return; } // Code taken from mrcal, license: // Copyright (c) 2017-2023 California Institute of Technology ("Caltech"). U.S. diff --git a/src/mrcal_wrapper.h b/src/mrcal_wrapper.h index 8404afa..fb1cdd0 100644 --- a/src/mrcal_wrapper.h +++ b/src/mrcal_wrapper.h @@ -1,3 +1,20 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + /* * Copyright (C) Photon Vision. *