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

Move PlatformConstraint to a param. #8375

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/python/pants/backend/python/rules/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
DirectoryWithPrefixToAdd,
)
from pants.engine.isolated_process import ExecuteProcessResult, MultiPlatformExecuteProcessRequest
from pants.engine.platform import Platform, PlatformConstraint
from pants.engine.platform import PlatformConstraint
from pants.engine.rules import optionable_rule, rule
from pants.engine.selectors import Get

Expand Down Expand Up @@ -46,7 +46,7 @@ def create_pex(
python_setup: PythonSetup,
subprocess_encoding_environment: SubprocessEncodingEnvironment,
pex_build_environment: PexBuildEnvironment,
platform: Platform
platform: PlatformConstraint
) -> Pex:
"""Returns a PEX with the given requirements, optional entry point, and optional
interpreter constraints."""
Expand All @@ -68,8 +68,12 @@ def create_pex(
all_inputs = (pex_bin.directory_digest, sources_digest_as_subdir,)
merged_digest = yield Get(Digest, DirectoriesToMerge(directories=all_inputs))

# ignore none constraint if some rule pushes a constraint down as none.
if platform == PlatformConstraint.none:
platform = PlatformConstraint.local_platform

# NB: PEX outputs are platform dependent so in order to get a PEX that we can use locally, without
# cross-building we specify that out PEX command be run on the current local platform. When we
# cross-building, we specify that our PEX command be run on the current local platform. When we
# support cross-building through CLI flags we can configure requests that build a PEX for out
# local platform that are able to execute on a different platform, but for now in order to
# guarantee correct build we need to restrict this command to execute on the same platform type
Expand All @@ -79,7 +83,7 @@ def create_pex(
# constraint`".
execute_process_request = MultiPlatformExecuteProcessRequest(
{
(PlatformConstraint(platform.value), PlatformConstraint(platform.value)):
(platform, platform):
pex_bin.create_execute_request(
python_setup=python_setup,
subprocess_encoding_environment=subprocess_encoding_environment,
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/engine/platform.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from pants.engine.rules import rule
from pants.engine.rules import RootRule, rule
from pants.util.memo import memoized_classproperty, memoized_property
from pants.util.objects import enum
from pants.util.osutil import all_normalized_os_names, get_normalized_os_name
Expand Down Expand Up @@ -36,4 +36,4 @@ def materialize_platform() -> Platform:


def create_platform_rules():
return [materialize_platform]
return [materialize_platform, RootRule(PlatformConstraint)]
9 changes: 6 additions & 3 deletions src/python/pants/init/engine_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from pants.engine.legacy.structs import rules as structs_rules
from pants.engine.mapper import AddressMapper
from pants.engine.parser import SymbolTable
from pants.engine.platform import create_platform_rules
from pants.engine.platform import PlatformConstraint, create_platform_rules
from pants.engine.rules import RootRule, UnionMembership, rule
from pants.engine.scheduler import Scheduler
from pants.engine.selectors import Params
Expand Down Expand Up @@ -199,14 +199,17 @@ def run_console_rules(self, options_bootstrapper, goals, target_roots):
:returns: An exit code.
"""
subject = target_roots.specs
global_options = options_bootstrapper.bootstrap_options.for_global_scope()
console = Console(
use_colors=options_bootstrapper.bootstrap_options.for_global_scope().colors
use_colors=global_options.colors
)
target_platform_constraint = PlatformConstraint.local_platform
workspace = Workspace(self.scheduler_session)

for goal in goals:
goal_product = self.goal_map[goal]
params = Params(subject, options_bootstrapper, console, workspace)
params = Params(subject, options_bootstrapper, console,
workspace, target_platform_constraint)
logger.debug(f'requesting {goal_product} to satisfy execution of `{goal}` goal')
try:
exit_code = self.scheduler_session.run_console_rule(goal_product, params)
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/option/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pants.option.scope import ScopeInfo
from pants.subsystem.subsystem_client_mixin import SubsystemClientMixin
from pants.util.objects import enum
from pants.util.osutil import all_normalized_os_names, get_normalized_os_name


class GlobMatchErrorBehavior(enum(['ignore', 'warn', 'error'])):
Expand Down
1 change: 1 addition & 0 deletions tests/python/pants_test/backend/python/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python_tests(
'src/python/pants/backend/python/rules',
'src/python/pants/backend/python/subsystems',
'src/python/pants/engine:fs',
'src/python/pants/engine:platform',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/util:collections',
Expand Down
4 changes: 3 additions & 1 deletion tests/python/pants_test/backend/python/rules/test_pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from pants.engine.fs import Digest, DirectoryToMaterialize, FileContent, InputFilesContent
from pants.engine.isolated_process import ExecuteProcessRequest, ExecuteProcessResult
from pants.engine.platform import PlatformConstraint
from pants.engine.rules import RootRule
from pants.engine.selectors import Params
from pants.util.collections import assert_single_element
Expand Down Expand Up @@ -64,7 +65,8 @@ def hashify_optional_collection(iterable):
request,
PythonSetup.global_instance(),
SubprocessEnvironment.global_instance(),
PythonNativeCode.global_instance()
PythonNativeCode.global_instance(),
PlatformConstraint.local_platform,
)])
)
with temporary_dir() as tmp_dir:
Expand Down
1 change: 1 addition & 0 deletions tests/python/pants_test/engine/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ python_tests(
name='isolated_process',
sources=['test_isolated_process.py'],
dependencies=[
'3rdparty/python:dataclasses',
'src/python/pants/engine:fs',
'src/python/pants/engine:isolated_process',
'src/python/pants/engine:rules',
Expand Down