Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workspace environment support #20900

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tdyas
Copy link
Contributor

@tdyas tdyas commented May 10, 2024

Add support for a "workspace environment" which is similar to a local environment except that execution happens in the repository itself (i.e., the "workspace") and not in an execution sandbox. This implements the user-visible experience of Design B from the "In-Workspace Process Execution" design document.

This PR builds on top of the Rust support for in-workspace execution contained in #20772.

Users will use the new workspace_environment target type to configure workspace execution support.

The pants-workspace-exec-testing repository contains an example of how to use this support to allow Pants to invoke Bazel in the workspace.

Comment on lines 590 to 593
# TODO: This is necessary for tests of `adhoc_tool` and `shell_command` with
# workspace execution to pass repeatedly in local Pants development.
# We need a viable solution instead of this hack.
cache_scope=ProcessCacheScope.PER_SESSION,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjyw: Any ideas on how to fix the test caching issue in the Pants repository and avoid this hack?

@tdyas
Copy link
Contributor Author

tdyas commented May 10, 2024

Only the most recent commit is new. The other commits are from #20772.

@tdyas tdyas force-pushed the shell_workspace_support_2 branch 2 times, most recently from 40dd9d4 to 2808018 Compare May 10, 2024 15:38
@tdyas tdyas force-pushed the shell_workspace_support_2 branch 3 times, most recently from 66e9416 to 3387cae Compare May 22, 2024 02:59
@@ -253,6 +254,33 @@ class AdhocToolOutputRootDirField(StringField):
)


class AdhocToolCacheScopeField(StringField):
Copy link
Contributor Author

@tdyas tdyas May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduction of cache scope to adhoc_tool and shell_command target types should be moved to a separate PR if we decide to keep it. It was necessary to provide a way for tests to set cache_scope to ProcessCacheScope.PER_SESSION in order to avoid cached results from prior tests runs from being used for a current test run.

This points to a more fundamental problem: Will workspace executions which modify the workspace be inherently a problem if the user is looking for them to always execute?

Comment on lines +509 to +653
# HACK: For workspace environments, the `find_binary.sh` will be mounted in the "chroot" directory
# which is not the current directory (since the process will execute in the workspace). Thus,
# adjust the path used as argv[0] to find the script.
script_name = "find_binary.sh"
script_exec_path = (
f"./{script_name}"
if not env_target.is_workspace_environment()
else f"{{chroot}}/{script_name}"
)
Copy link
Contributor Author

@tdyas tdyas May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to handle this subtle difference between workspace environments and every other kind of environment? I believe remote environments do not support the {chroot} replacement so simply using {chroot}/find_binary.sh as the path won't work for all environments.

@tdyas tdyas force-pushed the shell_workspace_support_2 branch from 3387cae to d5286e8 Compare May 23, 2024 16:54
@tdyas tdyas force-pushed the shell_workspace_support_2 branch from d5286e8 to 350d7cf Compare May 24, 2024 03:31
@tdyas tdyas requested a review from a team May 24, 2024 03:33
@tdyas tdyas marked this pull request as ready for review May 24, 2024 03:35
@tdyas tdyas requested a review from benjyw May 24, 2024 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant