Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. SCRIPTS_DIR := buildroot/share/scripts
  2. CONTAINER_RT_BIN := docker
  3. CONTAINER_RT_OPTS := --rm -v $(PWD):/code -v platformio-cache:/root/.platformio
  4. CONTAINER_IMAGE := marlin-dev
  5. UNIT_TEST_CONFIG ?= default
  6. help:
  7. @echo "Tasks for local development:"
  8. @echo "make marlin : Build Marlin for the configured board"
  9. @echo "make format-pins -j : Reformat all pins files (-j for parallel execution)"
  10. @echo "make validate-pins -j : Validate all pins files, fails if any require reformatting"
  11. @echo "make validate-boards -j : Validate boards.h and pins.h for standards compliance"
  12. @echo "make tests-single-ci : Run a single test from inside the CI"
  13. @echo "make tests-single-local : Run a single test locally"
  14. @echo "make tests-single-local-docker : Run a single test locally, using docker"
  15. @echo "make tests-all-local : Run all tests locally"
  16. @echo "make tests-all-local-docker : Run all tests locally, using docker"
  17. @echo "make unit-test-single-local : Run unit tests for a single config locally"
  18. @echo "make unit-test-single-local-docker : Run unit tests for a single config locally, using docker"
  19. @echo "make unit-test-all-local : Run all code tests locally"
  20. @echo "make unit-test-all-local-docker : Run all code tests locally, using docker"
  21. @echo "make setup-local-docker : Setup local docker using buildx"
  22. @echo ""
  23. @echo "Options for testing:"
  24. @echo " TEST_TARGET Set when running tests-single-*, to select the"
  25. @echo " test. If you set it to ALL it will run all "
  26. @echo " tests, but some of them are broken: use "
  27. @echo " tests-all-* instead to run only the ones that "
  28. @echo " run on GitHub CI"
  29. @echo " ONLY_TEST Limit tests to only those that contain this, or"
  30. @echo " the index of the test (1-based)"
  31. @echo " UNIT_TEST_CONFIG Set the name of the config from the test folder, without"
  32. @echo " the leading number. Default is 'default'". Used with the
  33. @echo " unit-test-single-* tasks"
  34. @echo " VERBOSE_PLATFORMIO If you want the full PIO output, set any value"
  35. @echo " GIT_RESET_HARD Used by CI: reset all local changes. WARNING:"
  36. @echo " THIS WILL UNDO ANY CHANGES YOU'VE MADE!"
  37. marlin:
  38. ./buildroot/bin/mftest -a
  39. .PHONY: marlin
  40. tests-single-ci:
  41. export GIT_RESET_HARD=true
  42. $(MAKE) tests-single-local TEST_TARGET=$(TEST_TARGET) PLATFORMIO_BUILD_FLAGS=-DGITHUB_ACTION
  43. tests-single-local:
  44. @if ! test -n "$(TEST_TARGET)" ; then echo "***ERROR*** Set TEST_TARGET=<your-module> or use make tests-all-local" ; return 1; fi
  45. export PATH="./buildroot/bin/:./buildroot/tests/:${PATH}" \
  46. && export VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) \
  47. && run_tests . $(TEST_TARGET) "$(ONLY_TEST)"
  48. tests-single-local-docker:
  49. @if ! test -n "$(TEST_TARGET)" ; then echo "***ERROR*** Set TEST_TARGET=<your-module> or use make tests-all-local-docker" ; return 1; fi
  50. @if ! $(CONTAINER_RT_BIN) images -q $(CONTAINER_IMAGE) > /dev/null ; then $(MAKE) setup-local-docker ; fi
  51. $(CONTAINER_RT_BIN) run $(CONTAINER_RT_OPTS) $(CONTAINER_IMAGE) make tests-single-local TEST_TARGET=$(TEST_TARGET) VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) GIT_RESET_HARD=$(GIT_RESET_HARD) ONLY_TEST="$(ONLY_TEST)"
  52. tests-all-local:
  53. @python -c "import yaml" 2>/dev/null || (echo 'pyyaml module is not installed. Install it with "python -m pip install pyyaml"' && exit 1)
  54. export PATH="./buildroot/bin/:./buildroot/tests/:${PATH}" \
  55. && export VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) \
  56. && for TEST_TARGET in $$(python $(SCRIPTS_DIR)/get_test_targets.py) ; do \
  57. if [ "$$TEST_TARGET" = "linux_native" ] && [ "$$(uname)" = "Darwin" ]; then \
  58. echo "Skipping tests for $$TEST_TARGET on macOS" ; \
  59. continue ; \
  60. fi ; \
  61. echo "Running tests for $$TEST_TARGET" ; \
  62. run_tests . $$TEST_TARGET || exit 1 ; \
  63. sleep 5; \
  64. done
  65. tests-all-local-docker:
  66. @if ! $(CONTAINER_RT_BIN) images -q $(CONTAINER_IMAGE) > /dev/null ; then $(MAKE) setup-local-docker ; fi
  67. $(CONTAINER_RT_BIN) run $(CONTAINER_RT_OPTS) $(CONTAINER_IMAGE) make tests-all-local VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) GIT_RESET_HARD=$(GIT_RESET_HARD)
  68. unit-test-single-local:
  69. platformio run -t marlin_$(UNIT_TEST_CONFIG) -e linux_native_test
  70. unit-test-single-local-docker:
  71. @if ! $(CONTAINER_RT_BIN) images -q $(CONTAINER_IMAGE) > /dev/null ; then $(MAKE) setup-local-docker ; fi
  72. $(CONTAINER_RT_BIN) run $(CONTAINER_RT_OPTS) $(CONTAINER_IMAGE) make unit-test-single-local UNIT_TEST_CONFIG=$(UNIT_TEST_CONFIG)
  73. unit-test-all-local:
  74. platformio run -t test-marlin -e linux_native_test
  75. unit-test-all-local-docker:
  76. @if ! $(CONTAINER_RT_BIN) images -q $(CONTAINER_IMAGE) > /dev/null ; then $(MAKE) setup-local-docker ; fi
  77. $(CONTAINER_RT_BIN) run $(CONTAINER_RT_OPTS) $(CONTAINER_IMAGE) make unit-test-all-local
  78. setup-local-docker:
  79. $(CONTAINER_RT_BIN) buildx build -t $(CONTAINER_IMAGE) -f docker/Dockerfile .
  80. PINS := $(shell find Marlin/src/pins -mindepth 2 -name '*.h')
  81. .PHONY: $(PINS) format-pins validate-pins
  82. $(PINS): %:
  83. @echo "Formatting $@"
  84. @python $(SCRIPTS_DIR)/pinsformat.py $< $@
  85. format-pins: $(PINS)
  86. validate-pins: format-pins
  87. @echo "Validating pins files"
  88. @git diff --exit-code || (git status && echo "\nError: Pins files are not formatted correctly. Run \"make format-pins\" to fix.\n" && exit 1)
  89. BOARDS_FILE := Marlin/src/core/boards.h
  90. .PHONY: validate-boards
  91. validate-boards:
  92. @echo "Validating boards.h file"
  93. @python $(SCRIPTS_DIR)/validate_boards.py $(BOARDS_FILE) || (echo "\nError: boards.h file is not valid. Please check and correct it.\n" && exit 1)