Path: blob/main/system/lib/update_compiler_rt.py
4150 views
#!/usr/bin/env python31# Copyright 2020 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 glob7import os8import sys9import shutil1011script_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')14local_src = os.path.join(script_dir, 'compiler-rt')1516copy_dirs = [17('include', 'sanitizer'),18('lib', 'sanitizer_common'),19('lib', 'asan'),20('lib', 'interception'),21('lib', 'builtins'),22('lib', 'lsan'),23('lib', 'ubsan'),24('lib', 'ubsan_minimal'),25('lib', 'profile'),26]2728preserve_files = ('readme.txt',)293031def clear(dirname):32for f in os.listdir(dirname):33if f in preserve_files or 'emscripten' in f:34continue35full = os.path.join(dirname, f)36if os.path.isdir(full):37shutil.rmtree(full)38else:39os.remove(full)404142def main():43if len(sys.argv) > 1:44llvm_dir = os.path.join(os.path.abspath(sys.argv[1]))45else:46llvm_dir = default_llvm_dir47upstream_dir = os.path.join(llvm_dir, 'compiler-rt')48assert os.path.exists(upstream_dir)49upstream_src = os.path.join(upstream_dir, 'lib', 'builtins')50upstream_include = os.path.join(upstream_dir, 'include', 'sanitizer')51assert os.path.exists(upstream_src)52assert os.path.exists(upstream_include)5354for dirname in copy_dirs:55srcdir = os.path.join(upstream_dir, *dirname)56assert os.path.exists(srcdir)57dest = os.path.join(local_src, *dirname)58clear(dest)59for name in os.listdir(srcdir):60if name in ('.clang-format', 'CMakeLists.txt', 'README.txt', 'weak_symbols.txt'):61continue62if name.endswith('.syms.extra') or name.endswith('.S'):63continue64if os.path.isfile(os.path.join(srcdir, name)):65shutil.copy2(os.path.join(srcdir, name), dest)6667shutil.copy2(os.path.join(upstream_dir, 'CREDITS.TXT'), local_src)68shutil.copy2(os.path.join(upstream_dir, 'LICENSE.TXT'), local_src)697071if __name__ == '__main__':72main()737475