Skip to content

Commit 714b546

Browse files
committed
Add python2/3 shell execution wrappers for emcmake, emconfigure, emmake and emar, which are called via the shell on OSX.
1 parent 3cee0f2 commit 714b546

8 files changed

Lines changed: 220 additions & 127 deletions

File tree

emar

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,17 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python
22

3-
'''
4-
emar - ar helper script
5-
=======================
3+
# This script should work in python 2 *or* 3. It loads emar.py, which needs python 2.
64

7-
This script acts as a frontend replacement for ar. See emcc.
8-
'''
95

10-
import os, subprocess, sys
11-
from tools import shared
6+
import sys
127

13-
DEBUG = os.environ.get('EMCC_DEBUG')
14-
if DEBUG == "0":
15-
DEBUG = None
168

17-
newargs = [shared.LLVM_AR] + sys.argv[1:]
18-
19-
if DEBUG:
20-
print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs
21-
22-
if len(newargs) > 2:
23-
to_delete = []
24-
if 'r' in newargs[1]:
25-
# we are adding files to the archive.
26-
# find the .a; everything after it is an input file.
27-
# we add a hash to each input, to make them unique as
28-
# possible, as llvm-ar cannot extract duplicate names
29-
# (and only the basename is used!)
30-
i = 1
31-
while i < len(newargs):
32-
if newargs[i].endswith('.a'):
33-
import hashlib, shutil
34-
for j in range(i+1, len(newargs)):
35-
orig_name = newargs[j]
36-
full_name = os.path.abspath(orig_name)
37-
dir_name = os.path.dirname(full_name)
38-
base_name = os.path.basename(full_name)
39-
h = hashlib.md5(full_name).hexdigest()[:8]
40-
parts = base_name.split('.')
41-
parts[0] += '_' + h
42-
newname = '.'.join(parts)
43-
full_newname = os.path.join(dir_name, newname)
44-
if not os.path.exists(full_newname):
45-
try: # it is ok to fail here, we just don't get hashing
46-
shutil.copyfile(orig_name, full_newname)
47-
newargs[j] = full_newname
48-
to_delete.append(full_newname)
49-
except:
50-
pass
51-
break
52-
i += 1
53-
subprocess.call(newargs)
54-
for d in to_delete:
55-
shared.try_delete(d)
569

10+
if sys.version_info.major == 2:
11+
import emar
12+
if __name__ == '__main__':
13+
emar.run()
14+
else:
15+
import os, subprocess
16+
if __name__ == '__main__':
17+
sys.exit(subprocess.call(['python2', os.path.join(os.path.dirname(__file__), 'emar.py')] + sys.argv[1:]))

emar.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python2
2+
3+
'''
4+
emar - ar helper script
5+
=======================
6+
7+
This script acts as a frontend replacement for ar. See emcc.
8+
'''
9+
10+
import os, subprocess, sys
11+
from tools import shared
12+
13+
#
14+
# Main run() function
15+
#
16+
def run():
17+
DEBUG = os.environ.get('EMCC_DEBUG')
18+
if DEBUG == "0":
19+
DEBUG = None
20+
21+
newargs = [shared.LLVM_AR] + sys.argv[1:]
22+
23+
if DEBUG:
24+
print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs
25+
26+
if len(newargs) > 2:
27+
to_delete = []
28+
if 'r' in newargs[1]:
29+
# we are adding files to the archive.
30+
# find the .a; everything after it is an input file.
31+
# we add a hash to each input, to make them unique as
32+
# possible, as llvm-ar cannot extract duplicate names
33+
# (and only the basename is used!)
34+
i = 1
35+
while i < len(newargs):
36+
if newargs[i].endswith('.a'):
37+
import hashlib, shutil
38+
for j in range(i+1, len(newargs)):
39+
orig_name = newargs[j]
40+
full_name = os.path.abspath(orig_name)
41+
dir_name = os.path.dirname(full_name)
42+
base_name = os.path.basename(full_name)
43+
h = hashlib.md5(full_name).hexdigest()[:8]
44+
parts = base_name.split('.')
45+
parts[0] += '_' + h
46+
newname = '.'.join(parts)
47+
full_newname = os.path.join(dir_name, newname)
48+
if not os.path.exists(full_newname):
49+
try: # it is ok to fail here, we just don't get hashing
50+
shutil.copyfile(orig_name, full_newname)
51+
newargs[j] = full_newname
52+
to_delete.append(full_newname)
53+
except:
54+
pass
55+
break
56+
i += 1
57+
subprocess.call(newargs)
58+
for d in to_delete:
59+
shared.try_delete(d)
60+
61+
if __name__ == '__main__':
62+
run()

