Path: blob/main/system/lib/update_compiler_rt.py
6173 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('include', 'profile'),19('lib', 'sanitizer_common'),20('lib', 'asan'),21('lib', 'interception'),22('lib', 'builtins'),23('lib', 'lsan'),24('lib', 'ubsan'),25('lib', 'ubsan_minimal'),26('lib', 'profile'),27]2829preserve_files = ('readme.txt',)303132def clear(dirname):33for f in os.listdir(dirname):34if f in preserve_files or 'emscripten' in f:35continue36full = os.path.join(dirname, f)37if os.path.isdir(full):38shutil.rmtree(full)39else:40os.remove(full)414243def main():44if len(sys.argv) > 1:45llvm_dir = os.path.join(os.path.abspath(sys.argv[1]))46else:47llvm_dir = default_llvm_dir48upstream_dir = os.path.join(llvm_dir, 'compiler-rt')49assert os.path.exists(upstream_dir)50upstream_src = os.path.join(upstream_dir, 'lib', 'builtins')51upstream_include = os.path.join(upstream_dir, 'include', 'sanitizer')52assert os.path.exists(upstream_src)53assert os.path.exists(upstream_include)5455for dirname in copy_dirs:56srcdir = os.path.join(upstream_dir, *dirname)57assert os.path.exists(srcdir)58dest = os.path.join(local_src, *dirname)59clear(dest)60for name in os.listdir(srcdir):61if name in ('.clang-format', 'CMakeLists.txt', 'README.txt', 'weak_symbols.txt'):62continue63if name.endswith('.syms.extra') or name.endswith('.S'):64continue65if os.path.isfile(os.path.join(srcdir, name)):66shutil.copy2(os.path.join(srcdir, name), dest)6768shutil.copy2(os.path.join(upstream_dir, 'CREDITS.TXT'), local_src)69shutil.copy2(os.path.join(upstream_dir, 'LICENSE.TXT'), local_src)707172if __name__ == '__main__':73main()747576