Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/update_compiler_rt.py
4150 views
1
#!/usr/bin/env python3
2
# Copyright 2020 The Emscripten Authors. All rights reserved.
3
# Emscripten is available under two separate licenses, the MIT license and the
4
# University of Illinois/NCSA Open Source License. Both these licenses can be
5
# found in the LICENSE file.
6
7
import glob
8
import os
9
import sys
10
import shutil
11
12
script_dir = os.path.abspath(os.path.dirname(__file__))
13
emscripten_root = os.path.dirname(os.path.dirname(script_dir))
14
default_llvm_dir = os.path.join(os.path.dirname(emscripten_root), 'llvm-project')
15
local_src = os.path.join(script_dir, 'compiler-rt')
16
17
copy_dirs = [
18
('include', 'sanitizer'),
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
]
28
29
preserve_files = ('readme.txt',)
30
31
32
def clear(dirname):
33
for f in os.listdir(dirname):
34
if f in preserve_files or 'emscripten' in f:
35
continue
36
full = os.path.join(dirname, f)
37
if os.path.isdir(full):
38
shutil.rmtree(full)
39
else:
40
os.remove(full)
41
42
43
def main():
44
if len(sys.argv) > 1:
45
llvm_dir = os.path.join(os.path.abspath(sys.argv[1]))
46
else:
47
llvm_dir = default_llvm_dir
48
upstream_dir = os.path.join(llvm_dir, 'compiler-rt')
49
assert os.path.exists(upstream_dir)
50
upstream_src = os.path.join(upstream_dir, 'lib', 'builtins')
51
upstream_include = os.path.join(upstream_dir, 'include', 'sanitizer')
52
assert os.path.exists(upstream_src)
53
assert os.path.exists(upstream_include)
54
55
for dirname in copy_dirs:
56
srcdir = os.path.join(upstream_dir, *dirname)
57
assert os.path.exists(srcdir)
58
dest = os.path.join(local_src, *dirname)
59
clear(dest)
60
for name in os.listdir(srcdir):
61
if name in ('.clang-format', 'CMakeLists.txt', 'README.txt', 'weak_symbols.txt'):
62
continue
63
if name.endswith('.syms.extra') or name.endswith('.S'):
64
continue
65
if os.path.isfile(os.path.join(srcdir, name)):
66
shutil.copy2(os.path.join(srcdir, name), dest)
67
68
shutil.copy2(os.path.join(upstream_dir, 'CREDITS.TXT'), local_src)
69
shutil.copy2(os.path.join(upstream_dir, 'LICENSE.TXT'), local_src)
70
71
72
if __name__ == '__main__':
73
main()
74
75