diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f929f80..a66cdac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: rev: 'v0.6.0' hooks: - id: cmake-format # cmake formatter - files: (CMakeLists.*|.*\.cmake^|.*\.cmake.in) + files: ^(CMakeLists.*|.*\.cmake|.*\.cmake.in)$ - repo: https://github.com/pre-commit/mirrors-yapf rev: 'v0.27.0' hooks: diff --git a/CMakeLists.txt b/CMakeLists.txt index ecca89e..80fddab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,29 +9,14 @@ project( VERSION ${PROJECT_VERSION} ) -if(NOT CMAKE_CROSSCOMPILING) - # - # If we are not crosscompiling, include `utils` with host tools. - # - add_subdirectory(utils) -endif() - # # Command Line Options # # You should specify those options when invoking CMake. Example: # ~~~ -# cmake .. -DPRINTER=MMU +# cmake .. -DCUSTOM_COMPILE_OPTIONS=-DENABLE_FEATURE_X # ~~~ -set(PRINTER_VALID_OPTS "MMU") - -set(PRINTER - "MMU" - CACHE - STRING - "Select the MMU unit for which you want to compile the project (valid values are ${PRINTER_VALID_OPTS})." - ) set(PROJECT_VERSION_SUFFIX "" CACHE @@ -53,13 +38,6 @@ set(CUSTOM_COMPILE_OPTIONS CACHE STRING "Allows adding custom C/C++ flags" ) -# Validate options -foreach(OPTION "PRINTER") - if(NOT ${OPTION} IN_LIST ${OPTION}_VALID_OPTS) - message(FATAL_ERROR "Invalid ${OPTION} ${${OPTION}}: Valid values are ${${OPTION}_VALID_OPTS}") - endif() -endforeach() - # Resolve BUILD_NUMBER and PROJECT_VERSION_* variables resolve_version_variables() @@ -86,7 +64,6 @@ message( STATUS "Project version with short suffix: ${PROJECT_VERSION}${PROJECT_VERSION_SUFFIX_SHORT}" ) message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") -message(STATUS "Printer: ${PRINTER}") # eclipse sets those variables, so lets just use them so we don't get a warning about unused # variables @@ -185,56 +162,16 @@ endif() # add_link_dependency(firmware "${LINKER_SCRIPT}") -target_include_directories(firmware PRIVATE include src) +target_include_directories(firmware PRIVATE src) target_compile_options(firmware PRIVATE -Wdouble-promotion) -target_sources( - firmware - PRIVATE src/main.cpp - src/hal/avr/cpu.cpp - src/hal/avr/usart.cpp - src/hal/avr/shr16.cpp - src/hal/avr/eeprom.cpp - src/hal/avr/tmc2130.cpp - src/hal/adc.cpp - src/modules/protocol.cpp - src/modules/buttons.cpp - src/modules/debouncer.cpp - src/modules/finda.cpp - src/modules/fsensor.cpp - src/modules/globals.cpp - src/modules/idler.cpp - src/modules/leds.cpp - src/modules/motion.cpp - src/modules/pulse_gen.cpp - src/modules/permanent_storage.cpp - src/modules/selector.cpp - src/modules/timebase.cpp - src/modules/user_input.cpp - src/modules/speed_table.cpp - src/logic/command_base.cpp - src/logic/cut_filament.cpp - src/logic/eject_filament.cpp - src/logic/feed_to_bondtech.cpp - src/logic/feed_to_finda.cpp - src/logic/load_filament.cpp - src/logic/no_command.cpp - src/logic/tool_change.cpp - src/logic/unload_filament.cpp - src/logic/unload_to_finda.cpp - ) -set_property( - SOURCE src/version.c - APPEND - PROPERTY COMPILE_DEFINITIONS - FW_BUILD_NUMBER=${BUILD_NUMBER} - FW_VERSION_FULL=${PROJECT_VERSION_FULL} - FW_VERSION=${PROJECT_VERSION} - FW_VERSION_SUFFIX=${PROJECT_VERSION_SUFFIX} - FW_VERSION_SUFFIX_SHORT=${PROJECT_VERSION_SUFFIX_SHORT} - ) +add_subdirectory(src) + if(NOT CMAKE_CROSSCOMPILING) + # do not build the firmware by default (tests are the focus if not crosscompiling) + set_target_properties(firmware PROPERTIES EXCLUDE_FROM_ALL YES) + enable_testing() add_subdirectory(tests) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..9fb39e8 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,19 @@ +target_sources( + firmware + PRIVATE main.cpp +) + +set_property( + SOURCE src/version.c + APPEND + PROPERTY COMPILE_DEFINITIONS + FW_BUILD_NUMBER=${BUILD_NUMBER} + FW_VERSION_FULL=${PROJECT_VERSION_FULL} + FW_VERSION=${PROJECT_VERSION} + FW_VERSION_SUFFIX=${PROJECT_VERSION_SUFFIX} + FW_VERSION_SUFFIX_SHORT=${PROJECT_VERSION_SUFFIX_SHORT} +) + +add_subdirectory(hal) +add_subdirectory(logic) +add_subdirectory(modules) diff --git a/src/hal/CMakeLists.txt b/src/hal/CMakeLists.txt new file mode 100644 index 0000000..1776def --- /dev/null +++ b/src/hal/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources( + firmware PRIVATE avr/cpu.cpp avr/usart.cpp avr/shr16.cpp avr/eeprom.cpp avr/tmc2130.cpp adc.cpp + ) diff --git a/src/hal/circular_buffer.h b/src/hal/circular_buffer.h index 7e8249a..4330e15 100644 --- a/src/hal/circular_buffer.h +++ b/src/hal/circular_buffer.h @@ -1,10 +1,6 @@ #pragma once - -#include #include -#ifndef __AVR__ -#include -#endif +#include "../limits.h" /// A generic circular index class which can be used to build circular buffers /// Can hold up to size elements @@ -15,10 +11,8 @@ template class CircularIndex { public: -#ifndef __AVR__ static_assert(size <= std::numeric_limits::max() / 2, "index_t is too small for the requested size"); -#endif constexpr inline CircularIndex() : tail(0) diff --git a/src/limits.h b/src/limits.h new file mode 100644 index 0000000..232f03b --- /dev/null +++ b/src/limits.h @@ -0,0 +1,23 @@ +#pragma once +#ifndef __AVR__ +#include +#else + +// A minimal std::numeric_limits for platforms that lack one +#include +#include + +namespace std { + +template +class numeric_limits; + +template <> +class numeric_limits { +public: + static constexpr size_t max() { return UINT8_MAX; } +}; + +} // namespace std + +#endif diff --git a/src/logic/CMakeLists.txt b/src/logic/CMakeLists.txt new file mode 100644 index 0000000..ec8f87b --- /dev/null +++ b/src/logic/CMakeLists.txt @@ -0,0 +1,14 @@ +target_sources( + firmware + PRIVATE + command_base.cpp + cut_filament.cpp + eject_filament.cpp + feed_to_bondtech.cpp + feed_to_finda.cpp + load_filament.cpp + no_command.cpp + tool_change.cpp + unload_filament.cpp + unload_to_finda.cpp +) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt new file mode 100644 index 0000000..c653a1a --- /dev/null +++ b/src/modules/CMakeLists.txt @@ -0,0 +1,17 @@ +target_sources( + firmware + PRIVATE protocol.cpp + buttons.cpp + debouncer.cpp + finda.cpp + fsensor.cpp + globals.cpp + idler.cpp + leds.cpp + motion.cpp + permanent_storage.cpp + selector.cpp + timebase.cpp + user_input.cpp + pulse_gen.cpp + ) diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt deleted file mode 100644 index 792d600..0000000 --- a/tests/integration/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -# diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index d755b48..53fd3a5 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -1,10 +1,6 @@ # first, let's create a symbolic target for all tests add_custom_target(tests) -# this had a reason on the Buddy FW, but on the AVR we cannot get close to having 16bit ints and -# pointers so the unit tests may be compiled 64bit afterall set(CMAKE_C_FLAGS -m32) -# set(CMAKE_CXX_FLAGS -m32) - # include catch_discover_tests function from Catch2 include(${Catch2_SOURCE_DIR}/contrib/Catch.cmake) @@ -21,6 +17,9 @@ endfunction() add_executable(system_tests ${CMAKE_CURRENT_SOURCE_DIR}/system_test.cpp) add_catch_test(system_tests) +set(MODULES_STUBS_DIR ${CMAKE_SOURCE_DIR}/tests/unit/modules/stubs) +set(LOGIC_STUBS_DIR ${CMAKE_SOURCE_DIR}/tests/unit/logic/stubs) + # now, include all the unit tests; they should add themselves using the add_catch_test function add_subdirectory(hal) add_subdirectory(logic) diff --git a/tests/unit/logic/cut_filament/CMakeLists.txt b/tests/unit/logic/cut_filament/CMakeLists.txt index d0e21e7..651b238 100644 --- a/tests/unit/logic/cut_filament/CMakeLists.txt +++ b/tests/unit/logic/cut_filament/CMakeLists.txt @@ -1,29 +1,29 @@ # define the test executable add_executable( cut_filament_tests - ../../../../src/logic/cut_filament.cpp - ../../../../src/logic/feed_to_finda.cpp - ../../../../src/logic/unload_filament.cpp - ../../../../src/logic/unload_to_finda.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_cut_filament.cpp ) diff --git a/tests/unit/logic/eject_filament/CMakeLists.txt b/tests/unit/logic/eject_filament/CMakeLists.txt index f658cca..e347b1d 100644 --- a/tests/unit/logic/eject_filament/CMakeLists.txt +++ b/tests/unit/logic/eject_filament/CMakeLists.txt @@ -1,30 +1,29 @@ # define the test executable add_executable( eject_filament_tests - ../../../../src/logic/eject_filament.cpp - ../../../../src/logic/feed_to_finda.cpp - ../../../../src/logic/unload_filament.cpp - ../../../../src/logic/unload_to_finda.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_eject_filament.cpp ) diff --git a/tests/unit/logic/feed_to_bondtech/CMakeLists.txt b/tests/unit/logic/feed_to_bondtech/CMakeLists.txt index 8a78a59..66e312e 100644 --- a/tests/unit/logic/feed_to_bondtech/CMakeLists.txt +++ b/tests/unit/logic/feed_to_bondtech/CMakeLists.txt @@ -1,26 +1,26 @@ # define the test executable add_executable( feed_to_bondtech_tests - ../../../../src/logic/feed_to_bondtech.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_feed_to_bondtech.cpp ) diff --git a/tests/unit/logic/feed_to_finda/CMakeLists.txt b/tests/unit/logic/feed_to_finda/CMakeLists.txt index a036a9c..bd3466c 100644 --- a/tests/unit/logic/feed_to_finda/CMakeLists.txt +++ b/tests/unit/logic/feed_to_finda/CMakeLists.txt @@ -1,26 +1,26 @@ # define the test executable add_executable( feed_to_finda_tests - ../../../../src/logic/feed_to_finda.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_feed_to_finda.cpp ) diff --git a/tests/unit/logic/load_filament/CMakeLists.txt b/tests/unit/logic/load_filament/CMakeLists.txt index 562e58f..74e8951 100644 --- a/tests/unit/logic/load_filament/CMakeLists.txt +++ b/tests/unit/logic/load_filament/CMakeLists.txt @@ -1,28 +1,28 @@ # define the test executable add_executable( load_filament_tests - ../../../../src/logic/feed_to_bondtech.cpp - ../../../../src/logic/feed_to_finda.cpp - ../../../../src/logic/load_filament.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_load_filament.cpp ) diff --git a/tests/unit/logic/tool_change/CMakeLists.txt b/tests/unit/logic/tool_change/CMakeLists.txt index c01d6ec..064f0f3 100644 --- a/tests/unit/logic/tool_change/CMakeLists.txt +++ b/tests/unit/logic/tool_change/CMakeLists.txt @@ -1,31 +1,31 @@ # define the test executable add_executable( tool_change_tests - ../../../../src/logic/feed_to_bondtech.cpp - ../../../../src/logic/feed_to_finda.cpp - ../../../../src/logic/load_filament.cpp - ../../../../src/logic/tool_change.cpp - ../../../../src/logic/unload_filament.cpp - ../../../../src/logic/unload_to_finda.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/tool_change.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_tool_change.cpp ) diff --git a/tests/unit/logic/unload_filament/CMakeLists.txt b/tests/unit/logic/unload_filament/CMakeLists.txt index 255a006..01bf7f7 100644 --- a/tests/unit/logic/unload_filament/CMakeLists.txt +++ b/tests/unit/logic/unload_filament/CMakeLists.txt @@ -1,28 +1,28 @@ # define the test executable add_executable( unload_filament_tests - ../../../../src/logic/feed_to_finda.cpp - ../../../../src/logic/unload_filament.cpp - ../../../../src/logic/unload_to_finda.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_filament.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_unload_filament.cpp ) diff --git a/tests/unit/logic/unload_to_finda/CMakeLists.txt b/tests/unit/logic/unload_to_finda/CMakeLists.txt index e2a3ceb..33c2f87 100644 --- a/tests/unit/logic/unload_to_finda/CMakeLists.txt +++ b/tests/unit/logic/unload_to_finda/CMakeLists.txt @@ -1,26 +1,26 @@ # define the test executable add_executable( unload_to_finda_tests - ../../../../src/logic/unload_to_finda.cpp - ../../../../src/modules/buttons.cpp - ../../../../src/modules/debouncer.cpp - ../../../../src/modules/finda.cpp - ../../../../src/modules/fsensor.cpp - ../../../../src/modules/globals.cpp - ../../../../src/modules/idler.cpp - ../../../../src/modules/leds.cpp - ../../../../src/modules/permanent_storage.cpp - ../../../../src/modules/selector.cpp - ../../../../src/modules/user_input.cpp - ../../../../src/modules/pulse_gen.cpp - ../../modules/stubs/stub_adc.cpp - ../../modules/stubs/stub_eeprom.cpp - ../../modules/stubs/stub_gpio.cpp - ../../modules/stubs/stub_shr16.cpp - ../../modules/stubs/stub_timebase.cpp - ../../modules/stubs/stub_tmc2130.cpp - ../stubs/main_loop_stub.cpp - ../stubs/stub_motion.cpp + ${CMAKE_SOURCE_DIR}/src/logic/unload_to_finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp + ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${CMAKE_SOURCE_DIR}/src/modules/finda.cpp + ${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp + ${CMAKE_SOURCE_DIR}/src/modules/globals.cpp + ${CMAKE_SOURCE_DIR}/src/modules/idler.cpp + ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp + ${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp + ${CMAKE_SOURCE_DIR}/src/modules/selector.cpp + ${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp + ${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp + ${MODULES_STUBS_DIR}/stub_eeprom.cpp + ${MODULES_STUBS_DIR}/stub_gpio.cpp + ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp + ${MODULES_STUBS_DIR}/stub_tmc2130.cpp + ${LOGIC_STUBS_DIR}/main_loop_stub.cpp + ${LOGIC_STUBS_DIR}/stub_motion.cpp test_unload_to_finda.cpp ) diff --git a/tests/unit/modules/buttons/CMakeLists.txt b/tests/unit/modules/buttons/CMakeLists.txt index 7bc32c3..4116fde 100644 --- a/tests/unit/modules/buttons/CMakeLists.txt +++ b/tests/unit/modules/buttons/CMakeLists.txt @@ -1,7 +1,8 @@ # define the test executable add_executable( - buttons_tests ../../../../src/modules/buttons.cpp ../../../../src/modules/debouncer.cpp - ../stubs/stub_adc.cpp ../stubs/stub_timebase.cpp test_buttons.cpp + buttons_tests + ${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp ${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp + ${MODULES_STUBS_DIR}/stub_adc.cpp ${MODULES_STUBS_DIR}/stub_timebase.cpp test_buttons.cpp ) # define required search paths diff --git a/tests/unit/modules/leds/CMakeLists.txt b/tests/unit/modules/leds/CMakeLists.txt index 045db8a..8643d17 100644 --- a/tests/unit/modules/leds/CMakeLists.txt +++ b/tests/unit/modules/leds/CMakeLists.txt @@ -1,7 +1,7 @@ # define the test executable add_executable( - leds_tests ../../../../src/modules/leds.cpp ../stubs/stub_shr16.cpp ../stubs/stub_timebase.cpp - test_leds.cpp + leds_tests ${CMAKE_SOURCE_DIR}/src/modules/leds.cpp ${MODULES_STUBS_DIR}/stub_shr16.cpp + ${MODULES_STUBS_DIR}/stub_timebase.cpp test_leds.cpp ) # define required search paths diff --git a/tests/unit/modules/protocol/CMakeLists.txt b/tests/unit/modules/protocol/CMakeLists.txt index 75344ba..58d1a78 100644 --- a/tests/unit/modules/protocol/CMakeLists.txt +++ b/tests/unit/modules/protocol/CMakeLists.txt @@ -1,5 +1,5 @@ # define the test executable -add_executable(protocol_tests ../../../../src/modules/protocol.cpp test_protocol.cpp) +add_executable(protocol_tests ${CMAKE_SOURCE_DIR}/src/modules/protocol.cpp test_protocol.cpp) # define required search paths target_include_directories(protocol_tests PUBLIC ${CMAKE_SOURCE_DIR}/src/modules) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt deleted file mode 100644 index e69de29..0000000 diff --git a/utils/bootstrap.py b/utils/bootstrap.py index 5ee1aaf..e01994a 100755 --- a/utils/bootstrap.py +++ b/utils/bootstrap.py @@ -45,11 +45,13 @@ dependencies = { }, }, 'gcc-avr': { - 'version': '5.4.0', + # dummy placeholder (currently downloading cmake just for the sake of a valid url/zip archive) + # ... we truly need the binaries! :) + 'version': '0.0.0', 'url': { - 'Linux': 'https://xxxarmkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2', - 'Windows': 'https://xxxarmkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-win32.zip', - 'Darwin': 'https://xxxarmkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-mac.tar.bz2', + 'Linux': 'https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5-Linux-x86_64.tar.gz', + 'Windows': 'https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5-win64-x64.zip', + 'Darwin': 'https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5-Darwin-x86_64.tar.gz', } }, 'clang-format': { @@ -61,7 +63,7 @@ dependencies = { } }, } -pip_dependencies = ['ecdsa', 'polib'] +pip_dependencies = [] # yapf: enable diff --git a/utils/build.py b/utils/build.py index 8da233d..8b5db24 100755 --- a/utils/build.py +++ b/utils/build.py @@ -61,31 +61,6 @@ def get_dependency(name): return install_dir -class Printer(Enum): - """Represents the -DPRINTER CMake option.""" - - MMU = 'MMU' - - -#class Bootloader(Enum): -# """Represents the -DBOOTLOADER CMake option.""" -# -# NO = 'NO' -# EMPTY = 'EMPTY' -# YES = 'YES' -# -# @property -# def file_component(self): -# if self == Bootloader.NO: -# return 'NOBOOT' -# elif self == Bootloader.EMPTY: -# return 'EMPTYBOOT' -# elif self == Bootloader.YES: -# return 'BOOT' -# else: -# raise NotImplementedError - - class BuildType(Enum): """Represents the -DCONFIG CMake option.""" @@ -93,15 +68,6 @@ class BuildType(Enum): RELEASE = 'RELEASE' -#class HostTool(Enum): -# """Known host tools.""" -# -# png2font = "png2font" -# bin2cc = "bin2cc" -# hex2dfu = "hex2dfu" -# makefsdata = "makefsdata" - - class BuildConfiguration(ABC): @abstractmethod def get_cmake_cache_entries(self): @@ -121,14 +87,12 @@ class BuildConfiguration(ABC): class FirmwareBuildConfiguration(BuildConfiguration): def __init__(self, - printer: Printer, build_type: BuildType, toolchain: Path = None, generator: str = None, version_suffix: str = None, version_suffix_short: str = None, custom_entries: List[str] = None): - self.printer = printer self.build_type = build_type self.toolchain = toolchain or FirmwareBuildConfiguration.default_toolchain( ) @@ -139,8 +103,7 @@ class FirmwareBuildConfiguration(BuildConfiguration): @staticmethod def default_toolchain() -> Path: - return Path( - __file__).resolve().parent.parent / 'cmake/AnyAvrGcc.cmake' + return Path(__file__).resolve().parent.parent / 'cmake/AnyAvrGcc.cmake' def get_cmake_cache_entries(self): entries = [] @@ -149,7 +112,6 @@ class FirmwareBuildConfiguration(BuildConfiguration): str(get_dependency('ninja')))) entries.extend([ ('CMAKE_MAKE_PROGRAM', 'FILEPATH', str(get_dependency('ninja'))), - ('PRINTER', 'STRING', self.printer.value), ('CMAKE_TOOLCHAIN_FILE', 'FILEPATH', str(self.toolchain)), ('CMAKE_BUILD_TYPE', 'STRING', self.build_type.value.title()), ('PROJECT_VERSION_SUFFIX', 'STRING', self.version_suffix or ''), @@ -170,7 +132,6 @@ class FirmwareBuildConfiguration(BuildConfiguration): @property def name(self): components = [ - self.printer.name, self.build_type.value, ] return '_'.join(components) @@ -178,7 +139,6 @@ class FirmwareBuildConfiguration(BuildConfiguration): class BuildResult: """Represents a result of an attempt to build the project.""" - def __init__(self, config_returncode: int, build_returncode: Optional[int], stdout: Path, stderr: Path, products: List[Path]): self.config_returncode = config_returncode @@ -281,7 +241,6 @@ def store_products(products: List[Path], build_config: BuildConfiguration, def list_of(EnumType): """Create an argument-parser for comma-separated list of values of some Enum subclass.""" - def convert(val): if val == '': return [] @@ -305,12 +264,6 @@ def cmake_cache_entry(arg): def main(): parser = argparse.ArgumentParser() # yapf: disable - parser.add_argument( - '--printer', - type=list_of(Printer), - default=list(Printer), - help='Printer type (default: {default}).'.format( - default=','.join(str(p.value.lower()) for p in Printer))) parser.add_argument( '--build-type', type=list_of(BuildType), @@ -348,12 +301,6 @@ def main(): '--toolchain', type=Path, help='Path to a CMake toolchain file to be used.') - parser.add_argument( - '--host-tools', - action='store_true', - help=('Build host tools (png2font and others). ' - 'Turned on by default with --generate-cproject only.') - ) parser.add_argument( '--no-build', action='store_true', @@ -388,13 +335,11 @@ def main(): # prepare configurations configurations = [ FirmwareBuildConfiguration( - printer=printer, build_type=build_type, version_suffix=args.version_suffix, version_suffix_short=args.version_suffix_short, generator=args.generator, - custom_entries=args.cmake_def) for printer in args.printer - for build_type in args.build_type + custom_entries=args.cmake_def) for build_type in args.build_type ] # build everything diff --git a/utils/holly/Dockerfile b/utils/holly/Dockerfile new file mode 100644 index 0000000..c44582c --- /dev/null +++ b/utils/holly/Dockerfile @@ -0,0 +1,9 @@ +FROM gcc:11.1 +RUN apt-get clean && \ + apt-get update -qq -y && \ + apt-get install curl python3 python3-pip libncurses5 -y +RUN pip3 install pre-commit ecdsa +WORKDIR /work +ADD utils/bootstrap.py bootstrap.py +RUN gcc --version +RUN python3 bootstrap.py diff --git a/utils/holly/Jenkinsfile b/utils/holly/Jenkinsfile new file mode 100644 index 0000000..e22bf7b --- /dev/null +++ b/utils/holly/Jenkinsfile @@ -0,0 +1,117 @@ +pipeline { + agent { + dockerfile { + label 'docker' + filename 'utils/holly/Dockerfile' + additionalBuildArgs '-t prusa-firmware-mmu' + } + } + + parameters { + string(name: 'VERSION_SUFFIX', defaultValue: '', description: 'Specify custom version suffix for the build (e.g. "-RC1+1010"). Set to "" to use the default one. Leave empty to make a final-version build without any suffix.') + string(name: 'VERSION_SUFFIX_SHORT', defaultValue: '', description: 'Specify custom version suffix for the build (e.g. "-RC1"). Set to "" to use the default one. Leave empty to make a final-version build without any suffix.') + } + + stages { + stage('Prepare Build Stages') { + steps { + script { + // required configurations + def configurations = [ + [build_type: "release"], + ] + + // prepare version suffix + def commit_nr = sh(script: 'git rev-list HEAD --count', returnStdout: true).trim() + def short_suffix + def full_suffix + if (env.CHANGE_ID) { + // This is a PR build + short_suffix = "-BETA+${commit_nr}" + full_suffix = "${short_suffix}.PR${env.CHANGE_ID}.B${env.BUILD_NUMBER}" + } else if (env.BRANCH_NAME.startsWith("RELEASE-")) { + // This is an RC build + short_suffix = "-RC+${commit_nr}" + full_suffix = "${short_suffix}.B${env.BUILD_NUMBER}" + } else { + // This is build of an ordinary branch (not a release branch) + short_suffix = "-BETA+${commit_nr}" + def branch_spec = env.BRANCH_NAME.replaceAll("_", "-") + full_suffix = "${short_suffix}.BRANCH-${branch_spec}.B${env.BUILD_NUMBER}" + } + + if (params.VERSION_SUFFIX != '') { + full_suffix = params.VERSION_SUFFIX + } + if (params.VERSION_SUFFIX_SHORT != '') { + short_suffix = params.VERSION_SUFFIX_SHORT + } + + // create the build stages + configurations.each { config -> + stage("Build - ${config.build_type}") { + catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { + sh """ + exit 0 # temporarily disable building (as we don't have avr-gcc in dependencies) + ln -fs /.dependencies + python3 utils/build.py \ + --build-type ${config.build_type} \ + --generate-bbf \ + --generate-dfu \ + --no-store-output \ + --version-suffix=${full_suffix} \ + --version-suffix-short=${short_suffix} \ + -DCUSTOM_COMPILE_OPTIONS:STRING=-Werror + """ + } + } + } + } + } + } + + stage('Check Formatting') { + when { + expression { env.CHANGE_TARGET } + } + steps { + sh """ + export XDG_CACHE_HOME=\$PWD/.precommit + pre-commit install + pre-commit run \ + --source remotes/origin/${env.CHANGE_TARGET} \ + --origin HEAD \ + --show-diff-on-failure \ + --hook-stage manual + """ + } + } + + stage('Test') { + steps { + sh """ + python3 utils/bootstrap.py + export PATH=\$PWD/.dependencies/cmake-3.15.5/bin:\$PWD/.dependencies/ninja-1.9.0:\$PATH + mkdir -p build-test + LD_LIBRARY_PATH=/usr/local/lib32 \$PWD/.dependencies/cmake-3.15.5/bin/ctest --build-and-test . build-test \ + -DCMAKE_MAKE_PROGRAM=\$PWD/.dependencies/ninja-1.9.0/ninja \ + --build-generator Ninja \ + --build-target tests \ + --test-command ctest + """ + } + } + } + + post { + always { + // archive build products + //archiveArtifacts artifacts: 'build/products/*', fingerprint: true + // archive test products + archiveArtifacts artifacts: 'build-test/Testing/Temporary/LastTest.log' + } + cleanup { + deleteDir() + } + } +}