From: Jason Ish Date: Wed, 9 Oct 2019 07:05:24 +0000 (-0600) Subject: rustup: handle rustup for sudo and su X-Git-Tag: suricata-5.0.0~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=389272f4c7c36cbe39d726be4dddf22c398305a9;p=thirdparty%2Fsuricata.git rustup: handle rustup for sudo and su If rustup is in use, and a user uses sudo or su for the make install, the install may fail with a "no default toolchain" error. To prevent this, detect at configure if rustup is being used, then set RUSTUP_HOME for all calls to cargo. --- diff --git a/configure.ac b/configure.ac index 93cd475f34..0f7abcb303 100644 --- a/configure.ac +++ b/configure.ac @@ -2407,6 +2407,26 @@ fi else AC_SUBST([CARGO_HOME], [$CARGO_HOME]) fi + + # Check for rustup. RUSTUP_HOME needs to be set if rustup is in + # use, and a user uses sudo (depending on configuration), or su to + # perform the install + rustup_home_path="no" + if test "x$RUSTUP_HOME" != "x"; then + rustup_home_path="$RUSTUP_HOME" + else + AC_PATH_PROG(have_rustup, rustup, "no") + if test "x$have_rustup" != "xno"; then + rustup_home_path=$($have_rustup show home 2>/dev/null || echo "no") + fi + fi + rustup_home="" + if test "x$rustup_home_path" != "xno"; then + rustup_home="RUSTUP_HOME=\$(RUSTUP_HOME_PATH)" + fi + AC_SUBST([RUSTUP_HOME_PATH], [$rustup_home_path]) + AC_SUBST([rustup_home]) + AC_CHECK_FILES([$srcdir/rust/vendor], [have_rust_vendor="yes"]) if test "x$have_rust_vendor" = "xyes"; then rust_vendor_comment="" diff --git a/rust/Makefile.am b/rust/Makefile.am index 3e7ec2eebc..e4f4a3a8e9 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -33,13 +33,13 @@ if HAVE_PYTHON endif if HAVE_CYGPATH rustpath=`cygpath -a -t mixed $(abs_top_builddir)` - cd $(top_srcdir)/rust && \ + cd $(top_srcdir)/rust && @rustup_home@ \ CARGO_HOME="$(CARGO_HOME)" \ CARGO_TARGET_DIR="$$rustpath/rust/target" \ $(CARGO) build $(RELEASE) $(FROZEN) \ --features "$(RUST_FEATURES)" else - cd $(top_srcdir)/rust && \ + cd $(top_srcdir)/rust && @rustup_home@ \ CARGO_HOME="$(CARGO_HOME)" \ CARGO_TARGET_DIR="$(abs_top_builddir)/rust/target" \ $(CARGO) build $(RELEASE) $(FROZEN) \ @@ -53,14 +53,15 @@ distclean-local: clean-local rm -rf vendor gen Cargo.lock check: - CARGO_HOME="$(CARGO_HOME)" $(CARGO) test + CARGO_HOME="$(CARGO_HOME)" @rustup_home@ $(CARGO) test Cargo.lock: Cargo.toml - CARGO_HOME="$(CARGO_HOME)" $(CARGO) generate-lockfile + CARGO_HOME="$(CARGO_HOME)" @rustup_home@ $(CARGO) \ + generate-lockfile if HAVE_CARGO_VENDOR vendor: - CARGO_HOME="$(CARGO_HOME)" $(CARGO) vendor > /dev/null + CARGO_HOME="$(CARGO_HOME)" @rustup_home@ $(CARGO) vendor > /dev/null else vendor: endif