Skip to content

Commit

Permalink
Merge pull request #3848 from juj/get_clang_native_env
Browse files Browse the repository at this point in the history
get_clang_native_env
  • Loading branch information
juj committed Oct 13, 2015
2 parents 45c1871 + 78aa504 commit a3895e8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/benchmark_sse1.py
Expand Up @@ -25,7 +25,7 @@ def path_from_root(*pathelems):
cmd = [CLANG_CPP] + get_clang_native_args() + [path_from_root('tests', 'benchmark_sse1.cpp'), '-O3', '-o', out_file]
print 'Building native version of the benchmark:'
print ' '.join(cmd)
build = Popen(cmd)
build = Popen(cmd, env=get_clang_native_env())
out = build.communicate()
if build.returncode != 0:
sys.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_core.py
Expand Up @@ -5757,7 +5757,7 @@ def test_sse1(self):
# Tests the full SSE1 API.
@SIMD
def test_sse1_full(self):
Popen([CLANG, path_from_root('tests', 'test_sse1_full.cpp'), '-o', 'test_sse1_full', '-D_CRT_SECURE_NO_WARNINGS=1'] + get_clang_native_args(), stdout=PIPE).communicate()
Popen([CLANG, path_from_root('tests', 'test_sse1_full.cpp'), '-o', 'test_sse1_full', '-D_CRT_SECURE_NO_WARNINGS=1'] + get_clang_native_args(), env=get_clang_native_env(), stdout=PIPE).communicate()
native_result, err = Popen('./test_sse1_full', stdout=PIPE).communicate()
native_result = native_result.replace('\r\n', '\n') # Windows line endings fix

Expand All @@ -5776,7 +5776,7 @@ def test_sse2_full(self):

args = []
if '-O0' in self.emcc_args: args += ['-D_DEBUG=1']
Popen([CLANG, path_from_root('tests', 'test_sse2_full.cpp'), '-o', 'test_sse2_full', '-D_CRT_SECURE_NO_WARNINGS=1'] + args + get_clang_native_args(), stdout=PIPE).communicate()
Popen([CLANG, path_from_root('tests', 'test_sse2_full.cpp'), '-o', 'test_sse2_full', '-D_CRT_SECURE_NO_WARNINGS=1'] + args + get_clang_native_args(), env=get_clang_native_env(), stdout=PIPE).communicate()
native_result, err = Popen('./test_sse2_full', stdout=PIPE).communicate()
native_result = native_result.replace('\r\n', '\n') # Windows line endings fix

Expand Down
2 changes: 1 addition & 1 deletion tests/test_other.py
Expand Up @@ -2793,7 +2793,7 @@ def test_odin_validation(self):
assert 'asm.js' in output, 'spidermonkey should mention asm.js compilation: ' + output

def test_bad_triple(self):
Popen([CLANG, path_from_root('tests', 'hello_world.c'), '-c', '-emit-llvm', '-o', 'a.bc'] + get_clang_native_args(), stdout=PIPE, stderr=PIPE).communicate()
Popen([CLANG, path_from_root('tests', 'hello_world.c'), '-c', '-emit-llvm', '-o', 'a.bc'] + get_clang_native_args(), env=get_clang_native_env(), stdout=PIPE, stderr=PIPE).communicate()
out, err = Popen([PYTHON, EMCC, 'a.bc'], stdout=PIPE, stderr=PIPE).communicate()
assert 'warning' in err or 'WARNING' in err, err
assert 'incorrect target triple' in err or 'different target triples' in err, err
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sockets.py
Expand Up @@ -44,7 +44,7 @@ def __enter__(self):
# NOTE empty filename support is a hack to support
# the current test_enet
if self.filename:
Popen([CLANG_CC, path_from_root('tests', self.filename), '-o', 'server', '-DSOCKK=%d' % self.target_port] + get_clang_native_args() + self.args).communicate()
Popen([CLANG_CC, path_from_root('tests', self.filename), '-o', 'server', '-DSOCKK=%d' % self.target_port] + get_clang_native_args() + self.args, env=get_clang_native_env()).communicate()
process = Popen([os.path.abspath('server')])
self.processes.append(process)

Expand Down
45 changes: 45 additions & 0 deletions tools/shared.py
Expand Up @@ -586,6 +586,51 @@ def get_clang_native_args():
# TODO: If Windows.h et al. are needed, will need to add something like '-isystemC:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Include'.
return CACHED_CLANG_NATIVE_ARGS

# This environment needs to be present when targeting a native host system executable
CACHED_CLANG_NATIVE_ENV=None
def get_clang_native_env():
global CACHED_CLANG_NATIVE_ENV
if CACHED_CLANG_NATIVE_ENV is not None: return CACHED_CLANG_NATIVE_ENV
env = os.environ.copy()

if WINDOWS:
# If already running in Visual Studio Command Prompt manually, no need to add anything here, so just return.
if 'VSINSTALLDIR' in env and 'INCLUDE' in env and 'LIB' in env:
CACHED_CLANG_NATIVE_ENV = env
return env

if 'VSINSTALLDIR' in env:
visual_studio_2013_path = env['VSINSTALLDIR']
elif 'VS120COMNTOOLS' in env:
visual_studio_2013_path = os.path.normpath(os.path.join(env['VS120COMNTOOLS'], '../..'))
elif 'ProgramFiles(x86)' in env:
visual_studio_2013_path = os.path.normpath(os.path.join(env['ProgramFiles(x86)'], 'Microsoft Visual Studio 12.0'))
elif 'ProgramFiles' in env:
visual_studio_2013_path = os.path.normpath(os.path.join(env['ProgramFiles'], 'Microsoft Visual Studio 12.0'))
else:
visual_studio_2013_path = 'C:\\Program Files (x86)\\Microsoft Visual Studio 12.0'
if not os.path.isdir(visual_studio_2013_path):
raise Exception('Visual Studio 2013 was not found in "' + visual_studio_2013_path + '"! Run in Visual Studio command prompt to avoid the need to autoguess this location (or set VSINSTALLDIR env var).')

if 'WindowsSdkDir' in env:
windows_sdk_dir = env['WindowsSdkDir']
elif 'ProgramFiles(x86)' in env:
windows_sdk_dir = os.path.normpath(os.path.join(env['ProgramFiles(x86)'], 'Windows Kits\\8.1'))
elif 'ProgramFiles' in env:
windows_sdk_dir = os.path.normpath(os.path.join(env['ProgramFiles'], 'Windows Kits\\8.1'))
else:
windows_sdk_dir = 'C:\\Program Files (x86)\\Windows Kits\\8.1'
if not os.path.isdir(windows_sdk_dir):
raise Exception('Windows SDK was not found in "' + windows_sdk_dir + '"! Run in Visual Studio command prompt to avoid the need to autoguess this location (or set WindowsSdkDir env var).')

env['INCLUDE'] = os.path.join(visual_studio_2013_path, 'VC\\INCLUDE')
env['LIB'] = os.path.join(visual_studio_2013_path, 'VC\\LIB\\amd64') + ';' + os.path.join(windows_sdk_dir, 'lib\\winv6.3\\um\\x64')

# Current configuration above is all Visual Studio -specific, so on non-Windowses, no action needed.

CACHED_CLANG_NATIVE_ENV = env
return env

CLANG_CC=os.path.expanduser(build_clang_tool_path('clang'))
CLANG_CPP=os.path.expanduser(build_clang_tool_path('clang++'))
CLANG=CLANG_CPP
Expand Down

0 comments on commit a3895e8

Please sign in to comment.