A makefile to facilitate checking Emacs packages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

153 lines
5.4 KiB

  1. MAKEL_VERSION=0.6.0
  2. MAKEL_LOAD_PATH=-L . $(patsubst %,-L ../%,$(ELPA_DEPENDENCIES))
  3. MAKEL_SET_ARCHIVES0=${ELPA_ARCHIVES}
  4. MAKEL_SET_ARCHIVES1=$(patsubst gnu,(cons \"gnu\" \"https://elpa.gnu.org/packages/\"),${MAKEL_SET_ARCHIVES0})
  5. MAKEL_SET_ARCHIVES2=$(patsubst melpa,(cons \"melpa\" \"https://melpa.org/packages/\"),${MAKEL_SET_ARCHIVES1})
  6. MAKEL_SET_ARCHIVES3=$(patsubst melpa-stable,(cons \"melpa-stable\" \"https://stable.melpa.org/packages/\"),${MAKEL_SET_ARCHIVES2})
  7. MAKEL_SET_ARCHIVES4=$(patsubst org,(cons \"org\" \"https://orgmode.org/elpa/\"),${MAKEL_SET_ARCHIVES3})
  8. MAKEL_SET_ARCHIVES=(setq package-archives (list ${MAKEL_SET_ARCHIVES4}))
  9. EMACSBIN?=emacs
  10. BATCH=$(EMACSBIN) -Q --batch $(MAKEL_LOAD_PATH) \
  11. --eval "(setq load-prefer-newer t)" \
  12. --eval "(require 'package)" \
  13. --eval "${MAKEL_SET_ARCHIVES}" \
  14. --eval "(setq enable-dir-local-variables nil)" \
  15. --funcall package-initialize
  16. CURL = curl --fail --silent --show-error --insecure \
  17. --location --retry 9 --retry-delay 9 \
  18. --remote-name-all
  19. # Definition of a utility function `split_with_commas`.
  20. # Argument 1: a space-separated list of filenames
  21. # Return: a comma+space-separated list of filenames
  22. comma:=,
  23. empty:=
  24. space:=$(empty) $(empty)
  25. split_with_commas=$(subst ${space},${comma}${space},$(1))
  26. .PHONY: debug install-elpa-dependencies download-non-elpa-dependencies ci-dependencies check test test-ert test-buttercup lint lint-checkdoc lint-package-lint lint-compile
  27. makel-version:
  28. @echo "makel v${MAKEL_VERSION}"
  29. debug:
  30. @echo "MAKEL_LOAD_PATH=${MAKEL_LOAD_PATH}"
  31. @echo "MAKEL_SET_ARCHIVES=${MAKEL_SET_ARCHIVES}"
  32. @${BATCH} --eval "(message \"%S\" package-archives)"
  33. install-elpa-dependencies:
  34. @if [ -n "${ELPA_DEPENDENCIES}" ]; then \
  35. echo "# Install ELPA dependencies: $(call split_with_commas,${ELPA_DEPENDENCIES})…"; \
  36. output=$$($(BATCH) \
  37. --funcall package-refresh-contents \
  38. ${patsubst %,--eval "(package-install (quote %))",${ELPA_DEPENDENCIES}} 2>&1) \
  39. || ( echo "$${output}" && exit 1 ); \
  40. fi
  41. download-non-elpa-dependencies:
  42. @if [ -n "${DOWNLOAD_DEPENDENCIES}" ]; then \
  43. echo "# Download non-ELPA dependencies: $(call split_with_commas,${DOWNLOAD_DEPENDENCIES})…"; \
  44. $(CURL) $(patsubst %,"%",${DOWNLOAD_DEPENDENCIES}); \
  45. fi
  46. ci-dependencies: install-elpa-dependencies download-non-elpa-dependencies
  47. check: test lint
  48. ####################################
  49. # Tests
  50. ####################################
  51. test: test-ert test-buttercup
  52. ####################################
  53. # Tests - ERT
  54. ####################################
  55. MAKEL_TEST_ERT_FILES0=$(filter-out %-autoloads.el,${TEST_ERT_FILES})
  56. MAKEL_TEST_ERT_FILES=$(patsubst %,(load-file \"%\"),${MAKEL_TEST_ERT_FILES0})
  57. test-ert:
  58. @if [ -n "${TEST_ERT_FILES}" ]; then \
  59. echo "# Run ert tests from $(call split_with_commas,${MAKEL_TEST_ERT_FILES0})…"; \
  60. output=$$(${BATCH} \
  61. $(if ${TEST_ERT_OPTIONS},${TEST_ERT_OPTIONS}) \
  62. --eval "(progn ${MAKEL_TEST_ERT_FILES} (ert-run-tests-batch-and-exit))" 2>&1) \
  63. || ( echo "$${output}" && exit 1 ); \
  64. fi;
  65. ####################################
  66. # Tests - Buttercup
  67. ####################################
  68. test-buttercup:
  69. @if [ -n "${TEST_BUTTERCUP_OPTIONS}" ]; then \
  70. echo "# Run buttercup tests on $(call split_with_commas,${TEST_BUTTERCUP_OPTIONS})"; \
  71. output=$$(${BATCH} \
  72. --eval "(require 'buttercup)" \
  73. -f buttercup-run-discover ${TEST_BUTTERCUP_OPTIONS} 2>&1) \
  74. || ( echo "$${output}" && exit 1 ); \
  75. fi;
  76. ####################################
  77. # Lint
  78. ####################################
  79. lint: lint-checkdoc lint-package-lint lint-compile
  80. ####################################
  81. # Lint - Checkdoc
  82. ####################################
  83. MAKEL_LINT_CHECKDOC_FILES0=$(filter-out %-autoloads.el,${LINT_CHECKDOC_FILES})
  84. MAKEL_LINT_CHECKDOC_FILES=$(patsubst %,\"%\",${MAKEL_LINT_CHECKDOC_FILES0})
  85. # This rule has to work around the fact that checkdoc doesn't throw
  86. # errors, it always succeeds. We thus have to check if checkdoc
  87. # printed anything to decide the exit status of the rule.
  88. lint-checkdoc:
  89. @if [ -n "${LINT_CHECKDOC_FILES}" ]; then \
  90. echo "# Run checkdoc on $(call split_with_commas,${MAKEL_LINT_CHECKDOC_FILES0})…"; \
  91. output=$$(${BATCH} \
  92. $(if ${LINT_CHECKDOC_OPTIONS},${LINT_CHECKDOC_OPTIONS}) \
  93. --eval "(mapcar #'checkdoc-file (list ${MAKEL_LINT_CHECKDOC_FILES}))" 2>&1); \
  94. [ -z "$${output}" ] || (echo "$${output}"; exit 1); \
  95. fi;
  96. ####################################
  97. # Lint - Package-lint
  98. ####################################
  99. MAKEL_LINT_PACKAGE_LINT_FILES=$(filter-out %-autoloads.el,${LINT_PACKAGE_LINT_FILES})
  100. lint-package-lint:
  101. @if [ -n "${LINT_PACKAGE_LINT_FILES}" ]; then \
  102. echo "# Run package-lint on $(call split_with_commas,${MAKEL_LINT_PACKAGE_LINT_FILES})…"; \
  103. ${BATCH} \
  104. --eval "(require 'package-lint)" \
  105. $(if ${LINT_PACKAGE_LINT_OPTIONS},${LINT_PACKAGE_LINT_OPTIONS}) \
  106. --funcall package-lint-batch-and-exit \
  107. ${MAKEL_LINT_PACKAGE_LINT_FILES}; \
  108. fi;
  109. ####################################
  110. # Lint - Compilation
  111. ####################################
  112. MAKEL_LINT_COMPILE_FILES=$(filter-out %-autoloads.el,${LINT_COMPILE_FILES})
  113. lint-compile:
  114. @if [ -n "${LINT_COMPILE_FILES}" ]; then \
  115. echo "# Run byte compilation on $(call split_with_commas,${MAKEL_LINT_COMPILE_FILES})…"; \
  116. ${BATCH} \
  117. --eval "(setq byte-compile-error-on-warn t)" \
  118. $(if ${LINT_COMPILE_OPTIONS},${LINT_COMPILE_OPTIONS}) \
  119. --funcall batch-byte-compile \
  120. ${MAKEL_LINT_COMPILE_FILES}; \
  121. fi