Skip to content

Commit

Permalink
plugin release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
tdyas committed May 10, 2024
1 parent 8a44531 commit 40dd9d4
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 36 deletions.
13 changes: 13 additions & 0 deletions docs/notes/2.22.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We offer [formal sponsorship tiers for companies](https://www.pantsbuild.org/spo
### Highlights

- A new implementation of the options system.
- In-workspace execution of processes via `workspace_environment` target type.

### New options system

Expand All @@ -22,6 +23,16 @@ The two systems are expected to be more-or-less functionally identical. We plan

If you encounter such discrepancies, and you can't resolve them easily, please [reach out to us on Slack or file an issue](https://www.pantsbuild.org/community/getting-help).

### Environments: In-Workspace Execution

Pants now supports executing processes locally within the repository itself via the new "workspace" environment which is configured by the new `workspace_environment` target type. The primary motivation for this feature is to better support integration with third-party build orchestration tools (e.g., Bazel) which may not operate properly when not invoked in the repository (including in some cases signifcant performance penalties).

There is a significant trade-off though: Pants cannot reasonbly guarantee that build processes are reproducible if they run in the workspace
environment. Thus, Pants puts that burden on you, the Pants user, to guarantee that any process executed in the workspace environment is reproducible
based solely on inputs in the repository. If a process is not reproducible, then unknown side effects may occur.

**Thus, this feature is inherently UNSAFE.**

### Backends

#### JVM
Expand Down Expand Up @@ -58,6 +69,8 @@ Setting [the `orphan_files_behaviour = "ignore"` option](https://www.pantsbuild.

### Plugin API changes

The process execution intrinsic rule in Rust now contains support for "workspace" execution. This is local execution from within the repository itself without using an execution sandbox. `ProcessExecutionEnvironment`'s constructor has a new `execute_in_workspace` parameter which enables workspace execution.

## Full Changelog

For the full changelog, see the individual GitHub Releases for this series: https://github.com/pantsbuild/pants/releases
32 changes: 32 additions & 0 deletions src/python/pants/backend/adhoc/adhoc_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

from pathlib import Path
from textwrap import dedent

import pytest
Expand All @@ -17,6 +18,7 @@
from pants.core.target_types import rules as core_target_type_rules
from pants.core.util_rules import archive, source_files
from pants.core.util_rules.adhoc_process_support import AdhocProcessRequest
from pants.core.util_rules.environments import LocalWorkspaceEnvironmentTarget
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
from pants.engine.addresses import Address
from pants.engine.fs import EMPTY_SNAPSHOT, DigestContents
Expand Down Expand Up @@ -52,6 +54,7 @@ def rule_runner() -> PythonRuleRunner:
ArchiveTarget,
FilesGeneratorTarget,
PythonSourceTarget,
LocalWorkspaceEnvironmentTarget,
],
)
rule_runner.set_options([], env_inherit={"PATH"})
Expand Down Expand Up @@ -302,3 +305,32 @@ def test_execution_dependencies_and_runnable_dependencies(rule_runner: PythonRul
Address("b", target_name="deps"),
expected_contents={"b/stdout": file_contents},
)


def test_adhoc_tool_with_workspace_execution(rule_runner: PythonRuleRunner) -> None:
rule_runner.write_files(
{
"BUILD": dedent(
"""
system_binary(name="bash", binary_name="bash")
adhoc_tool(
name="make-file",
runnable=":bash",
args=["-c", "echo 'workspace' > ./foo.txt"],
environment="workspace",
stderr="stderr",
)
workspace_environment(name="workspace")
"""
)
}
)
rule_runner.set_options(
["--environments-preview-names={'workspace': '//:workspace'}"], env_inherit={"PATH"}
)

assert_adhoc_tool_result(rule_runner, Address("", target_name="make-file"), {"stderr": ""})

workspace_output_path = Path(rule_runner.build_root).joinpath("foo.txt")
assert workspace_output_path.exists()
assert workspace_output_path.read_text().strip() == "workspace"
35 changes: 35 additions & 0 deletions src/python/pants/backend/shell/util_rules/shell_command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import logging
import shlex
from pathlib import Path
from textwrap import dedent

import pytest
Expand All @@ -26,6 +27,7 @@
from pants.core.target_types import rules as core_target_type_rules
from pants.core.util_rules import archive, source_files
from pants.core.util_rules.adhoc_process_support import AdhocProcessRequest
from pants.core.util_rules.environments import LocalWorkspaceEnvironmentTarget
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
from pants.engine.addresses import Address
from pants.engine.environment import EnvironmentName
Expand Down Expand Up @@ -65,6 +67,7 @@ def rule_runner() -> RuleRunner:
ShellSourcesGeneratorTarget,
ArchiveTarget,
FilesGeneratorTarget,
LocalWorkspaceEnvironmentTarget,
],
)
rule_runner.set_options([], env_inherit={"PATH"})
Expand Down Expand Up @@ -837,3 +840,35 @@ def test_working_directory_special_values(
Address("src", target_name="workdir"),
expected_contents={"out.log": f"{expected_dir}\n"},
)


def test_shell_command_with_workspace_execution(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"BUILD": dedent(
"""
shell_command(
name="make-file",
command="echo workspace > foo.txt && echo sandbox > {chroot}/out.log",
output_files=["out.log"],
environment="workspace",
)
workspace_environment(name="workspace")
"""
)
}
)
rule_runner.set_options(
["--environments-preview-names={'workspace': '//:workspace'}", "--no-local-cache"],
env_inherit={"PATH"},
)

print(f"build root = {rule_runner.build_root}")
assert_shell_command_result(
rule_runner,
Address("", target_name="make-file"),
expected_contents={"out.log": "sandbox\n"},
)
workspace_output_path = Path(rule_runner.build_root).joinpath("foo.txt")
assert workspace_output_path.exists()
assert workspace_output_path.read_text().strip() == "workspace"
2 changes: 2 additions & 0 deletions src/python/pants/core/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from pants.core.util_rules.environments import (
DockerEnvironmentTarget,
LocalEnvironmentTarget,
LocalWorkspaceEnvironmentTarget,
RemoteEnvironmentTarget,
)
from pants.core.util_rules.wrap_source import wrap_source_rule_and_target
Expand Down Expand Up @@ -113,6 +114,7 @@ def target_types():
FileTarget,
GenericTarget,
LocalEnvironmentTarget,
LocalWorkspaceEnvironmentTarget,
LockfilesGeneratorTarget,
LockfileTarget,
RelocatedFiles,
Expand Down
12 changes: 11 additions & 1 deletion src/python/pants/core/util_rules/adhoc_process_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
Snapshot,
)
from pants.engine.internals.native_engine import AddressInput, RemovePrefix
from pants.engine.process import FallibleProcessResult, Process, ProcessResult, ProductDescription
from pants.engine.process import (
FallibleProcessResult,
Process,
ProcessCacheScope,
ProcessResult,
ProductDescription,
)
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import (
FieldSetsPerTarget,
Expand Down Expand Up @@ -581,6 +587,10 @@ async def prepare_adhoc_process(
working_directory=working_directory,
append_only_caches=append_only_caches,
immutable_input_digests=immutable_input_digests,
# 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,
)

return _output_at_build_root(proc, bash)
Expand Down

0 comments on commit 40dd9d4

Please sign in to comment.