Skip to content

Commit

Permalink
introduce CMake BinaryTool and use it to fully isolate the environmen…
Browse files Browse the repository at this point in the history
…t when building conan deps
  • Loading branch information
cosmicexplorer committed Oct 19, 2018
1 parent 4fc332c commit 53a8013
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
20 changes: 20 additions & 0 deletions src/python/pants/backend/native/subsystems/binaries/cmake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding=utf-8
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import absolute_import, division, print_function, unicode_literals

import os

from pants.binaries.binary_tool import NativeTool
from pants.util.memo import memoized_property


class CMake(NativeTool):
options_scope = 'cmake'
default_version = '3.9.5'
archive_type = 'tgz'

@memoized_property
def bin_dir(self):
return os.path.join(self.select(), 'bin')
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pex.interpreter import PythonInterpreter

from pants.backend.native.config.environment import LLVMCppToolchain, Platform
from pants.backend.native.subsystems.binaries.cmake import CMake
from pants.backend.native.subsystems.conan import Conan
from pants.backend.native.subsystems.native_toolchain import NativeToolchain
from pants.backend.native.targets.external_native_library import ExternalNativeLibrary
Expand Down Expand Up @@ -88,6 +89,7 @@ class NativeExternalLibraryFetch(NativeTask):
@classmethod
def subsystem_dependencies(cls):
return super(NativeExternalLibraryFetch, cls).subsystem_dependencies() + (
CMake.scoped(cls),
Conan.scoped(cls),
NativeToolchain.scoped(cls),
)
Expand Down Expand Up @@ -121,18 +123,21 @@ def _native_toolchain(self):
def _cpp_toolchain(self):
return self._request_single(LLVMCppToolchain, self._native_toolchain).cpp_toolchain

@memoized_property
def _cmake(self):
return CMake.scoped_instance(self)

@memoized_property
def _build_environment(self):
cpp_compiler = self._cpp_toolchain.cpp_compiler
cpp_linker = self._cpp_toolchain.cpp_linker
# Compose the invocation environments.
invocation_env_dict = cpp_compiler.as_invocation_environment_dict.copy()
invocation_env_dict.update(cpp_linker.as_invocation_environment_dict)
invocation_env_dict.update({
'PATH': create_path_env_var((cpp_compiler.path_entries + cpp_linker.path_entries),
os.environ.copy(),
prepend=True),
})
invocation_env_dict['PATH'] = create_path_env_var((
cpp_compiler.path_entries +
cpp_linker.path_entries +
[self._cmake.bin_dir]))
return invocation_env_dict

class NativeExternalLibraryFetchError(TaskError):
Expand Down
14 changes: 1 addition & 13 deletions src/python/pants/backend/python/subsystems/python_native_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

from pex.pex import PEX

from pants.backend.native.config.environment import CppToolchain, CToolchain, Platform
from pants.backend.native.config.environment import CppToolchain, CToolchain
from pants.backend.native.subsystems.native_toolchain import NativeToolchain
from pants.backend.native.subsystems.xcode_cli_tools import MIN_OSX_VERSION_ARG
from pants.backend.native.targets.native_library import NativeLibrary
from pants.backend.python.python_requirement import PythonRequirement
from pants.backend.python.subsystems.python_setup import PythonSetup
Expand Down Expand Up @@ -159,7 +158,6 @@ def base_requirements(self):
class SetupPyNativeTools(datatype([
('c_toolchain', CToolchain),
('cpp_toolchain', CppToolchain),
('platform', Platform),
])):
"""The native tools needed for a setup.py invocation.
Expand All @@ -175,16 +173,6 @@ class SetupPyExecutionEnvironment(datatype([
'setup_py_native_tools',
])):

_SHARED_CMDLINE_ARGS = {
'darwin': lambda: [
MIN_OSX_VERSION_ARG,
'-Wl,-dylib',
'-undefined',
'dynamic_lookup',
],
'linux': lambda: ['-shared'],
}

def as_environment(self):
ret = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ def _prepare_and_create_dist(self, interpreter, shared_libs_product, versioned_t
# TODO: test this branch somehow!
native_tools = SetupPyNativeTools(
c_toolchain=self._c_toolchain,
cpp_toolchain=self._cpp_toolchain,
platform=self._platform)
cpp_toolchain=self._cpp_toolchain)
# Native code in this python_dist() target requires marking the dist as platform-specific.
is_platform_specific = True
elif len(all_native_artifacts) > 0:
Expand Down

0 comments on commit 53a8013

Please sign in to comment.