Path: blob/main/system/lib/update_llvm_libc.py
4150 views
#!/usr/bin/env python31# Copyright 2019 The Emscripten Authors. All rights reserved.2# Emscripten is available under two separate licenses, the MIT license and the3# University of Illinois/NCSA Open Source License. Both these licenses can be4# found in the LICENSE file.56import os7import sys8import shutil9import glob1011script_dir = os.path.abspath(os.path.dirname(__file__))12emscripten_root = os.path.dirname(os.path.dirname(script_dir))13default_llvm_dir = os.path.join(os.path.dirname(emscripten_root), 'llvm-project')1415preserve_files = ('readme.txt', '__assertion_handler', '__config_site')16# ryu_long_double_constants.h from libc is unused (and very large)17excludes = ('CMakeLists.txt', 'ryu_long_double_constants.h')1819libc_copy_dirs = [20'hdr',21'include/llvm-libc-macros',22'include/llvm-libc-types',23'shared',24'config',25'src/__support',26'src/assert',27'src/complex',28'src/errno',29'src/inttypes',30'src/math',31'src/setjmp',32'src/stdio/printf_core',33'src/stdlib',34'src/string',35'src/strings',36'src/wchar',37]3839libc_exclusion_patterns = [40# float16 is unsupported in Emscripten.41'src/complex/**/*f16*',42'src/math/generic/*f16*',4344'src/setjmp/**/*', # setjmp in Emscripten is implemented by the clang backend.45'src/strings/str*casecmp_l*', # locale_t is unsupported in Overlay Mode.46]4748def clean_dir(dirname):49if not os.path.exists(dirname):50return51for f in os.listdir(dirname):52if f in preserve_files:53continue54full = os.path.join(dirname, f)55if os.path.isdir(full):56shutil.rmtree(full)57else:58os.remove(full)596061def copy_tree(upstream_dir, local_dir):62if not os.path.exists(local_dir):63os.makedirs(local_dir)64for f in os.listdir(upstream_dir):65full = os.path.join(upstream_dir, f)66if os.path.isdir(full):67shutil.copytree(full, os.path.join(local_dir, f))68elif f not in excludes:69shutil.copy2(full, os.path.join(local_dir, f))70for root, dirs, files in os.walk(local_dir):71for f in files:72if f in excludes:73full = os.path.join(root, f)74os.remove(full)757677def main():78if len(sys.argv) > 1:79llvm_dir = os.path.abspath(sys.argv[1])80else:81llvm_dir = default_llvm_dir82libc_upstream_dir = os.path.join(llvm_dir, 'libc')83assert os.path.exists(libc_upstream_dir)84libc_local_dir = os.path.join(script_dir, 'llvm-libc')8586for dirname in libc_copy_dirs:87local_dir = os.path.join(libc_local_dir, dirname)88clean_dir(local_dir)8990for dirname in libc_copy_dirs:91upstream_dir = os.path.join(libc_upstream_dir, dirname)92local_dir = os.path.join(libc_local_dir, dirname)93copy_tree(upstream_dir, local_dir)9495# Certain llvm-libc files that are incompatible in Emscripten96for excludsion_pattern in libc_exclusion_patterns:97files_to_exclude = glob.glob(os.path.join(libc_local_dir, excludsion_pattern))98for file in files_to_exclude:99os.remove(file)100101if __name__ == '__main__':102main()103104