Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import tarfile
from dataclasses import dataclass
from enum import Enum, auto, unique
from subprocess import PIPE

# This assert needs to happen early, before any too-recent python syntax is used.
# In particular it needs to happen before we import any python file that uses the
Expand Down Expand Up @@ -172,6 +173,15 @@ def make_relative(filename):
reproduce_file.add(rsp_name, os.path.join(root, 'response.txt'))


def get_clang_resource_dir(args):
resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))]
if resource_dir:
return resource_dir[-1].split('=')[1]
else:
output = utils.run_process([shared.CLANG_CC, '-print-resource-dir'], stdout=PIPE).stdout
return output.strip()


@ToolchainProfiler.profile()
def main(args):
if shared.run_via_emxx:
Expand Down Expand Up @@ -253,7 +263,9 @@ def main(args):

if '-print-search-dirs' in args or '--print-search-dirs' in args:
print(f'programs: ={config.LLVM_ROOT}')
print(f'libraries: ={cache.get_lib_dir(absolute=True)}')
resource_dir = get_clang_resource_dir(args)
libdir = cache.get_lib_dir(absolute=True)
print(f'libraries: ={resource_dir}{os.pathsep}{libdir}')
return 0

if '-print-libgcc-file-name' in args or '--print-libgcc-file-name' in args:
Expand All @@ -265,14 +277,13 @@ def main(args):
print_file_name = [a for a in args if a.startswith(('-print-file-name=', '--print-file-name='))]
if print_file_name:
libname = print_file_name[-1].split('=')[1]
resource_dir = [a for a in args if a.startswith(('-resource-dir=', '--resource-dir='))]
if resource_dir:
system_libpath = resource_dir[-1].split('=')[1]
else:
system_libpath = cache.get_lib_dir(absolute=True)
fullpath = os.path.join(system_libpath, libname)
if os.path.isfile(fullpath):
print(fullpath)
resource_dir = get_clang_resource_dir(args)
system_libpath = cache.get_lib_dir(absolute=True)
for dirname in (resource_dir, system_libpath):
fullpath = os.path.join(dirname, libname)
if os.path.isfile(fullpath):
print(fullpath)
break
else:
Comment thread
sbc100 marked this conversation as resolved.
print(libname)
return 0
Expand Down
22 changes: 14 additions & 8 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,21 +768,27 @@ def test_print_prog_name(self):
def test_print_file_name(self, args):
# make sure the corresponding version of libc exists in the cache
self.run_process([EMCC, test_file('hello_world.c'), '-O2'] + args)
output = self.run_process([EMCC, '-print-file-name=libc.a'] + args, stdout=PIPE).stdout
output2 = self.run_process([EMCC, '--print-file-name=libc.a'] + args, stdout=PIPE).stdout
output = self.run_process([EMCC, '-print-file-name=libc.a'] + args, stdout=PIPE).stdout.rstrip()
output2 = self.run_process([EMCC, '--print-file-name=libc.a'] + args, stdout=PIPE).stdout.rstrip()
self.assertEqual(output, output2)
filename = Path(output)
settings.LTO = '-flto' in args
settings.MEMORY64 = int('-m64' in args)
self.assertContained(cache.get_lib_name('libc.a'), str(filename))

@crossplatform
def test_print_file_name_with_resource_dir(self):
file = Path(EMCC).name
output = self.run_process([EMCC, f'-print-file-name={file}'], stdout=PIPE).stdout
output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), f'-print-file-name={file}'], stdout=PIPE).stdout
self.assertNotExists(output.rstrip())
self.assertExists(output_relative.rstrip())
def test_print_file_name_resdir(self):
output = self.run_process([EMCC, '-print-file-name=include/wmmintrin.h'], stdout=PIPE).stdout.rstrip()
print('print-file-name: ' + output)
Comment thread
sbc100 marked this conversation as resolved.
self.assertExists(output)

@crossplatform
def test_print_file_name_custom_resdir(self):
output = self.run_process([EMCC, '-print-file-name=emcc.py'], stdout=PIPE).stdout.rstrip()
self.assertNotExists(output)

output_relative = self.run_process([EMCC, '-resource-dir=' + path_from_root(), '-print-file-name=emcc.py'], stdout=PIPE).stdout.rstrip()
self.assertExists(output_relative)

def test_emar_em_config_flag(self):
# Test that the --em-config flag is accepted but not passed down do llvm-ar.
Expand Down
Loading