From 51a6141cf9d6768d841d644bd760361443b3dd65 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sun, 6 Dec 2015 00:45:23 +0300 Subject: [PATCH] luarocks wrapper prevents race condition See https://github.com/mxe/mxe/pull/1017#issuecomment-161557440 See http://wiki.bash-hackers.org/howto/mutex --- plugins/luarocks/luarocks.mk | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/luarocks/luarocks.mk b/plugins/luarocks/luarocks.mk index b7cbbae3..10131ee5 100644 --- a/plugins/luarocks/luarocks.mk +++ b/plugins/luarocks/luarocks.mk @@ -33,6 +33,30 @@ define $(PKG)_BUILD_SHARED LUAROCKS_UNAME_S="MXE" \ LUAROCKS_UNAME_M="$(TARGET)" $(MAKE) -C '$(1)' install + + # move installed lua file luarocks to luarocks.lua + mv '$(PREFIX)/$(TARGET)/bin/luarocks' '$(PREFIX)/$(TARGET)/bin/luarocks.lua' + + # create bash wrapper adding inter-process mutex + # see https://github.com/mxe/mxe/pull/1017#issuecomment-161557440 + (echo '#!/usr/bin/env bash'; \ + echo 'echo "== Using MXE wrapper: $(PREFIX)/$(TARGET)/bin/luarocks"'; \ + echo '# Creating a directory is an atomic operation, that is why'; \ + echo '# it can be used as a mutex.'; \ + echo '# See http://wiki.bash-hackers.org/howto/mutex'; \ + echo 'while ( ! mkdir "$(PREFIX)/$(TARGET)/lib/luarocks/lock.dir" ); do'; \ + echo ' echo "Waiting for $(PREFIX)/$(TARGET)/lib/luarocks/lock.dir to lock"'; \ + echo ' sleep 5'; \ + echo 'done'; \ + echo '"$(PREFIX)/$(TARGET)/bin/luarocks.lua" "$$@"'; \ + echo 'rmdir "$(PREFIX)/$(TARGET)/lib/luarocks/lock.dir"'; \ + ) \ + > '$(PREFIX)/$(TARGET)/bin/luarocks' + chmod 0755 '$(PREFIX)/$(TARGET)/bin/luarocks' + # remove lock dir if it exists after previous failed installation + -rmdir "$(PREFIX)/$(TARGET)/lib/luarocks/lock.dir" + + # symlink ln -sf '$(PREFIX)/$(TARGET)/bin/luarocks' '$(PREFIX)/bin/$(TARGET)-luarocks' # create wine wrapper for testing