Skip to content

Commit

Permalink
remove glibc, and remove executable step from native subsystem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jun 14, 2018
1 parent 14b8a7d commit 5a28312
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 62 deletions.
21 changes: 2 additions & 19 deletions src/python/pants/backend/native/subsystems/native_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
from pants.backend.native.subsystems.llvm import LLVM
from pants.backend.native.subsystems.platform_specific.darwin.xcode_cli_tools import XCodeCLITools
from pants.backend.native.subsystems.platform_specific.linux.binutils import Binutils
from pants.backend.native.subsystems.platform_specific.linux.glibc import GLibc
from pants.binaries.binary_tool import ExecutablePathProvider
from pants.subsystem.subsystem import Subsystem
from pants.util.memo import memoized_method
from pants.util.osutil import get_normalized_os_name, get_os_name, normalize_os_name
from pants.util.osutil import get_os_name, normalize_os_name


class NativeToolchain(Subsystem, ExecutablePathProvider):
Expand Down Expand Up @@ -84,23 +83,7 @@ def _get_platform_specific_subsystems(cls):
def subsystem_dependencies(cls):
prev = super(NativeToolchain, cls).subsystem_dependencies()
cur_platform_subsystems = cls._get_platform_specific_subsystems()
return prev + tuple(sub.scoped(cls) for sub in cur_platform_subsystems) + (
GLibc.scoped(cls),
)

@memoized_method
def glibc_dir(self):
# FIXME: Once #5815 lands, the "compiler" datatype should be given a field for
# (DY)?LD_LIBRARY_PATH entries. GCC and LLVM should be made to depend on GLibc on Linux and
# provide glibc in the new library path field. This provides necessary files including crti.o
# that are not included in the compiler.
normalized_os_name = get_normalized_os_name()
if normalized_os_name == 'darwin':
return None
elif normalized_os_name == 'linux':
return GLibc.scoped_instance(self).lib_dir()
else:
raise self.UnsupportedPlatformError("unrecognized os name: {}".format(normalized_os_name))
return prev + tuple(sub.scoped(cls) for sub in cur_platform_subsystems)

@memoized_method
def _subsystem_instances(self):
Expand Down

This file was deleted.

8 changes: 2 additions & 6 deletions src/python/pants/backend/python/tasks/setup_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _setup_command(self):
return self.__setup_command


class SetupPyInvocationEnvironment(datatype(['joined_path', 'glibc_dir'])):
class SetupPyInvocationEnvironment(datatype(['joined_path'])):

def as_env_dict(self):
ret = {
Expand All @@ -88,18 +88,14 @@ def as_env_dict(self):
'PATH': self.joined_path,
}

if self.glibc_dir:
ret['LD_LIBRARY_PATH'] = self.glibc_dir

return ret


@rule(SetupPyInvocationEnvironment, [Select(NativeToolchain)])
def get_setup_py_env(native_toolchain):
# Isolate the PATH to just our toolchain.
joined_path = get_joined_path(native_toolchain.path_entries())
# Include the glibc lib directory for crti.o.
return SetupPyInvocationEnvironment(joined_path, native_toolchain.glibc_dir())
return SetupPyInvocationEnvironment(joined_path)


class TargetAncestorIterator(object):
Expand Down
1 change: 1 addition & 0 deletions tests/python/pants_test/backend/native/subsystems/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ python_tests(
'tests/python/pants_test:base_test',
'tests/python/pants_test/subsystem:subsystem_utils',
],
tags={'platform_specific_behavior'},
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os

from pants.backend.native.subsystems.native_toolchain import NativeToolchain
from pants.util.contextutil import environment_as, get_joined_path
from pants.util.process_handler import subprocess
Expand All @@ -23,17 +25,15 @@ def setUp(self):
super(TestNativeToolchain, self).setUp()
self.toolchain = global_subsystem_instance(NativeToolchain)

def _get_test_file_path(self, path):
return os.path.join(self.build_root, path)

def _invoke_capturing_output(self, cmd, cwd=None):
if cwd is None:
cwd = self.build_root

toolchain_dirs = self.toolchain.path_entries()
isolated_toolchain_path = get_joined_path(toolchain_dirs)
process_invocation_env = dict(PATH=isolated_toolchain_path)

glibc_dir = self.toolchain.glibc_dir()
if glibc_dir:
process_invocation_env['LD_LIBRARY_PATH'] = glibc_dir
process_invocation_env = dict(PATH=get_joined_path(toolchain_dirs))

try:
with environment_as(**process_invocation_env):
Expand All @@ -56,13 +56,11 @@ def test_hello_c(self):
}
""")

self._invoke_capturing_output(['gcc', 'hello.c', '-o', 'hello_gcc'])
gcc_output = self._invoke_capturing_output(['./hello_gcc'])
self.assertEqual(gcc_output, 'hello, world!\n')
self._invoke_capturing_output(['gcc', '-c', 'hello.c', '-o', 'hello_gcc.o'])
self.assertTrue(os.path.isfile(self._get_test_file_path('hello_gcc.o')))

self._invoke_capturing_output(['clang', 'hello.c', '-o', 'hello_clang'])
clang_output = self._invoke_capturing_output(['./hello_clang'])
self.assertEqual(clang_output, 'hello, world!\n')
self._invoke_capturing_output(['clang', '-c', 'hello.c', '-o', 'hello_clang.o'])
self.assertTrue(os.path.isfile(self._get_test_file_path('hello_clang.o')))

def test_hello_cpp(self):
self.create_file('hello.cpp', contents="""
Expand All @@ -73,10 +71,8 @@ def test_hello_cpp(self):
}
""")

self._invoke_capturing_output(['g++', 'hello.cpp', '-o', 'hello_g++'])
gpp_output = self._invoke_capturing_output(['./hello_g++'])
self.assertEqual(gpp_output, 'hello, world!\n')
self._invoke_capturing_output(['g++', '-c', 'hello.cpp', '-o', 'hello_g++.o'])
self.assertTrue(os.path.isfile(self._get_test_file_path('hello_g++.o')))

self._invoke_capturing_output(['clang++', 'hello.cpp', '-o', 'hello_clang++'])
clangpp_output = self._invoke_capturing_output(['./hello_clang++'])
self.assertEqual(clangpp_output, 'hello, world!\n')
self._invoke_capturing_output(['clang++', '-c', 'hello.cpp', '-o', 'hello_clang++.o'])
self.assertTrue(os.path.isfile(self._get_test_file_path('hello_clang++.o')))

0 comments on commit 5a28312

Please sign in to comment.