2019-05-01 02:13:22 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
# Setup config name.
|
|
|
|
config.name = 'CRT' + config.name_suffix
|
|
|
|
|
|
|
|
# Setup source root.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
|
2020-06-10 18:46:29 +08:00
|
|
|
# Choose between lit's internal shell pipeline runner and a real shell. If
|
|
|
|
# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
|
|
|
|
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
|
|
|
|
if use_lit_shell:
|
|
|
|
# 0 is external, "" is default, and everything else is internal.
|
|
|
|
execute_external = (use_lit_shell == "0")
|
|
|
|
else:
|
|
|
|
# Otherwise we default to internal on Windows and external elsewhere, as
|
|
|
|
# bash on Windows is usually very slow.
|
|
|
|
execute_external = (not sys.platform in ['win32'])
|
|
|
|
|
2019-05-01 02:13:22 +08:00
|
|
|
def get_library_path(file):
|
|
|
|
cmd = subprocess.Popen([config.clang.strip(),
|
|
|
|
config.target_cflags.strip(),
|
|
|
|
'-print-file-name=%s' % file],
|
|
|
|
stdout=subprocess.PIPE,
|
[compiler-rt] Better Windows support for running tests in external shell
Summary:
These changes are necessary to support remote running compiler-rt tests
that were compiled on Windows.
Most of the code here has been copy-pasted from other lit configs.
Why do we remove the conversions to ASCII in the crt config?
We set the `universal_newlines` argument to `True` in `Popen` instead.
This is supported in both Python 2.7 and 3, is easier
(no need to do the `str(dir.decode('ascii'))` dance) and less
error prone.
Also, this is necessary because if the config is executed on Windows,
and `execute_external` is `True`, we take the branch
`if sys.platform in ['win32'] and execute_external`,
and if we use Python 3, then the `dir` variable is a byte-like object,
not str, but the ``replace method on byte-like objects requires its
arguments to also be byte-like objects, which is incompatible with
Python 2 etc etc.
It is a lot simpler to just work with strings in the first place, which
is achieved by setting `universal_newlines` to `True`. As far as
I understand, this way wasn't taken because of the need to support
Python <2.7, but this is not the case now.
Reviewers: compnerd, phosek, weimingz
Reviewed By: compnerd
Subscribers: dberris, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83485
2020-07-10 00:36:15 +08:00
|
|
|
env=config.environment,
|
|
|
|
universal_newlines=True)
|
2019-05-01 02:13:22 +08:00
|
|
|
if not cmd.stdout:
|
|
|
|
lit_config.fatal("Couldn't find the library path for '%s'" % file)
|
|
|
|
dir = cmd.stdout.read().strip()
|
|
|
|
if sys.platform in ['win32'] and execute_external:
|
|
|
|
# Don't pass dosish path separator to msys bash.exe.
|
|
|
|
dir = dir.replace('\\', '/')
|
[compiler-rt] Better Windows support for running tests in external shell
Summary:
These changes are necessary to support remote running compiler-rt tests
that were compiled on Windows.
Most of the code here has been copy-pasted from other lit configs.
Why do we remove the conversions to ASCII in the crt config?
We set the `universal_newlines` argument to `True` in `Popen` instead.
This is supported in both Python 2.7 and 3, is easier
(no need to do the `str(dir.decode('ascii'))` dance) and less
error prone.
Also, this is necessary because if the config is executed on Windows,
and `execute_external` is `True`, we take the branch
`if sys.platform in ['win32'] and execute_external`,
and if we use Python 3, then the `dir` variable is a byte-like object,
not str, but the ``replace method on byte-like objects requires its
arguments to also be byte-like objects, which is incompatible with
Python 2 etc etc.
It is a lot simpler to just work with strings in the first place, which
is achieved by setting `universal_newlines` to `True`. As far as
I understand, this way wasn't taken because of the need to support
Python <2.7, but this is not the case now.
Reviewers: compnerd, phosek, weimingz
Reviewed By: compnerd
Subscribers: dberris, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83485
2020-07-10 00:36:15 +08:00
|
|
|
return dir
|
2019-05-01 02:13:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_libgcc_file_name():
|
|
|
|
cmd = subprocess.Popen([config.clang.strip(),
|
|
|
|
config.target_cflags.strip(),
|
|
|
|
'-print-libgcc-file-name'],
|
|
|
|
stdout=subprocess.PIPE,
|
[compiler-rt] Better Windows support for running tests in external shell
Summary:
These changes are necessary to support remote running compiler-rt tests
that were compiled on Windows.
Most of the code here has been copy-pasted from other lit configs.
Why do we remove the conversions to ASCII in the crt config?
We set the `universal_newlines` argument to `True` in `Popen` instead.
This is supported in both Python 2.7 and 3, is easier
(no need to do the `str(dir.decode('ascii'))` dance) and less
error prone.
Also, this is necessary because if the config is executed on Windows,
and `execute_external` is `True`, we take the branch
`if sys.platform in ['win32'] and execute_external`,
and if we use Python 3, then the `dir` variable is a byte-like object,
not str, but the ``replace method on byte-like objects requires its
arguments to also be byte-like objects, which is incompatible with
Python 2 etc etc.
It is a lot simpler to just work with strings in the first place, which
is achieved by setting `universal_newlines` to `True`. As far as
I understand, this way wasn't taken because of the need to support
Python <2.7, but this is not the case now.
Reviewers: compnerd, phosek, weimingz
Reviewed By: compnerd
Subscribers: dberris, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83485
2020-07-10 00:36:15 +08:00
|
|
|
env=config.environment,
|
|
|
|
universal_newlines=True)
|
2019-05-01 02:13:22 +08:00
|
|
|
if not cmd.stdout:
|
|
|
|
lit_config.fatal("Couldn't find the library path for '%s'" % file)
|
|
|
|
dir = cmd.stdout.read().strip()
|
|
|
|
if sys.platform in ['win32'] and execute_external:
|
|
|
|
# Don't pass dosish path separator to msys bash.exe.
|
|
|
|
dir = dir.replace('\\', '/')
|
[compiler-rt] Better Windows support for running tests in external shell
Summary:
These changes are necessary to support remote running compiler-rt tests
that were compiled on Windows.
Most of the code here has been copy-pasted from other lit configs.
Why do we remove the conversions to ASCII in the crt config?
We set the `universal_newlines` argument to `True` in `Popen` instead.
This is supported in both Python 2.7 and 3, is easier
(no need to do the `str(dir.decode('ascii'))` dance) and less
error prone.
Also, this is necessary because if the config is executed on Windows,
and `execute_external` is `True`, we take the branch
`if sys.platform in ['win32'] and execute_external`,
and if we use Python 3, then the `dir` variable is a byte-like object,
not str, but the ``replace method on byte-like objects requires its
arguments to also be byte-like objects, which is incompatible with
Python 2 etc etc.
It is a lot simpler to just work with strings in the first place, which
is achieved by setting `universal_newlines` to `True`. As far as
I understand, this way wasn't taken because of the need to support
Python <2.7, but this is not the case now.
Reviewers: compnerd, phosek, weimingz
Reviewed By: compnerd
Subscribers: dberris, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83485
2020-07-10 00:36:15 +08:00
|
|
|
return dir
|
2019-05-01 02:13:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
def build_invocation(compile_flags):
|
|
|
|
return ' ' + ' '.join([config.clang] + compile_flags) + ' '
|
|
|
|
|
|
|
|
|
|
|
|
# Setup substitutions.
|
|
|
|
config.substitutions.append(
|
|
|
|
('%clang ', build_invocation([config.target_cflags])))
|
|
|
|
config.substitutions.append(
|
|
|
|
('%clangxx ',
|
|
|
|
build_invocation(config.cxx_mode_flags + [config.target_cflags])))
|
|
|
|
|
|
|
|
base_lib = os.path.join(
|
|
|
|
config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix)
|
[compiler-rt] Better Windows support for running tests in external shell
Summary:
These changes are necessary to support remote running compiler-rt tests
that were compiled on Windows.
Most of the code here has been copy-pasted from other lit configs.
Why do we remove the conversions to ASCII in the crt config?
We set the `universal_newlines` argument to `True` in `Popen` instead.
This is supported in both Python 2.7 and 3, is easier
(no need to do the `str(dir.decode('ascii'))` dance) and less
error prone.
Also, this is necessary because if the config is executed on Windows,
and `execute_external` is `True`, we take the branch
`if sys.platform in ['win32'] and execute_external`,
and if we use Python 3, then the `dir` variable is a byte-like object,
not str, but the ``replace method on byte-like objects requires its
arguments to also be byte-like objects, which is incompatible with
Python 2 etc etc.
It is a lot simpler to just work with strings in the first place, which
is achieved by setting `universal_newlines` to `True`. As far as
I understand, this way wasn't taken because of the need to support
Python <2.7, but this is not the case now.
Reviewers: compnerd, phosek, weimingz
Reviewed By: compnerd
Subscribers: dberris, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D83485
2020-07-10 00:36:15 +08:00
|
|
|
|
|
|
|
if sys.platform in ['win32'] and execute_external:
|
|
|
|
# Don't pass dosish path separator to msys bash.exe.
|
|
|
|
base_lib = base_lib.replace('\\', '/')
|
|
|
|
|
2019-05-01 02:13:22 +08:00
|
|
|
config.substitutions.append(('%crtbegin', base_lib % "crtbegin"))
|
|
|
|
config.substitutions.append(('%crtend', base_lib % "crtend"))
|
|
|
|
|
|
|
|
config.substitutions.append(
|
|
|
|
('%crt1', get_library_path('crt1.o')))
|
|
|
|
config.substitutions.append(
|
|
|
|
('%crti', get_library_path('crti.o')))
|
|
|
|
config.substitutions.append(
|
|
|
|
('%crtn', get_library_path('crtn.o')))
|
|
|
|
|
|
|
|
config.substitutions.append(
|
|
|
|
('%libgcc', get_libgcc_file_name()))
|
|
|
|
|
|
|
|
config.substitutions.append(
|
|
|
|
('%libstdcxx', '-l' + config.sanitizer_cxx_lib.lstrip('lib')))
|
|
|
|
|
|
|
|
# Default test suffixes.
|
2019-08-06 03:25:35 +08:00
|
|
|
config.suffixes = ['.c', '.cpp']
|
2019-05-01 02:13:22 +08:00
|
|
|
|
|
|
|
if config.host_os not in ['Linux']:
|
|
|
|
config.unsupported = True
|