inaka/elvis.mk

Plugin uses GNU-specific options with 'cp', 'rm' and 'rmdir'

Opened this issue · 7 comments

This means that it fails on macOS unless you have GNU cp/rm/rmdir ahead of the BSD ones in $PATH. For example:

cp: illegal option -- -
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-aclpsvXx] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-aclpsvXx] source_file ... target_directory
make: *** [foo/deps/elvis_mk/plugins.mk:39: foo/elvis] Error 64

Maybe this?

diff --git a/plugins.mk b/plugins.mk
index 33d4aca..3b27fba 100644
--- a/plugins.mk
+++ b/plugins.mk
@@ -46,12 +46,12 @@ endif
                cd elvis-$(ELVIS_VERSION) && \
                $(ELVIS_REBAR3) escriptize
        $(gen_verbose) cp $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/_build/default/bin/elvis $(ELVIS)
-       $(gen_verbose) cp --no-clobber $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG)
+       $(gen_verbose) -cp -n $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG)
        $(verbose) chmod +x $(ELVIS)
        $(verbose) rm -rf $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)
        $(verbose) rm $(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE)
-       $(verbose) rm --force $(ELVIS_BUILD_DIR)/rebar3
-       $(verbose) rmdir --ignore-fail-on-non-empty $(ELVIS_BUILD_DIR)
+       $(verbose) rm -f $(ELVIS_BUILD_DIR)/rebar3
+       $(verbose) -rmdir $(ELVIS_BUILD_DIR)

 elvis: $(ELVIS)
        $(verbose) $(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)

Hmmm. Breaks with V=2.

This seems to work:

diff --git a/plugins.mk b/plugins.mk
index 33d4aca..e8f826c 100644
--- a/plugins.mk
+++ b/plugins.mk
@@ -46,12 +46,12 @@ endif
                cd elvis-$(ELVIS_VERSION) && \
                $(ELVIS_REBAR3) escriptize
        $(gen_verbose) cp $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/_build/default/bin/elvis $(ELVIS)
-       $(gen_verbose) cp --no-clobber $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG)
+       $(gen_verbose) if [ ! -f $(ELVIS_CONFIG) ]; then cp $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG); fi
        $(verbose) chmod +x $(ELVIS)
        $(verbose) rm -rf $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)
        $(verbose) rm $(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE)
-       $(verbose) rm --force $(ELVIS_BUILD_DIR)/rebar3
-       $(verbose) rmdir --ignore-fail-on-non-empty $(ELVIS_BUILD_DIR)
+       $(verbose) rm -f $(ELVIS_BUILD_DIR)/rebar3
+       -$(verbose) rmdir $(ELVIS_BUILD_DIR)

 elvis: $(ELVIS)
        $(verbose) $(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)

Thanks, @rlipscombe!
Do you mind submitting a pull request with the changes?

@rlipscombe, I added your changes and made some performance improvements. Can you please test?

You can update your Makefile with:

dep_elvis_mk = git https://github.com/andrei-mihaila/elvis.mk.git
dep_elvis_mk_commit = master

And, if possible, clone my repo and run test/run.sh.

Thanks!

Minor tweak for consistency with erlang.mk, but lgtm.

Minor tweak for consistency with erlang.mk, but lgtm.

I used that initially and then decided against it because it shows a warning when the build directory doesn't exist.

ls: cannot access '/[...]/elvis.mk/test/_build/': No such file or directory

But we can live with that.