scripts: cros_setup_toolchains: Stash temporary structure at |root|

/tmp is moving to a different mount than root (/), so hard links from
root to /tmp will stop working. It'd be rather involved to rewrite this
script to avoid hard links without sacrificing a ton of duplicate I/O
(copying files instead).

But this step is only for SDK/toolchain builders, which necessarily will
perform read/write operations on the SDK. So the concerns that are
driving the SDK-vs-state separation are less relevant here.

BUG=b:282231712
TEST=`sudo cros_setup_toolchains --debug --create-packages \
	   --output-dir /tmp/toolchain-pkgs` with /tmp as a distinct
     mount from /
TEST=chromiumos-sdk-tryjob

Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4545343
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
(cherry picked from commit ca274dd7eff8fe212acebc1aff76c10698881d47)
Change-Id: I6142684e6bcaa7713283d1a6ed34614979c6c72c
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index d3bf0ef..14d568c 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -1410,7 +1410,10 @@
     ldpaths = lddtree.LoadLdpaths(root)
     targets = ExpandTargets(targets_wanted)
 
-    with osutils.TempDir(prefix="create-packages") as tempdir:
+    # b/282231712: Stash temporary path structure at |root|, so we have control
+    # over cross-device linking. The default base directory (/tmp) might be on
+    # a different filesystem/mount, so hard links won't work.
+    with osutils.TempDir(base_dir=root, prefix="create-packages") as tempdir:
         logging.debug("Using tempdir: %s", tempdir)
 
         # We have to split the root generation from the compression stages.