| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 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 | 5 |
| 6 """NEXE building script | 6 """NEXE building script |
| 7 | 7 |
| 8 This module will take a set of source files, include paths, library paths, and | 8 This module will take a set of source files, include paths, library paths, and |
| 9 additional arguments, and use them to build. | 9 additional arguments, and use them to build. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import hashlib |
| 12 from optparse import OptionParser | 13 from optparse import OptionParser |
| 13 import os | 14 import os |
| 14 import re | 15 import re |
| 15 import Queue | 16 import Queue |
| 16 import shutil | 17 import shutil |
| 17 import subprocess | 18 import subprocess |
| 18 import sys | 19 import sys |
| 19 import tempfile | 20 import tempfile |
| 20 import threading | 21 import threading |
| 21 import urllib2 | 22 import urllib2 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 def RemoveFile(path): | 60 def RemoveFile(path): |
| 60 os.remove(FixPath(path)) | 61 os.remove(FixPath(path)) |
| 61 | 62 |
| 62 | 63 |
| 63 def OpenFile(path, mode='r'): | 64 def OpenFile(path, mode='r'): |
| 64 return open(FixPath(path), mode) | 65 return open(FixPath(path), mode) |
| 65 | 66 |
| 66 | 67 |
| 67 def RemoveQuotes(opt): | 68 def RemoveQuotes(opt): |
| 68 if opt and opt[0] == '"': | 69 if opt and opt[0] == '"': |
| 69 return opt[1:-1] | 70 assert opt[-1] == '"', opt |
| 71 return opt[1:-1].replace('\\"', '"') |
| 70 return opt | 72 return opt |
| 71 | 73 |
| 72 | 74 |
| 73 def ArgToList(opt): | 75 def ArgToList(opt): |
| 74 outlist = [] | 76 outlist = [] |
| 75 if opt is None: | 77 if opt is None: |
| 76 return outlist | 78 return outlist |
| 77 optlist = RemoveQuotes(opt).split(' ') | 79 optlist = opt.split(' ') |
| 78 for optitem in optlist: | 80 for optitem in optlist: |
| 79 optitem = RemoveQuotes(optitem).replace('\\"', '"') | 81 optitem = RemoveQuotes(optitem) |
| 80 if optitem: | 82 if optitem: |
| 81 outlist.append(optitem) | 83 outlist.append(optitem) |
| 82 return outlist | 84 return outlist |
| 83 | 85 |
| 84 | 86 |
| 85 def GetMTime(filepath): | 87 def GetMTime(filepath): |
| 86 """GetMTime returns the last modification time of the file or None.""" | 88 """GetMTime returns the last modification time of the file or None.""" |
| 87 try: | 89 try: |
| 88 return os.path.getmtime(FixPath(filepath)) | 90 return os.path.getmtime(FixPath(filepath)) |
| 89 except OSError: | 91 except OSError: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 222 |
| 221 self.inc_paths = ArgToList(options.incdirs) | 223 self.inc_paths = ArgToList(options.incdirs) |
| 222 self.lib_paths = ArgToList(options.libdirs) | 224 self.lib_paths = ArgToList(options.libdirs) |
| 223 self.define_list = ArgToList(options.defines) | 225 self.define_list = ArgToList(options.defines) |
| 224 | 226 |
| 225 self.name = options.name | 227 self.name = options.name |
| 226 self.BuildCompileOptions(options.compile_flags, self.define_list) | 228 self.BuildCompileOptions(options.compile_flags, self.define_list) |
| 227 self.BuildLinkOptions(options.link_flags) | 229 self.BuildLinkOptions(options.link_flags) |
| 228 self.BuildArchiveOptions() | 230 self.BuildArchiveOptions() |
| 229 self.verbose = options.verbose | 231 self.verbose = options.verbose |
| 230 self.suffix = options.suffix | |
| 231 self.strip = options.strip | 232 self.strip = options.strip |
| 232 self.empty = options.empty | 233 self.empty = options.empty |
| 233 self.strip_all = options.strip_all | 234 self.strip_all = options.strip_all |
| 234 self.strip_debug = options.strip_debug | 235 self.strip_debug = options.strip_debug |
| 235 self.tls_edit = options.tls_edit | 236 self.tls_edit = options.tls_edit |
| 236 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' | 237 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' |
| 237 goma_config = self.GetGomaConfig(options.gomadir, arch, toolname) | 238 goma_config = self.GetGomaConfig(options.gomadir, arch, toolname) |
| 238 self.gomacc = goma_config.get('gomacc', '') | 239 self.gomacc = goma_config.get('gomacc', '') |
| 239 self.goma_burst = goma_config.get('burst', False) | 240 self.goma_burst = goma_config.get('burst', False) |
| 240 self.goma_threads = goma_config.get('threads', 1) | 241 self.goma_threads = goma_config.get('threads', 1) |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 except Exception as err: | 429 except Exception as err: |
| 429 raise Error('%s\nFAILED: %s' % (' '.join(cmd_line), str(err))) | 430 raise Error('%s\nFAILED: %s' % (' '.join(cmd_line), str(err))) |
| 430 finally: | 431 finally: |
| 431 if temp_file is not None: | 432 if temp_file is not None: |
| 432 RemoveFile(temp_file.name) | 433 RemoveFile(temp_file.name) |
| 433 return result | 434 return result |
| 434 | 435 |
| 435 def GetObjectName(self, src): | 436 def GetObjectName(self, src): |
| 436 if self.strip: | 437 if self.strip: |
| 437 src = src.replace(self.strip,'') | 438 src = src.replace(self.strip,'') |
| 439 # Hash the full path of the source file and add 32 bits of that hash onto |
| 440 # the end of the object file name. This helps disambiguate files with the |
| 441 # same name, because all of the object files are placed into the same |
| 442 # directory. Technically, the correct solution would be to preserve the |
| 443 # directory structure of the input source files inside the object file |
| 444 # directory, but doing that runs the risk of running into filename length |
| 445 # issues on Windows. |
| 446 h = hashlib.sha1() |
| 447 h.update(src) |
| 448 wart = h.hexdigest()[:8] |
| 438 _, filename = os.path.split(src) | 449 _, filename = os.path.split(src) |
| 439 filename, _ = os.path.splitext(filename) | 450 filename, _ = os.path.splitext(filename) |
| 440 if self.suffix: | 451 return os.path.join(self.outdir, filename + '_' + wart + '.o') |
| 441 return os.path.join(self.outdir, filename + '.o') | |
| 442 else: | |
| 443 filename = os.path.split(src)[1] | |
| 444 return os.path.join(self.outdir, os.path.splitext(filename)[0] + '.o') | |
| 445 | 452 |
| 446 def CleanOutput(self, out): | 453 def CleanOutput(self, out): |
| 447 if IsFile(out): | 454 if IsFile(out): |
| 448 RemoveFile(out) | 455 RemoveFile(out) |
| 449 | 456 |
| 450 def FixWindowsPath(self, path): | 457 def FixWindowsPath(self, path): |
| 451 # The windows version of the nacl toolchain returns badly | 458 # The windows version of the nacl toolchain returns badly |
| 452 # formed system header paths. As we do want changes in the | 459 # formed system header paths. As we do want changes in the |
| 453 # toolchain to trigger rebuilds, compensate by detecting | 460 # toolchain to trigger rebuilds, compensate by detecting |
| 454 # malformed paths (starting with /libexec/) and assume these | 461 # malformed paths (starting with /libexec/) and assume these |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 else: | 876 else: |
| 870 raise Error('FAILED: Unknown outtype: %s' % (self.outtype)) | 877 raise Error('FAILED: Unknown outtype: %s' % (self.outtype)) |
| 871 | 878 |
| 872 | 879 |
| 873 def Main(argv): | 880 def Main(argv): |
| 874 parser = OptionParser() | 881 parser = OptionParser() |
| 875 parser.add_option('--empty', dest='empty', default=False, | 882 parser.add_option('--empty', dest='empty', default=False, |
| 876 help='Do not pass sources to library.', action='store_true') | 883 help='Do not pass sources to library.', action='store_true') |
| 877 parser.add_option('--no-suffix', dest='suffix', default=True, | 884 parser.add_option('--no-suffix', dest='suffix', default=True, |
| 878 help='Do not append arch suffix.', action='store_false') | 885 help='Do not append arch suffix.', action='store_false') |
| 879 parser.add_option('--sufix', dest='suffix', | |
| 880 help='Do append arch suffix.', action='store_true') | |
| 881 parser.add_option('--strip-debug', dest='strip_debug', default=False, | 886 parser.add_option('--strip-debug', dest='strip_debug', default=False, |
| 882 help='Strip the NEXE for debugging', action='store_true') | 887 help='Strip the NEXE for debugging', action='store_true') |
| 883 parser.add_option('--strip-all', dest='strip_all', default=False, | 888 parser.add_option('--strip-all', dest='strip_all', default=False, |
| 884 help='Strip the NEXE for production', action='store_true') | 889 help='Strip the NEXE for production', action='store_true') |
| 885 parser.add_option('--strip', dest='strip', default='', | 890 parser.add_option('--strip', dest='strip', default='', |
| 886 help='Strip the filename') | 891 help='Strip the filename') |
| 887 parser.add_option('--nonstable-pnacl', dest='finalize_pexe', default=True, | 892 parser.add_option('--nonstable-pnacl', dest='finalize_pexe', default=True, |
| 888 help='Do not finalize pnacl bitcode for ABI stability', | 893 help='Do not finalize pnacl bitcode for ABI stability', |
| 889 action='store_false') | 894 action='store_false') |
| 890 parser.add_option('--source-list', dest='source_list', | 895 parser.add_option('--source-list', dest='source_list', |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 shutil.copy(objs[0], options.name) | 1031 shutil.copy(objs[0], options.name) |
| 1027 else: | 1032 else: |
| 1028 build.Generate(objs) | 1033 build.Generate(objs) |
| 1029 return 0 | 1034 return 0 |
| 1030 except Error as e: | 1035 except Error as e: |
| 1031 sys.stderr.write('%s\n' % e) | 1036 sys.stderr.write('%s\n' % e) |
| 1032 return 1 | 1037 return 1 |
| 1033 | 1038 |
| 1034 if __name__ == '__main__': | 1039 if __name__ == '__main__': |
| 1035 sys.exit(Main(sys.argv)) | 1040 sys.exit(Main(sys.argv)) |
| OLD | NEW |