104104
105105.PHONY : deps clean-deps update-deps
106106
107+ # Make really doesn't handle spaces in filenames well.
108+ # Using $(realpath) exposes make to spaces in directory names above this one.
109+ # Though we might prefer to use $(realpath), this function operates a fallback
110+ # so that the full path is not used if there are spaces in directory names.
111+ ifeq ($(words $(realpath $(LIBDIR ) ) ) ,1)
112+ safe-realpath = $(realpath $(1 ) )
113+ relative-paths := false
114+ else
115+ ifneq (,$(DISABLE_SPACES_WARNING ) )
116+ $(warning Your $$LIBDIR ($(LIBDIR)) contains spaces; some things might break.)
117+ endif
118+ safe-realpath = $(1 )
119+ relative-paths := true
120+ endif
121+
107122ifeq (true,$(DISABLE_CACHE ) )
108123no-cache := --no-cache
109124no-cache-dir := --no-cache-dir
@@ -114,10 +129,10 @@ endif
114129
115130ifeq (true,$(CI ) )
116131# Override VENVDIR so we can use caching in CI.
117- VENVDIR = $(realpath .) /.venv
132+ VENVDIR = $(call safe-realpath, .) /.venv
118133endif
119134
120- VENVDIR ?= $(realpath $(LIBDIR ) ) /.venv
135+ VENVDIR ?= $(call safe-realpath, $(LIBDIR ) ) /.venv
121136REQUIREMENTS_TXT := $(wildcard requirements.txt)
122137
123138ifneq (,$(strip $(REQUIREMENTS_TXT ) ) )
@@ -137,7 +152,7 @@ ifeq (true,$(CI))
137152# Under CI, install from the local requirements.txt, but install globally (no venv).
138153pip ?= pip3
139154$(LOCAL_VENV ) :
140- $(pip ) install $(no-cache-dir ) $(foreach path,$(REQUIREMENTS_TXT ) ,-r $(path ) )
155+ " $( pip) " install --no-user $(no-cache-dir ) $(foreach path,$(REQUIREMENTS_TXT ) ,-r $(path ) )
141156 @touch $@
142157
143158# No clean-deps target in CI..
@@ -162,8 +177,8 @@ endif
162177clean-deps :: clean-venv
163178endif # CI
164179update-deps ::
165- $(pip ) install $(no-cache-dir ) --upgrade --upgrade-strategy eager \
166- $(foreach path,$(REQUIREMENTS_TXT ) ,-r $(path ) )
180+ " $( pip) " install --no-user $(no-cache-dir ) --upgrade --upgrade-strategy eager \
181+ $(foreach path,$(REQUIREMENTS_TXT ) ,-r " $(path ) " )
167182endif # -e requirements.txt
168183
169184# Variable defaults for CI
@@ -183,42 +198,55 @@ BUNDLE_IGNORE_MESSAGES := true
183198export BUNDLE_IGNORE_MESSAGES
184199ifeq (true,$(CI ) )
185200# Override BUNDLE_PATH so we can use caching in CI.
186- BUNDLE_PATH := $(realpath .) /.gems
201+ BUNDLE_PATH := $(call safe-realpath, .) /.gems
187202BUNDLE_DISABLE_VERSION_CHECK := true
188203export BUNDLE_DISABLE_VERSION_CHECK
189204endif
190- export BUNDLE_PATH ?= $(realpath $(LIBDIR ) ) /.gems
205+ BUNDLE_PATH ?= $(call safe-realpath, $(LIBDIR ) ) /.gems
191206# Install binaries to somewhere sensible instead of .../ruby/$v/bin where $v
192207# doesn't even match the current ruby version.
193- export BUNDLE_BIN := $(BUNDLE_PATH ) /bin
208+ BUNDLE_BIN := $(BUNDLE_PATH ) /bin
194209export PATH := $(BUNDLE_BIN ) :$(PATH )
210+ ifeq (true,$(relative-paths ) )
211+ # This means that BUNDLE_PATH is relative, which bundler will interpret
212+ # as being relative to the Gemfile, not the current directory, so tweak
213+ # the two path settings for bundler. After setting $PATH.
214+ # Thankfully, we don't install from $(LIBDIR)/Gemfile in CI, which
215+ # would mean that this would need to be "../.gems" there.
216+ $(warning Using a relative path for bundler)
217+ bundle-path-override-lib := BUNDLE_PATH=$(LIBDIR ) /.gems BUNDLE_BIN=$(LIBDIR ) /.gems/bin
218+ bundle-path-override := BUNDLE_PATH=.gems BUNDLE_BIN=.gems/bin
219+ endif
220+ export BUNDLE_PATH
221+ export BUNDLE_BIN
222+
195223
196224ifneq (,$(wildcard Gemfile) )
197225# A local Gemfile exists.
198226DEPS_FILES += Gemfile.lock
199227Gemfile.lock : Gemfile
200- bundle install $(no-cache ) --gemfile=$( realpath $< )
228+ $( bundle-path-override-lib ) bundle install $(no-cache ) --gemfile=" $( call safe-realpath, $< ) "
201229 @touch $@
202230
203231update-deps :: Gemfile
204- bundle update $(bundle-update-all ) --gemfile=$( realpath $< )
232+ $( bundle-path-override-lib ) bundle update $(bundle-update-all ) --gemfile=" $( call safe-realpath, $< ) "
205233
206234clean-deps ::
207- -rm -rf $(BUNDLE_PATH )
235+ -rm -rf " $( BUNDLE_PATH) "
208236endif # Gemfile
209237
210238ifneq (true,$(CI ) )
211239# Install kramdown-rfc.
212240DEPS_FILES += $(LIBDIR ) /Gemfile.lock
213241$(LIBDIR ) /Gemfile.lock : $(LIBDIR ) /Gemfile
214- bundle install $(no-cache ) --gemfile=$( realpath $< )
242+ $( bundle-path-override ) bundle install $(no-cache ) --gemfile=" $( call safe-realpath, $< ) "
215243 @touch $@
216244
217245update-deps :: $(LIBDIR ) /Gemfile
218- bundle update $(bundle-update-all ) --gemfile=$( realpath $< )
246+ $( bundle-path-override ) bundle update $(bundle-update-all ) --gemfile=" $( call safe-realpath, $< ) "
219247
220248clean-deps ::
221- -rm -rf $(BUNDLE_PATH )
249+ -rm -rf " $( BUNDLE_PATH) "
222250endif # !CI
223251endif # !NO_RUBY
224252
@@ -232,8 +260,8 @@ NO_NODEJS := true
232260endif
233261
234262ifneq (true,$(NO_NODEJS ) )
235- ifneq (,$(wildcard package.json) )
236263export PATH := $(abspath node_modules/.bin) :$(PATH )
264+ ifneq (,$(wildcard package.json) )
237265DEPS_FILES += package-lock.json
238266package-lock.json : package.json
239267 npm install
0 commit comments