From 9bd1235e00439dad6390ac0a052b86559271694b Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Wed, 22 Jan 2020 17:05:16 -0600 Subject: [PATCH] Meta: Update makem.sh files --- .github/workflows/test.yml | 10 +-- Makefile | 9 ++- makem.sh | 125 ++++++++++++++++++++++++++++++++----- 3 files changed, 120 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a9c29c..b3c22ed 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,8 +28,8 @@ on: pull_request: push: # Comment out this section to enable testing of all branches. - # branches: - # - master + branches: + - master jobs: build: @@ -51,13 +51,15 @@ jobs: run: | SANDBOX_DIR=$(mktemp -d) || exit 1 echo ::set-env name=SANDBOX_DIR::$SANDBOX_DIR - ./makem.sh -vv --sandbox-dir=$SANDBOX_DIR --auto-install --install package-lint + ./makem.sh -vv --sandbox-dir=$SANDBOX_DIR --install-deps --install-linters # The "all" rule is not used, because it treats compilation warnings # as failures, so linting and testing are run as separate steps. - name: Lint - continue-on-error: true + # NOTE: Uncomment this line to treat lint failures as passing + # so the job doesn't show failure. + # continue-on-error: true run: ./makem.sh -vv --sandbox-dir=$SANDBOX_DIR lint - name: Test diff --git a/Makefile b/Makefile index 58c5a06..1ca3da4 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,11 @@ # conflict with Make's own arguments through Make to the script. # Using -- doesn't seem to do it. -ifdef auto-install - AUTO_INSTALL = "--auto-install" +ifdef install-deps + INSTALL_DEPS = "--install-deps" +endif +ifdef install-linters + INSTALL_LINTERS = "--install-linters" endif ifdef sandbox @@ -46,4 +49,4 @@ endif # directory by that name exists, which can confuse Make. %: - @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(SANDBOX_DIR) $(AUTO_INSTALL) $(@) + @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(SANDBOX_DIR) $(INSTALL_DEPS) $(INSTALL_LINTERS) $(@) diff --git a/makem.sh b/makem.sh index 4cdf914..9f3538c 100755 --- a/makem.sh +++ b/makem.sh @@ -48,16 +48,21 @@ function usage { cat </dev/null + then + if [[ $direct_p ]] + then + error "$package not available." + else + verbose 2 "$package not available." + fi + return 1 + fi +} + +function ensure-tests-available { + # If tests of type $1 (like "ERT") are available, return 0. Otherwise, if + # $2 is set, give an error and return 1; otherwise give verbose message. $1 + # should have a corresponding predicate command, like ert-tests-p for ERT. + local test_name=$1 + local test_command="${test_name,,}-tests-p" # Converts name to lowercase. + local direct_p=$2 + + if ! $test_command + then + if [[ $direct_p ]] + then + error "$test_name tests not found." + else + verbose 2 "$test_name tests not found." + fi + return 1 + fi +} + function echo_color { # This allows bold, italic, etc. without needing a function for # each variation. @@ -407,9 +459,9 @@ function log { echo "LOG ($(ts)): $@" >&2 } function log_color { - local color=$1 + local color_name=$1 shift - echo_color $color "LOG ($(ts)): $@" >&2 + echo_color $color_name "LOG ($(ts)): $@" >&2 } function success { if [[ $verbose -ge 2 ]] @@ -421,11 +473,11 @@ function verbose { # $1 is the verbosity level, rest are echoed when appropriate. if [[ $verbose -ge $1 ]] then - [[ $1 -eq 1 ]] && local color=blue - [[ $1 -ge 2 ]] && local color=cyan + [[ $1 -eq 1 ]] && local color_name=blue + [[ $1 -ge 2 ]] && local color_name=cyan shift - log_color $color "$@" >&2 + log_color $color_name "$@" >&2 fi } @@ -436,6 +488,9 @@ function ts { # * Rules # These functions are intended to be called as rules, like a Makefile. +# Some rules test $1 to determine whether the rule is being called +# directly or from a meta-rule; if directly, an error is given if the +# rule can't be run, otherwise it's skipped. function all { verbose 1 "Running all rules..." @@ -466,7 +521,7 @@ function batch { } function interactive { - # Run Emacs interactively. Most useful with --sandbox and --auto-install. + # Run Emacs interactively. Most useful with --sandbox and --install-deps. unset arg_batch run_emacs \ $(args-load-files "${files_project_source[@]}" "${files_project_test[@]}") @@ -478,6 +533,7 @@ function lint { lint-checkdoc lint-compile + lint-indent lint-package } @@ -504,7 +560,36 @@ function lint-compile { unset compile_error_on_warn } +function lint-indent { + ensure-package-available indent-lint $1 || return $(echo-unset-p $1) + + verbose 1 "Linting indentation..." + + # FIXME: indent-lint outputs a summary line like: + # Diff finished (has differences). Fri Jan 17 10:30:34 2020 + # which is unnecessary for our use and clutters output. + + # We load project source files as well, because they may contain + # macros with (declare (indent)) rules which must be loaded to set + # indentation. However... + + # FIXME: This doesn't appear to actually work: macros that set + # indentation and are correctly indented in the source files are + # reported as having wrong indentation. Not sure if bug in + # indent-lint or here. + + run_emacs \ + --load indent-lint \ + $(args-load-files "${files_project_source[@]}" "${files_project_test[@]}") \ + --funcall indent-lint-batch \ + "${files_project_source[@]}" "${files_project_test[@]}" \ + && success "Linting indentation finished without errors." \ + || error "Linting indentation failed." +} + function lint-package { + ensure-package-available package-lint $1 || return $(echo-unset-p $1) + verbose 1 "Linting package..." run_emacs \ @@ -523,7 +608,7 @@ function tests { } function test-buttercup { - buttercup-tests-p || return 0 + ensure-tests-available Buttercup $1 || return $(echo-unset-p $1) compile || die verbose 1 "Running Buttercup tests..." @@ -540,7 +625,7 @@ function test-buttercup { } function test-ert { - ert-tests-p || return 0 + ensure-tests-available ERT $1 || return $(echo-unset-p $1) compile || die verbose 1 "Running ERT tests..." @@ -555,7 +640,7 @@ function test-ert { # * Defaults -test_files_regexp='^(tests?|t)/' +test_files_regexp='^((tests?|t)/)|-test.el$|^test-' emacs_command=("emacs") errors=0 @@ -630,7 +715,7 @@ files_project_byte_compile=("${files_project_source[@]}" "${files_project_test[@ args=$(getopt -n "$0" \ -o dhi:sS:vf:CO \ - -l auto-install,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,no-org-repo,sandbox,sandbox-dir: \ + -l install-deps,install-linters,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,no-org-repo,sandbox,sandbox-dir: \ -- "$@") \ || { usage; exit 1; } eval set -- "$args" @@ -638,8 +723,12 @@ eval set -- "$args" while true do case "$1" in - --auto-install) - auto_install=true + --install-deps) + install_deps=true + ;; + --install-linters) + args_sandbox_package_install+=(--eval "(package-install 'indent-lint)" + --eval "(package-install 'package-lint)") ;; -d|--debug) debug=true @@ -726,7 +815,9 @@ do batch=true elif type -t "$rule" 2>/dev/null | grep function &>/dev/null then - $rule + # Pass called-directly as $1 to indicate that the rule is + # being called directly rather than from a meta-rule. + $rule called-directly elif [[ $rule = test ]] then # Allow the "tests" rule to be called as "test". Since "test"