about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-10-17 22:57:30 +0000
committerbors <bors@rust-lang.org>2014-10-17 22:57:30 +0000
commit9b80efd74eb1246189aa256c76b4e2ece4410969 (patch)
tree2a4e8e563a5f83b1263776739680a33e70270e66
parent4694b9910279f5af7dd9c4616b5870c82aead7f0 (diff)
parent23c26617cbd073847c5f6d819157773d9272b41c (diff)
downloadrust-9b80efd74eb1246189aa256c76b4e2ece4410969.tar.gz
rust-9b80efd74eb1246189aa256c76b4e2ece4410969.zip
auto merge of #17009 : kballard/rust/install_no_sudo, r=pnkfelix
When running `sudo make install`, we only want to run the actual install
as root, the building of the documentation and the distribution folder
should happen as the non-root user.

Related to #13728.
-rw-r--r--mk/install.mk26
1 files changed, 22 insertions, 4 deletions
diff --git a/mk/install.mk b/mk/install.mk
index ddbbac49543..88b451f661a 100644
--- a/mk/install.mk
+++ b/mk/install.mk
@@ -14,16 +14,34 @@ else
 MAYBE_DISABLE_VERIFY=
 endif
 
-install: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir
+install:
+ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
+# Build the dist as the original user
+	$(Q)sudo -u "$$SUDO_USER" $(MAKE) prepare_install
+else
+	$(Q)$(MAKE) prepare_install
+endif
 	$(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)" "$(MAYBE_DISABLE_VERIFY)"
-# Remove tmp files while we can because they may have been created under sudo
+# Remove tmp files because it's a decent amount of disk space
 	$(Q)rm -R tmp/dist
 
-uninstall: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir
+prepare_install: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir
+
+uninstall:
+ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
+# Build the dist as the original user
+	$(Q)sudo -u "$$SUDO_USER" $(MAKE) prepare_uninstall
+else
+	$(Q)$(MAKE) prepare_uninstall
+endif
 	$(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)"
-# Remove tmp files while we can because they may have been created under sudo
+# Remove tmp files because it's a decent amount of disk space
 	$(Q)rm -R tmp/dist
 
+prepare_uninstall: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir
+
+.PHONY: install prepare_install uninstall prepare_uninstall
+
 tmp/empty_dir:
 	mkdir -p $@