Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/update_libcxx.py
4150 views
1
#!/usr/bin/env python3
2
# Copyright 2019 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 os
8
import sys
9
import shutil
10
11
script_dir = os.path.abspath(os.path.dirname(__file__))
12
emscripten_root = os.path.dirname(os.path.dirname(script_dir))
13
default_llvm_dir = os.path.join(os.path.dirname(emscripten_root), 'llvm-project')
14
local_root = os.path.join(script_dir, 'libcxx')
15
local_src = os.path.join(local_root, 'src')
16
local_inc = os.path.join(local_root, 'include')
17
18
preserve_files = ('readme.txt', '__assertion_handler', '__config_site')
19
# ryu_long_double_constants.h from libc is unused (and very large)
20
excludes = ('CMakeLists.txt', 'ryu_long_double_constants.h')
21
22
libc_copy_dirs = [
23
'hdr',
24
'include/llvm-libc-macros',
25
'include/llvm-libc-types',
26
'shared',
27
'config',
28
]
29
30
def clean_dir(dirname):
31
if not os.path.exists(dirname):
32
return
33
for f in os.listdir(dirname):
34
if f in preserve_files:
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 copy_tree(upstream_dir, local_dir):
44
if not os.path.exists(local_dir):
45
os.makedirs(local_dir)
46
for f in os.listdir(upstream_dir):
47
full = os.path.join(upstream_dir, f)
48
if os.path.isdir(full):
49
shutil.copytree(full, os.path.join(local_dir, f))
50
elif f not in excludes:
51
shutil.copy2(full, os.path.join(local_dir, f))
52
for root, dirs, files in os.walk(local_dir):
53
for f in files:
54
if f in excludes:
55
full = os.path.join(root, f)
56
os.remove(full)
57
58
59
def main():
60
if len(sys.argv) > 1:
61
llvm_dir = os.path.abspath(sys.argv[1])
62
else:
63
llvm_dir = default_llvm_dir
64
libcxx_dir = os.path.join(llvm_dir, 'libcxx')
65
upstream_src = os.path.join(libcxx_dir, 'src')
66
upstream_inc = os.path.join(libcxx_dir, 'include')
67
assert os.path.exists(upstream_inc)
68
assert os.path.exists(upstream_src)
69
70
# Remove old version
71
clean_dir(local_src)
72
clean_dir(local_inc)
73
74
copy_tree(upstream_src, local_src)
75
copy_tree(upstream_inc, local_inc)
76
77
shutil.copy2(os.path.join(libcxx_dir, 'CREDITS.TXT'), local_root)
78
shutil.copy2(os.path.join(libcxx_dir, 'LICENSE.TXT'), local_root)
79
80
# We don't use frozen c++03 headers for now
81
shutil.rmtree(os.path.join(local_inc, '__cxx03'))
82
83
# libcxx includes headers from LLVM's libc
84
libc_upstream_dir = os.path.join(llvm_dir, 'libc')
85
assert os.path.exists(libc_upstream_dir)
86
libc_local_dir = os.path.join(script_dir, 'llvm-libc')
87
88
for dirname in libc_copy_dirs:
89
local_dir = os.path.join(libc_local_dir, dirname)
90
clean_dir(local_dir)
91
92
for dirname in libc_copy_dirs:
93
upstream_dir = os.path.join(libc_upstream_dir, dirname)
94
local_dir = os.path.join(libc_local_dir, dirname)
95
copy_tree(upstream_dir, local_dir)
96
97
shutil.copy2(os.path.join(libc_upstream_dir, 'LICENSE.TXT'), libc_local_dir)
98
99
if __name__ == '__main__':
100
main()
101
102