emcmake

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python
22

3-
import os, subprocess, sys
4-
from tools import shared
3+
# This script should work in python 2 *or* 3. It loads emcmake.py, which needs python 2.
54

6-
configure_path = shared.path_from_root('emconfigure')
75

8-
exit(subprocess.call([shared.PYTHON, configure_path] + sys.argv[1:]))
6+
import sys
7+
8+
9+
10+
if sys.version_info.major == 2:
11+
import emcmake
12+
if __name__ == '__main__':
13+
emcmake.run()
14+
else:
15+
import os, subprocess
16+
if __name__ == '__main__':
17+
sys.exit(subprocess.call(['python2', os.path.join(os.path.dirname(__file__), 'emcmake.py')] + sys.argv[1:]))

emcmake.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python2
2+
3+
import os, subprocess, sys
4+
from tools import shared
5+
6+
#
7+
# Main run() function
8+
#
9+
def run():
10+
configure_path = shared.path_from_root('emconfigure')
11+
12+
exit(subprocess.call([shared.PYTHON, configure_path] + sys.argv[1:]))
13+
14+
if __name__ == '__main__':
15+
run()

emconfigure

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python
22

3-
'''
4-
This is a helper script. It runs ./configure (or cmake,
5-
etc.) for you, setting the environment variables to use
6-
emcc and so forth. Usage:
3+
# This script should work in python 2 *or* 3. It loads emconfigure.py, which needs python 2.
74

8-
emconfigure ./configure [FLAGS]
95

10-
You can also use this for cmake and other configure-like
11-
stages. What happens is that all compilations done during
12-
this command are to native code, not JS, so that configure
13-
tests will work properly.
6+
import sys
147

15-
Relevant defines:
168

17-
CONFIGURE_CC - see emcc
18-
'''
19-
20-
import os, sys
21-
from tools import shared
22-
from subprocess import CalledProcessError
23-
24-
if len(sys.argv) < 2 or ('configure' not in sys.argv[1] and 'cmake' not in sys.argv[1]):
25-
print >> sys.stderr, '''
26-
emconfigure is a helper for configure, setting various environment
27-
variables so that emcc etc. are used. Typical usage:
28-
29-
emconfigure ./configure [FLAGS]
30-
31-
(but you can run any command instead of configure)
32-
33-
'''
34-
elif 'cmake' in sys.argv[1]:
35-
node_js = shared.NODE_JS
36-
if type(node_js) is list: node_js = ' '.join(node_js)
37-
node_js = node_js.replace('"', '\"')
38-
sys.argv = sys.argv[:2] + ['-DCMAKE_CROSSCOMPILING_EMULATOR="' + node_js +'"'] + sys.argv[2:]
39-
40-
try:
41-
shared.Building.configure(sys.argv[1:])
42-
except CalledProcessError, e:
43-
sys.exit(e.returncode)
449

10+
if sys.version_info.major == 2:
11+
import emconfigure
12+
if __name__ == '__main__':
13+
emconfigure.run()
14+
else:
15+
import os, subprocess
16+
if __name__ == '__main__':
17+
sys.exit(subprocess.call(['python2', os.path.join(os.path.dirname(__file__), 'emconfigure.py')] + sys.argv[1:]))

