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
6173 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
('include', 'profile'),
20
('lib', 'sanitizer_common'),
21
('lib', 'asan'),
22
('lib', 'interception'),
23
('lib', 'builtins'),
24
('lib', 'lsan'),
25
('lib', 'ubsan'),
26
('lib', 'ubsan_minimal'),
27
('lib', 'profile'),
28
]
29
30
preserve_files = ('readme.txt',)
31
32
33
def clear(dirname):
34
for f in os.listdir(dirname):
35
if f in preserve_files or 'emscripten' in f:
36
continue
37
full = os.path.join(dirname, f)
38
if os.path.isdir(full):
39
shutil.rmtree(full)
40
else:
41
os.remove(full)
42
43
44
def main():
45
if len(sys.argv) > 1:
46
llvm_dir = os.path.join(os.path.abspath(sys.argv[1]))
47
else:
48
llvm_dir = default_llvm_dir
49
upstream_dir = os.path.join(llvm_dir, 'compiler-rt')
50
assert os.path.exists(upstream_dir)
51
upstream_src = os.path.join(upstream_dir, 'lib', 'builtins')
52
upstream_include = os.path.join(upstream_dir, 'include', 'sanitizer')
53
assert os.path.exists(upstream_src)
54
assert os.path.exists(upstream_include)
55
56
for dirname in copy_dirs:
57
srcdir = os.path.join(upstream_dir, *dirname)
58
assert os.path.exists(srcdir)
59
dest = os.path.join(local_src, *dirname)
60
clear(dest)
61
for name in os.listdir(srcdir):
62
if name in ('.clang-format', 'CMakeLists.txt', 'README.txt', 'weak_symbols.txt'):
63
continue
64
if name.endswith('.syms.extra') or name.endswith('.S'):
65
continue
66
if os.path.isfile(os.path.join(srcdir, name)):
67
shutil.copy2(os.path.join(srcdir, name), dest)
68
69
shutil.copy2(os.path.join(upstream_dir, 'CREDITS.TXT'), local_src)
70
shutil.copy2(os.path.join(upstream_dir, 'LICENSE.TXT'), local_src)
71
72
73
if __name__ == '__main__':
74
main()
75
76