diff --git a/Makefile b/Makefile index 5000738..58c5a06 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +# * makem.sh/Makefile --- Script to aid building and testing Emacs Lisp packages + +# This Makefile is from the makem.sh repo: . + # * Arguments # For consistency, we use only var=val options, not hyphen-prefixed options. diff --git a/makem.sh b/makem.sh index d63285c..4c739cb 100755 --- a/makem.sh +++ b/makem.sh @@ -46,6 +46,60 @@ # * Functions +function usage { + cat <. + + -s, --sandbox Run Emacs with emacs-sandbox.sh in a temporary + directory (removing directory on exit). + -S, --sandbox-dir DIR Use DIR for the sandbox directory (leaving it + on exit). Implies -s. + --auto-install Automatically install package dependencies. + -i, --install PACKAGE Install PACKAGE before running rules. + +Source files are automatically discovered from git, or may be +specified with options. + +Package dependencies are discovered from "Package-Requires" headers in +source files and from a Cask file. +EOF +} + # ** Elisp # These functions return a path to an elisp file which can be loaded @@ -113,10 +167,10 @@ EOF # ** Emacs function run_emacs { - debug "run_emacs: $emacs_command -Q --batch --load=$package_initialize_file -L \"$load_path\" $@" + debug "run_emacs: $emacs_command -Q $batch_arg --load=$package_initialize_file -L \"$load_path\" $@" if [[ $debug_load_path ]] then - debug $($emacs_command -Q --batch \ + debug $($emacs_command -Q $batch_arg \ --load=$package_initialize_file \ -L "$load_path" \ --eval "(message \"LOAD-PATH: %s\" load-path)" \ @@ -124,7 +178,7 @@ function run_emacs { fi output_file=$(mktemp) - $emacs_command -Q --batch \ + $emacs_command -Q $batch_arg \ --load=$package_initialize_file \ -L "$load_path" \ "$@" \ @@ -328,53 +382,6 @@ function ts { date "+%Y-%m-%d %H:%M:%S" } -function usage { - cat <. - - -s, --sandbox Run Emacs with emacs-sandbox.sh in a temporary - directory (removing directory on exit). - -S, --sandbox-dir DIR Use DIR for the sandbox directory (leaving it - on exit). Implies -s. - --auto-install Automatically install package dependencies. - -i, --install PACKAGE Install PACKAGE before running rules. - -Source files are automatically discovered from git, or may be -specified with options. - -Package dependencies are discovered from "Package-Requires" headers in -source files and from a Cask file. -EOF -} - # * Rules # These functions are intended to be called as rules, like a Makefile. @@ -398,6 +405,23 @@ function compile { || error "Compilation failed." } +function batch { + # Run Emacs with $batch_args and with project source and test files loaded. + verbose 1 "Executing Emacs with arguments: ${batch_args[@]}" + + run_emacs \ + $(load-files-args "${project_source_files[@]}" "${project_test_files[@]}") \ + "${batch_args[@]}" +} + +function interactive { + # Run Emacs interactively. Most useful with --sandbox and --auto-install. + unset batch_arg + run_emacs \ + $(load-files-args "${project_source_files[@]}" "${project_test_files[@]}") + batch_arg="--batch" +} + function lint { verbose 1 "Linting..." @@ -485,6 +509,7 @@ emacs_command="emacs" errors=0 verbose=0 compile=true +batch_arg="--batch" # MAYBE: Disable color if not outputting to a terminal. (OTOH, the # colorized output is helpful in CI logs, and I don't know if, @@ -659,7 +684,16 @@ fi # Run rules. for rule in "${rest[@]}" do - if type "$rule" 2>/dev/null | grep "$rule is a function" &>/dev/null + if [[ $batch ]] + then + debug "Adding batch argument: $rule" + batch_args+=("$rule") + + elif [[ $rule = batch ]] + then + # Remaining arguments are passed to Emacs. + batch=true + elif type "$rule" 2>/dev/null | grep "$rule is a function" &>/dev/null then $rule elif [[ $rule = test ]] @@ -672,6 +706,9 @@ do fi done +# The batch rule. +[[ $batch ]] && batch + if [[ $errors -gt 0 ]] then log_color red "Finished with $errors errors."