Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/update_libunwind.py
4150 views
1
#!/usr/bin/env python3
2
# Copyright 2023 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, 'libunwind')
15
local_src = os.path.join(local_root, 'src')
16
local_inc = os.path.join(local_root, 'include')
17
18
excludes = ('CMakeLists.txt',)
19
preserve_files = ()
20
21
22
def clean_dir(dirname):
23
for f in os.listdir(dirname):
24
if f in preserve_files:
25
continue
26
full = os.path.join(dirname, f)
27
if os.path.isdir(full):
28
shutil.rmtree(full)
29
else:
30
os.remove(full)
31
32
33
def copy_tree(upstream_dir, local_dir):
34
for f in os.listdir(upstream_dir):
35
full = os.path.join(upstream_dir, f)
36
if os.path.isdir(full):
37
shutil.copytree(full, os.path.join(local_dir, f))
38
elif f not in excludes:
39
shutil.copy2(full, os.path.join(local_dir, f))
40
41
42
def main():
43
if len(sys.argv) > 1:
44
llvm_dir = os.path.join(os.path.abspath(sys.argv[1]))
45
else:
46
llvm_dir = default_llvm_dir
47
upstream_root = os.path.join(llvm_dir, 'libunwind')
48
upstream_src = os.path.join(upstream_root, 'src')
49
upstream_inc = os.path.join(upstream_root, 'include')
50
assert os.path.exists(upstream_inc)
51
assert os.path.exists(upstream_src)
52
53
# Remove old version
54
clean_dir(local_src)
55
clean_dir(local_inc)
56
57
copy_tree(upstream_src, local_src)
58
copy_tree(upstream_inc, local_inc)
59
shutil.copy2(os.path.join(upstream_root, 'LICENSE.TXT'), local_root)
60
61
62
if __name__ == '__main__':
63
main()
64
65