emconfigure.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python2
2+
3+
'''
4+
This is a helper script. It runs ./configure (or cmake,
5+
etc.) for you, setting the environment variables to use
6+
emcc and so forth. Usage:
7+
8+
emconfigure ./configure [FLAGS]
9+
10+
You can also use this for cmake and other configure-like
11+
stages. What happens is that all compilations done during
12+
this command are to native code, not JS, so that configure
13+
tests will work properly.
14+
15+
Relevant defines:
16+
17+
CONFIGURE_CC - see emcc
18+
'''
19+
20+
import os, sys
21+
from tools import shared
22+
from subprocess import CalledProcessError
23+
24+
#
25+
# Main run() function
26+
#
27+
def run():
28+
if len(sys.argv) < 2 or ('configure' not in sys.argv[1] and 'cmake' not in sys.argv[1]):
29+
print >> sys.stderr, '''
30+
emconfigure is a helper for configure, setting various environment
31+
variables so that emcc etc. are used. Typical usage:
32+
33+
emconfigure ./configure [FLAGS]
34+
35+
(but you can run any command instead of configure)
36+
37+
'''
38+
elif 'cmake' in sys.argv[1]:
39+
node_js = shared.NODE_JS
40+
if type(node_js) is list: node_js = ' '.join(node_js)
41+
node_js = node_js.replace('"', '\"')
42+
sys.argv = sys.argv[:2] + ['-DCMAKE_CROSSCOMPILING_EMULATOR="' + node_js +'"'] + sys.argv[2:]
43+
44+
try:
45+
shared.Building.configure(sys.argv[1:])
46+
except CalledProcessError, e:
47+
sys.exit(e.returncode)
48+
49+
if __name__ == '__main__':
50+
run()

emmake

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python
22

3-
'''
4-
This is a helper script. It runs make for you, setting
5-
the environment variables to use emcc and so forth. Usage:
3+
# This script should work in python 2 *or* 3. It loads emmake.py, which needs python 2.
64

7-
emmake make [FLAGS]
85

9-
Note that if you ran configure with emconfigure, then
10-
the environment variables have already been detected
11-
and set. This script is useful if you have no configure
12-
step, and your Makefile uses the environment vars
13-
directly.
6+
import sys
147

15-
The difference between this and emconfigure is that
16-
emconfigure runs compilation into native code, so
17-
that configure tests pass. emmake uses Emscripten to
18-
generate JavaScript.
19-
'''
208

21-
import os, sys
22-
from tools import shared
23-
from subprocess import CalledProcessError
24-
25-
if len(sys.argv) < 2 or sys.argv[1] != 'make':
26-
print >> sys.stderr, '''
27-
emmake is a helper for make, setting various environment
28-
variables so that emcc etc. are used. Typical usage:
29-
30-
emmake make [FLAGS]
31-
32-
(but you can run any command instead of make)
33-
34-
'''
35-
36-
try:
37-
shared.Building.make(sys.argv[1:])
38-
except CalledProcessError, e:
39-
sys.exit(e.returncode)
409

10+
if sys.version_info.major == 2:
11+
import emmake
12+
if __name__ == '__main__':
13+
emmake.run()
14+
else:
15+
import os, subprocess
16+
if __name__ == '__main__':
17+
sys.exit(subprocess.call(['python2', os.path.join(os.path.dirname(__file__), 'emmake.py')] + sys.argv[1:]))

emmake.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python2
2+
3+
'''
4+
This is a helper script. It runs make for you, setting
5+
the environment variables to use emcc and so forth. Usage:
6+
7+
emmake make [FLAGS]
8+
9+
Note that if you ran configure with emconfigure, then
10+
the environment variables have already been detected
11+
and set. This script is useful if you have no configure
12+
step, and your Makefile uses the environment vars
13+
directly.
14+
15+
The difference between this and emconfigure is that
16+
emconfigure runs compilation into native code, so
17+
that configure tests pass. emmake uses Emscripten to
18+
generate JavaScript.
19+
'''
20+
21+
import os, sys
22+
from tools import shared
23+
from subprocess import CalledProcessError
24+
25+
#
26+
# Main run() function
27+
#
28+
def run():
29+
if len(sys.argv) < 2 or sys.argv[1] != 'make':
30+
print >> sys.stderr, '''
31+
emmake is a helper for make, setting various environment
32+
variables so that emcc etc. are used. Typical usage:
33+
34+
emmake make [FLAGS]
35+
36+
(but you can run any command instead of make)
37+
38+
'''
39+
40+
try:
41+
shared.Building.make(sys.argv[1:])
42+
except CalledProcessError, e:
43+
sys.exit(e.returncode)
44+
45+
if __name__ == '__main__':
46+
run()

0 commit comments

Comments
 (0)