<#20458 Add an option to create a symlink to the b...
# github-notifications
c
#20458 Add an option to create a symlink to the build root sandbox directory in the workspace directory Issue created by AlexTereshenkov Is your feature request related to a problem? Please describe. When running a Pants goal, it is possible to ask Pants to keep a sandbox, created by default in the temp directory, after the goal is complete (they are normally deleted), see keep_sandboxes. These directories are referred to as "local directories used as chroots for running processes".
Copy code
$ pants --keep-sandboxes=always test tests/repository/parsing/test_casts.py
16:13:37.11 [INFO] waiting for pantsd to start...
16:13:37.31 [INFO] pantsd started
16:13:37.35 [INFO] Preserving local process execution dir /tmp/pants-sandbox-OoKpm6 for Searching for `bash` on PATH=/usr/bin:/bin:/usr/local/bin
16:13:37.36 [INFO] Preserving local process execution dir /tmp/pants-sandbox-5e0IW0 for Test binary /usr/bin/bash.
16:13:37.36 [INFO] Preserving local process execution dir /tmp/pants-sandbox-g6oXcE for Test binary /bin/bash.
[removed for brevity]
16:13:43.38 [INFO] Preserving local process execution dir /tmp/pants-sandbox-HOXnMe for Searching for `bash` on PATH=/usr/bin:/bin:/usr/local/bin
16:13:43.39 [INFO] Preserving local process execution dir /tmp/pants-sandbox-sCspHw for Test binary /bin/bash.
16:13:43.39 [INFO] Preserving local process execution dir /tmp/pants-sandbox-ogABFs for Test binary /usr/bin/bash.
16:13:44.96 [INFO] Preserving local process execution dir /tmp/pants-sandbox-Lp7oNC for Run Pytest for tests/repository/parsing/test_casts.py:tests
16:13:43.41 [INFO] Completed: Run Pytest - tests/repository/parsing/test_casts.py:tests - succeeded.

✓ tests/repository/parsing/test_casts.py:tests succeeded in 0.25s.
by reading through the logs, we can see
16:13:44.96 [INFO] Preserving local process execution dir /tmp/pants-sandbox-Lp7oNC for Run Pytest for tests/repository/parsing/test_casts.py:tests
which is what would be most often of interest to a user. The directory is useful for debugging tests; for instance, your BUILD files metadata is incomplete and some of the files are not copied. By inspecting the directory, you'll be able to see the missing files and what files are copied.
Copy code
$ tree /tmp/pants-sandbox-Lp7oNC -L 2
/tmp/pants-sandbox-Lp7oNC
├── cheeseshop
│   ├── __init__.py
│   ├── __pycache__
│   └── repository
├── extra-output
├── local_dists.pex
│   ├── __main__.py
│   ├── __pex__
│   └── PEX-INFO
├── pytest.pex
│   ├── __main__.py
│   ├── __pex__
│   └── PEX-INFO
├── pytest_runner.pex
│   ├── __main__.py
│   ├── __pex__
│   └── PEX-INFO
├── pytest_runner.pex_bin_python_shim.sh
├── pytest_runner.pex_pex_shim.sh
├── requirements.pex
│   ├── __main__.py
│   ├── __pex__
│   └── PEX-INFO
├── __run.sh
├── tests
│   ├── __init__.py
│   ├── __pycache__
│   └── repository
└── tests.repository.parsing.test_casts.py.tests.xml

16 directories, 14 files
To get to this sandbox directory, reading through the log is required and then copying/pasting path to that directory. Upon subsequent re-runs, a new directory is created meaning that you have to repeat the search. For the user's convenience, we could create a symlink in the workspace directory which would point to the latest sandbox used. Pants itself won't use them. Of course, writing to the workspace would take place only if the workspace root is writable. So in addition to the
dist
directory containing the binary artifacts, we could have a
.pants-sandbox
symlink or something along these lines which would point to that
/tmp/pants-sandbox-Lp7oNC
directory and any other directory that was used as a sandbox in the last Pants run. This means user would be able to see the contents of the directory all the time and see how it changes as the changes to the build metadata and source code are made. This should help with debugging tests. Describe the solution you'd like Have an option that would enable creating a symlink in the workspace directory which would point to the latest sandbox used. Describe alternatives you've considered The current approach implies parsing the goal log, copying the path to the sandbox, and listing its contents. This could be automated to some extent. Additional context FWIW this is done in Bazel, see https://bazel.build/remote/output-directories#layout-diagram pantsbuild/pants