From 53a8013e54b00b78363fb5e607357990e81d9d57 Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Fri, 19 Oct 2018 12:42:11 -0700 Subject: [PATCH] introduce CMake BinaryTool and use it to fully isolate the environment when building conan deps --- .../native/subsystems/binaries/cmake.py | 20 +++++++++++++++++++ .../tasks/native_external_library_fetch.py | 15 +++++++++----- .../python/subsystems/python_native_code.py | 14 +------------ .../tasks/build_local_python_distributions.py | 3 +-- 4 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 src/python/pants/backend/native/subsystems/binaries/cmake.py diff --git a/src/python/pants/backend/native/subsystems/binaries/cmake.py b/src/python/pants/backend/native/subsystems/binaries/cmake.py new file mode 100644 index 000000000000..e70a3afa33fc --- /dev/null +++ b/src/python/pants/backend/native/subsystems/binaries/cmake.py @@ -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') diff --git a/src/python/pants/backend/native/tasks/native_external_library_fetch.py b/src/python/pants/backend/native/tasks/native_external_library_fetch.py index d6ecbaba1d60..6c2dd5efdf7e 100644 --- a/src/python/pants/backend/native/tasks/native_external_library_fetch.py +++ b/src/python/pants/backend/native/tasks/native_external_library_fetch.py @@ -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 @@ -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), ) @@ -121,6 +123,10 @@ 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 @@ -128,11 +134,10 @@ def _build_environment(self): # 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): diff --git a/src/python/pants/backend/python/subsystems/python_native_code.py b/src/python/pants/backend/python/subsystems/python_native_code.py index f8becc87f041..38240d63bb27 100644 --- a/src/python/pants/backend/python/subsystems/python_native_code.py +++ b/src/python/pants/backend/python/subsystems/python_native_code.py @@ -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 @@ -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. @@ -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 = {} diff --git a/src/python/pants/backend/python/tasks/build_local_python_distributions.py b/src/python/pants/backend/python/tasks/build_local_python_distributions.py index 39aaacc8ab59..19e84fbef527 100644 --- a/src/python/pants/backend/python/tasks/build_local_python_distributions.py +++ b/src/python/pants/backend/python/tasks/build_local_python_distributions.py @@ -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: