1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#!/usr/bin/env python3
# Copyright 2020 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.
"""Install the parts of emscripten needed for end users. This works like
a traditional `make dist` target but is written in python so it can be portable
and run on non-unix platforms (basically windows).
"""
import argparse
import fnmatch
import logging
import os
import shutil
import subprocess
import sys
INCLUDES = '''
tests/hello_world.c
'''
EXCLUDES = [os.path.normpath(x) for x in '''
tests/third_party
site
node_modules
Makefile
.git
cache
cache.lock
.circleci
.github
.pc
AUTHORS
ChangeLog.md
CONTRIBUTING.md
debian
docs/graph.png
docs/packaging.md
docs/paper.tex
docs/process.md
emar
embuilder
emcc
emcmake
em-config
emconfigure
emmake
em++
emranlib
emrun
emscons
emsize
emscripten-version.txt.orig
LICENSE
package.json
package-lock.json
README.md
requirements-dev.txt
third_party/websockify
tests
Xtypes
'''.split()]
EXCLUDE_PATTERNS = '''
*.pyc
*.bat
.*
__pycache__
'''.split()
logger = logging.getLogger('install')
def add_revision_file(target):
# text=True would be better than encoding here, but it's only supported in 3.7+
git_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], encoding='utf-8').strip()
with open(os.path.join(target, 'emscripten-revision.txt'), 'w') as f:
f.write(git_hash + '\n')
def copy_emscripten(target):
script_dir = os.path.dirname(os.path.abspath(__file__))
emscripten_root = os.path.dirname(script_dir)
os.chdir(emscripten_root)
for root, dirs, files in os.walk('.'):
# Handle the case where the target directory is underneath emscripten_root
if os.path.abspath(root) == os.path.abspath(target):
dirs.clear()
continue
remove_dirs = []
for d in dirs:
if d in EXCLUDE_PATTERNS:
remove_dirs.append(d)
continue
fulldir = os.path.normpath(os.path.join(root, d))
if fulldir in EXCLUDES and not fulldir in INCLUDES:
remove_dirs.append(d)
continue
os.makedirs(os.path.join(target, fulldir))
for d in remove_dirs:
# Prevent recursion in excluded dirs
logger.debug('skipping dir: ' + os.path.join(root, d))
dirs.remove(d)
for f in files:
if any(fnmatch.fnmatch(f, pat) for pat in EXCLUDE_PATTERNS):
logger.debug('skipping file: ' + os.path.join(root, f))
continue
full = os.path.normpath(os.path.join(root, f))
if full in EXCLUDES and not full in INCLUDES:
logger.debug('skipping file: ' + os.path.join(root, f))
continue
logger.debug('installing file: ' + os.path.join(root, f))
shutil.copy2(full, os.path.join(target, root, f), follow_symlinks=False)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-v', '--verbose', action='store_true', help='verbose',
default=int(os.environ.get('EMCC_DEBUG', '0')))
parser.add_argument('target', help='target directory')
args = parser.parse_args()
target = os.path.abspath(args.target)
if os.path.exists(target):
print('target directory already exists: %s' % target)
return 1
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
os.makedirs(target)
copy_emscripten(target)
#add_revision_file(target)
return 0
if __name__ == '__main__':
sys.exit(main())
|