| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Native Client Authors. All rights reserved. | 2 # Copyright 2015 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 """Download the Emscripten SDK for the current platform. | 5 """Download the Emscripten SDK for the current platform. |
| 6 | 6 |
| 7 This script downloads the emscripten tarball and expands it. | 7 This script downloads the emscripten tarball and expands it. |
| 8 It requires gsutil to be in the bin PATH and is currently | 8 It requires gsutil to be in the bin PATH and is currently |
| 9 supported on Linux and Mac OSX and not windows. | 9 supported on Linux and Mac OSX and not windows. |
| 10 | |
| 11 Additional prerequisites include cmake, node.js and Java. | |
| 12 """ | 10 """ |
| 13 | 11 |
| 14 import os | 12 import os |
| 15 import subprocess | 13 import subprocess |
| 16 import sys | 14 import sys |
| 17 import tarfile | 15 import tarfile |
| 18 | 16 |
| 19 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 20 NACLPORTS_ROOT = os.path.dirname(SCRIPT_DIR) | 18 NACLPORTS_ROOT = os.path.dirname(SCRIPT_DIR) |
| 21 sys.path.append(os.path.join(NACLPORTS_ROOT, 'lib')) | 19 sys.path.append(os.path.join(NACLPORTS_ROOT, 'lib')) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 naclports.Log("Verified cached file: %s" % filename) | 47 naclports.Log("Verified cached file: %s" % filename) |
| 50 return full_name | 48 return full_name |
| 51 except naclports.util.HashVerificationError: | 49 except naclports.util.HashVerificationError: |
| 52 naclports.Log("Hash mistmatch on cached download: %s" % filename) | 50 naclports.Log("Hash mistmatch on cached download: %s" % filename) |
| 53 | 51 |
| 54 naclports.DownloadFile(full_name, url) | 52 naclports.DownloadFile(full_name, url) |
| 55 naclports.util.VerifyHash(full_name, sha1) | 53 naclports.util.VerifyHash(full_name, sha1) |
| 56 return full_name | 54 return full_name |
| 57 | 55 |
| 58 | 56 |
| 59 def DownloadAndExtract(url, sha1, target_dir): | 57 def DownloadAndExtract(url, sha1, target_dir, link_name=None): |
| 60 tar_file = DownloadToCache(url, sha1) | 58 tar_file = DownloadToCache(url, sha1) |
| 61 | 59 |
| 62 if not os.path.exists(OUT_DIR): | 60 if not os.path.exists(OUT_DIR): |
| 63 os.makedirs(OUT_DIR) | 61 os.makedirs(OUT_DIR) |
| 64 | 62 |
| 65 os.chdir(OUT_DIR) | 63 os.chdir(OUT_DIR) |
| 66 | 64 |
| 67 # Remove previously extracted archive | 65 # Remove previously extracted archive |
| 68 if os.path.exists(target_dir): | 66 if os.path.exists(target_dir): |
| 69 naclports.Log('Cleaning up existing %s...' % target_dir) | 67 naclports.Log('Cleaning up existing %s...' % target_dir) |
| 70 cmd = ['rm', '-rf'] | 68 cmd = ['rm', '-rf'] |
| 71 cmd.append(target_dir) | 69 cmd.append(target_dir) |
| 72 subprocess.check_call(cmd) | 70 subprocess.check_call(cmd) |
| 73 | 71 |
| 74 # Extract archive | 72 # Extract archive |
| 75 naclports.Log('Exctacting %s...' % os.path.basename(tar_file)) | 73 naclports.Log('Exctacting %s...' % os.path.basename(tar_file)) |
| 76 if subprocess.call(['tar', 'xf', tar_file]): | 74 if subprocess.call(['tar', 'xf', tar_file]): |
| 77 raise naclports.Error('Error unpacking Emscripten SDK') | 75 raise naclports.Error('Error unpacking Emscripten SDK') |
| 78 | 76 |
| 77 if link_name: |
| 78 if os.path.exists(link_name): |
| 79 os.remove(link_name) |
| 80 os.symlink(target_dir, link_name) |
| 81 |
| 82 |
| 83 def BuildOptimizer(): |
| 84 emsdk_root = os.path.join(OUT_DIR, 'emsdk') |
| 85 node_bin = os.path.join(OUT_DIR, 'node', 'bin') |
| 86 emscripten_root = os.path.join(emsdk_root, 'emscripten') |
| 87 os.environ['EMSDK_ROOT'] = emscripten_root |
| 88 os.environ['EM_CONFIG'] = os.path.join(emsdk_root, '.emscripten') |
| 89 os.environ['PATH'] += ':' + node_bin |
| 90 os.environ['PATH'] += ':' + emscripten_root |
| 91 |
| 92 # Run using -O2 to compile the native js-optimizer |
| 93 open('test.c', 'w').close() |
| 94 subprocess.check_call(['emcc', '-O2', '-o', 'test.js', 'test.c']) |
| 95 os.remove('test.js') |
| 96 os.remove('test.c') |
| 97 return 0 |
| 98 |
| 79 | 99 |
| 80 def main(argv): | 100 def main(argv): |
| 81 if sys.platform in ['win32', 'cygwin']: | 101 if sys.platform in ['win32', 'cygwin']: |
| 82 naclports.Error('Emscripten support is currently not available on Windows.') | 102 naclports.Error('Emscripten support is currently not available on Windows.') |
| 83 return 1 | 103 return 1 |
| 84 | 104 |
| 85 DownloadAndExtract(EMSDK_URL, EMSDK_SHA1, 'emsdk') | 105 DownloadAndExtract(EMSDK_URL, EMSDK_SHA1, 'emsdk') |
| 86 DownloadAndExtract(NODEJS_URL, NODEJS_SHA1, 'node-v0.12.1-linux-x64') | 106 DownloadAndExtract(NODEJS_URL, NODEJS_SHA1, 'node-v0.12.1-linux-x64', 'node') |
| 107 BuildOptimizer() |
| 108 |
| 87 naclports.Log('Emscripten SDK Install complete') | 109 naclports.Log('Emscripten SDK Install complete') |
| 88 return 0 | 110 return 0 |
| 89 | 111 |
| 90 | 112 |
| 91 if __name__ == '__main__': | 113 if __name__ == '__main__': |
| 92 try: | 114 try: |
| 93 rtn = main(sys.argv[1:]) | 115 rtn = main(sys.argv[1:]) |
| 94 except naclports.Error as e: | 116 except naclports.Error as e: |
| 95 sys.stderr.write('error: %s\n' % str(e)) | 117 sys.stderr.write('error: %s\n' % str(e)) |
| 96 rtn = 1 | 118 rtn = 1 |
| OLD | NEW |