]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rustup: handle rustup for sudo and su
authorJason Ish <jason.ish@oisf.net>
Wed, 9 Oct 2019 07:05:24 +0000 (01:05 -0600)
committerJason Ish <jason.ish@oisf.net>
Thu, 10 Oct 2019 22:36:08 +0000 (16:36 -0600)
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.

configure.ac
rust/Makefile.am

index 93cd475f341332020f1cf1fce70f3f30b2d6ed46..0f7abcb3031cd0b1ae902a8a5342c3c11a5f868b 100644 (file)
@@ -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=""
index 3e7ec2eebcaf635ef9d735f614c89d98653492a4..e4f4a3a8e9f52830828a7c386380232b2a25d4be 100644 (file)
@@ -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