Skip to content

Commit

Permalink
Add global option process_extra_env (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
grihabor authored Oct 5, 2024
1 parent 43bfed3 commit 4ddb67b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions tags/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ let
patch -p1 --batch -u -i ${./patch-coursier-fetch.txt}
patch -p1 --batch -u -i ${./patch-process.txt}
patch -p1 --batch -u -i ${./patch-jdk-sh.txt}
patch -p1 --batch -u -i ${./patch-process-extra-env-2.22.txt}
'';

preBuild = ''
Expand Down
46 changes: 46 additions & 0 deletions tags/patch-process-extra-env-2.22.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/src/python/pants/engine/intrinsics.py b/src/python/pants/engine/intrinsics.py
index b99e1a682a..1114d86de4 100644
--- a/src/python/pants/engine/intrinsics.py
+++ b/src/python/pants/engine/intrinsics.py
@@ -97,15 +97,19 @@ async def add_prefix_request_to_digest(add_prefix: AddPrefix) -> Digest:
return await native_engine.add_prefix_request_to_digest(add_prefix)


+import dataclasses
+from pants.option.global_options import GlobalOptions
@rule
async def process_request_to_process_result(
- process: Process, process_execution_environment: ProcessExecutionEnvironment
+ process: Process,
+ process_execution_environment: ProcessExecutionEnvironment,
+ options: GlobalOptions,
) -> FallibleProcessResult:
+ process = dataclasses.replace(process, env={**process.env, **options.process_extra_env})
return await native_engine.process_request_to_process_result(
process, process_execution_environment
)

-
@rule
async def digest_subset_to_digest(digest_subset: DigestSubset) -> Digest:
return await native_engine.digest_subset_to_digest(digest_subset)
diff --git a/src/python/pants/option/global_options.py b/src/python/pants/option/global_options.py
index 364d4366a0..a1e279e2e6 100644
--- a/src/python/pants/option/global_options.py
+++ b/src/python/pants/option/global_options.py
@@ -1964,6 +1964,15 @@ class GlobalOptions(BootstrapOptions, Subsystem):
default=[],
)

+ process_extra_env = DictOption[str](
+ advanced=True,
+ help=softwrap(
+ """
+ Extra environment variables for every Process call.
+ """
+ )
+ )
+
@classmethod
def validate_instance(cls, opts):
"""Validates an instance of global options for cases that are not prohibited via
41 changes: 41 additions & 0 deletions tags/patch-process-extra-env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/src/python/pants/engine/intrinsics.py b/src/python/pants/engine/intrinsics.py
index 5695a3baf..2d14b9314 100644
--- a/src/python/pants/engine/intrinsics.py
+++ b/src/python/pants/engine/intrinsics.py
@@ -100,10 +100,15 @@ async def add_prefix(add_prefix: AddPrefix) -> Digest:
return await native_engine.add_prefix(add_prefix)


+import dataclasses
+from pants.option.global_options import GlobalOptions
@rule
async def execute_process(
- process: Process, process_execution_environment: ProcessExecutionEnvironment
+ process: Process,
+ process_execution_environment: ProcessExecutionEnvironment,
+ options: GlobalOptions,
) -> FallibleProcessResult:
+ process = dataclasses.replace(process, env={**process.env, **options.process_extra_env})
return await native_engine.execute_process(process, process_execution_environment)


diff --git a/src/python/pants/option/global_options.py b/src/python/pants/option/global_options.py
index 6ae7843a9..3e397534b 100644
--- a/src/python/pants/option/global_options.py
+++ b/src/python/pants/option/global_options.py
@@ -1998,6 +1998,15 @@ class GlobalOptions(BootstrapOptions, Subsystem):
default=[],
)

+ process_extra_env = DictOption[str](
+ advanced=True,
+ help=softwrap(
+ """
+ Extra environment variables for every Process call.
+ """
+ )
+ )
+
@classmethod
def validate_instance(cls, opts):
"""Validates an instance of global options for cases that are not prohibited via

0 comments on commit 4ddb67b

Please sign in to comment.