Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Problem Our `LibcDev` subsystem searches for `crti.o`, a file necessary to create executables on Linux. We use this in order to test both clang and gcc in `test_native_toolchain.py`. This is not needed except within Pants CI right now, and if the host system doesn't contain this file, it will always error out. ### Solution - Add `--enable-libc-search` to `NativeToolchain`, defaulting to `False`, so that systems without this currently-unnecessary file don't need to worry about this implementation detail. - Create `@platform_specific` decorator for individual tests which should only run on a specific platform to validate the expected behavior of this flag. ### Result Pants invocations using the native toolchain on Linux hosts without a `crti.o` do not error out.
- Loading branch information
1 parent
35f7873
commit 53e6ac3
Showing
9 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
tests/python/pants_test/backend/native/subsystems/test_libc_resolution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 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 | ||
|
||
from pants.backend.native.config.environment import Platform | ||
from pants.backend.native.subsystems.libc_dev import LibcDev | ||
from pants.backend.native.subsystems.utils.parse_search_dirs import ParseSearchDirs | ||
from pants_test.backend.native.util.platform_utils import platform_specific | ||
from pants_test.subsystem.subsystem_util import global_subsystem_instance, init_subsystems | ||
from pants_test.test_base import TestBase | ||
|
||
|
||
class TestLibcDirectorySearchFailure(TestBase): | ||
|
||
def setUp(self): | ||
init_subsystems([LibcDev], options={ | ||
'libc': { | ||
'enable_libc_search': True, | ||
'libc_dir': '/does/not/exist', | ||
}, | ||
}) | ||
|
||
self.libc = global_subsystem_instance(LibcDev) | ||
self.platform = Platform.create() | ||
|
||
@platform_specific('linux') | ||
def test_libc_search_failure(self): | ||
with self.assertRaises(LibcDev.HostLibcDevResolutionError) as cm: | ||
self.libc.get_libc_dirs(self.platform) | ||
expected_msg = ( | ||
"Could not locate crti.o in directory /does/not/exist provided by the --libc-dir option.") | ||
self.assertEqual(expected_msg, str(cm.exception)) | ||
|
||
@platform_specific('darwin') | ||
def test_libc_search_noop_osx(self): | ||
self.assertEqual([], self.libc.get_libc_dirs(self.platform)) | ||
|
||
|
||
class TestLibcSearchDisabled(TestBase): | ||
|
||
def setUp(self): | ||
init_subsystems([LibcDev], options={ | ||
'libc': { | ||
'enable_libc_search': False, | ||
'libc_dir': '/does/not/exist', | ||
}, | ||
}) | ||
|
||
self.libc = global_subsystem_instance(LibcDev) | ||
self.platform = Platform.create() | ||
|
||
@platform_specific('linux') | ||
def test_libc_disabled_search(self): | ||
self.assertEqual([], self.libc.get_libc_dirs(self.platform)) | ||
|
||
|
||
class TestLibcCompilerSearchFailure(TestBase): | ||
|
||
def setUp(self): | ||
init_subsystems([LibcDev], options={ | ||
'libc': { | ||
'enable_libc_search': True, | ||
'host_compiler': 'this_executable_does_not_exist', | ||
}, | ||
}) | ||
|
||
self.libc = global_subsystem_instance(LibcDev) | ||
self.platform = Platform.create() | ||
|
||
@platform_specific('linux') | ||
def test_libc_compiler_search_failure(self): | ||
with self.assertRaises(ParseSearchDirs.ParseSearchDirsError) as cm: | ||
self.libc.get_libc_dirs(self.platform) | ||
expected_msg = ( | ||
"Invocation of 'this_executable_does_not_exist' with argv " | ||
"'this_executable_does_not_exist -print-search-dirs' failed.") | ||
self.assertIn(expected_msg, str(cm.exception)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# coding=utf-8 | ||
|
||
python_library( | ||
dependencies=[ | ||
'src/python/pants/backend/native/config', | ||
'src/python/pants/util:osutil', | ||
], | ||
) |
24 changes: 24 additions & 0 deletions
24
tests/python/pants_test/backend/native/util/platform_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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 | ||
|
||
from pants.backend.native.config.environment import Platform | ||
from pants.util.osutil import all_normalized_os_names | ||
|
||
|
||
def platform_specific(normalized_os_name): | ||
if normalized_os_name not in all_normalized_os_names(): | ||
raise ValueError("unrecognized platform: {}".format(normalized_os_name)) | ||
|
||
def decorator(test_fn): | ||
def wrapper(self, *args, **kwargs): | ||
# FIXME: This should be drawn from the v2 engine somehow. | ||
platform = Platform.create() | ||
|
||
if platform.normalized_os_name == normalized_os_name: | ||
test_fn(self, *args, **kwargs) | ||
|
||
return wrapper | ||
return decorator |