Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/update_musl.py
4150 views
1
#!/usr/bin/env python3
2
# Copyright 2021 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
"""Simple script for updating musl from external git repo.
8
9
The upstream sources, along with our local changes, live at:
10
11
https://github.com/emscripten-core/musl
12
13
To update musl first make sure all changes from the emscripten repo
14
are present in the `emscripten` branch of the above repo. Then run
15
`git merge v<musl_version>` to pull in the latest musl changes from
16
a given musl version. Once any merge conflict are resolved those
17
change can then be copied back into emscripten using this script.
18
"""
19
20
import os
21
import sys
22
import shutil
23
24
script_dir = os.path.abspath(os.path.dirname(__file__))
25
local_src = os.path.join(script_dir, 'libc', 'musl')
26
emscripten_root = os.path.dirname(os.path.dirname(script_dir))
27
default_musl_dir = os.path.join(os.path.dirname(emscripten_root), 'musl')
28
exclude_dirs = (
29
# Top level directories we don't include
30
'tools', 'obj', 'lib', 'crt', 'musl', 'compat',
31
# Parts of src we don't build
32
'malloc',
33
# Arch-specific code we don't use
34
'arm', 'x32', 'sh', 'i386', 'x86_64', 'aarch64', 'riscv64',
35
's390x', 'mips', 'mips64', 'mipsn32', 'powerpc', 'powerpc64',
36
'm68k', 'microblaze', 'or1k')
37
exclude_files = (
38
'aio.h',
39
'sendfile.h',
40
'auxv.h',
41
'personality.h',
42
'klog.h',
43
'fanotify.h',
44
'vt.h',
45
'swap.h',
46
'reboot.h',
47
'quota.h',
48
'kd.h',
49
'io.h',
50
'fsuid.h',
51
'epoll.h',
52
'inotify.h',
53
'timerfd.h',
54
'timex.h',
55
'cachectl.h',
56
'soundcard.h',
57
'eventfd.h',
58
'signalfd.h',
59
'ptrace.h',
60
'prctl.h',
61
)
62
63
64
if len(sys.argv) > 1:
65
musl_dir = os.path.abspath(sys.argv[1])
66
else:
67
musl_dir = default_musl_dir
68
69
70
def should_ignore(name):
71
return name in exclude_dirs or name[0] == '.' or name in exclude_files
72
73
74
def ignore(dirname, contents):
75
return [c for c in contents if should_ignore(c)]
76
77
78
def main():
79
assert os.path.exists(musl_dir)
80
81
# Remove old version
82
shutil.rmtree(local_src)
83
84
# Copy new version into place
85
shutil.copytree(musl_dir, local_src, ignore=ignore)
86
87
# Create version.h
88
version = open(os.path.join(local_src, 'VERSION')).read().strip()
89
with open(os.path.join(local_src, 'src', 'internal', 'version.h'), 'w') as f:
90
f.write('#define VERSION "%s"\n' % version)
91
92
93
if __name__ == '__main__':
94
main()
95
96