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

Change-Id: Ic3abe8ca2dd195c9d501a5dc4c2b785076295af3
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>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 2b547c5..43e2ffa 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -1411,7 +1411,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.