| 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 """ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 if not out_ts or not src_ts: | 91 if not out_ts or not src_ts: |
| 92 return True | 92 return True |
| 93 | 93 |
| 94 # If just rebuilt timestamps may be equal due to time granularity. | 94 # If just rebuilt timestamps may be equal due to time granularity. |
| 95 if rebuilt: | 95 if rebuilt: |
| 96 return out_ts < src_ts | 96 return out_ts < src_ts |
| 97 # If about to build, be conservative and rebuilt just in case. | 97 # If about to build, be conservative and rebuilt just in case. |
| 98 return out_ts <= src_ts | 98 return out_ts <= src_ts |
| 99 | 99 |
| 100 | 100 |
| 101 def GetGomaConfig(gomadir, osname, arch, toolname): | 101 def GetGomaPath(osname, arch, toolname): |
| 102 """Returns full-path of gomacc if goma is available or None.""" | 102 """Returns full-path of gomacc if goma is available or None.""" |
| 103 # Start goma support from os/arch/toolname that have been tested. | 103 # Start goma support from os/arch/toolname that have been tested. |
| 104 # Set NO_NACL_GOMA=true to force to avoid using goma. | 104 # Set NO_NACL_GOMA=true to force to avoid using goma. |
| 105 if (osname != 'linux' or arch not in ['x86-32', 'x86-64'] | 105 if (osname != 'linux' or arch not in ['x86-32', 'x86-64'] |
| 106 or toolname not in ['newlib', 'glibc'] | 106 or toolname not in ['newlib', 'glibc'] |
| 107 or os.environ.get('NO_NACL_GOMA')): | 107 or os.environ.get('NO_NACL_GOMA', None)): |
| 108 return {} | 108 return None |
| 109 | 109 |
| 110 goma_config = {} | |
| 111 try: | 110 try: |
| 112 gomacc_base = 'gomacc.exe' if os.name == 'nt' else 'gomacc' | 111 gomacc_base = 'gomacc.exe' if os.name == 'nt' else 'gomacc' |
| 113 # Search order of gomacc: | 112 for directory in os.environ.get('PATH', '').split(os.path.pathsep): |
| 114 # --gomadir command argument -> GOMA_DIR env. -> PATH env. | |
| 115 search_path = [] | |
| 116 # 1. --gomadir in the command argument. | |
| 117 if gomadir: | |
| 118 search_path.append(gomadir) | |
| 119 # 2. Use GOMA_DIR environmental variable if exist. | |
| 120 goma_dir_env = os.environ.get('GOMA_DIR') | |
| 121 if goma_dir_env: | |
| 122 search_path.append(gomadir_env) | |
| 123 # 3. Append PATH env. | |
| 124 path_env = os.environ.get('PATH') | |
| 125 if path_env: | |
| 126 search_path.extend(path_env.split(os.path.pathsep)) | |
| 127 | |
| 128 for directory in search_path: | |
| 129 gomacc = os.path.join(directory, gomacc_base) | 113 gomacc = os.path.join(directory, gomacc_base) |
| 130 if os.path.isfile(gomacc): | 114 if os.path.isfile(gomacc): |
| 131 port = subprocess.Popen( | 115 port = subprocess.Popen( |
| 132 [gomacc, 'port'], stdout=subprocess.PIPE).communicate()[0].strip() | 116 [gomacc, 'port'], stdout=subprocess.PIPE).communicate()[0].strip() |
| 133 if port: | 117 if port: |
| 134 status = urllib2.urlopen( | 118 status = urllib2.urlopen( |
| 135 'http://127.0.0.1:%s/healthz' % port).read().strip() | 119 'http://127.0.0.1:%s/healthz' % port).read().strip() |
| 136 if status == 'ok': | 120 if status == 'ok': |
| 137 goma_config['gomacc'] = gomacc | 121 return gomacc |
| 138 break | |
| 139 except Exception: | 122 except Exception: |
| 140 # Anyway, fallbacks to non-goma mode. | 123 # Anyway, fallbacks to non-goma mode. |
| 141 pass | 124 pass |
| 142 | 125 return None |
| 143 if goma_config: | |
| 144 goma_config['burst'] = False | |
| 145 if osname == 'linux' and not os.environ.get('NO_NACL_GOMA_BURST', None): | |
| 146 goma_config['burst'] = True | |
| 147 return goma_config | |
| 148 | 126 |
| 149 | 127 |
| 150 class Builder(object): | 128 class Builder(object): |
| 151 """Builder object maintains options and generates build command-lines. | 129 """Builder object maintains options and generates build command-lines. |
| 152 | 130 |
| 153 The Builder object takes a set of script command-line options, and generates | 131 The Builder object takes a set of script command-line options, and generates |
| 154 a set of paths, and command-line options for the NaCl toolchain. | 132 a set of paths, and command-line options for the NaCl toolchain. |
| 155 """ | 133 """ |
| 156 def __init__(self, options): | 134 def __init__(self, options): |
| 157 arch = options.arch | 135 arch = options.arch |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 self.BuildCompileOptions(options.compile_flags, self.define_list) | 216 self.BuildCompileOptions(options.compile_flags, self.define_list) |
| 239 self.BuildLinkOptions(options.link_flags) | 217 self.BuildLinkOptions(options.link_flags) |
| 240 self.BuildArchiveOptions() | 218 self.BuildArchiveOptions() |
| 241 self.verbose = options.verbose | 219 self.verbose = options.verbose |
| 242 self.suffix = options.suffix | 220 self.suffix = options.suffix |
| 243 self.strip = options.strip | 221 self.strip = options.strip |
| 244 self.empty = options.empty | 222 self.empty = options.empty |
| 245 self.strip_all = options.strip_all | 223 self.strip_all = options.strip_all |
| 246 self.strip_debug = options.strip_debug | 224 self.strip_debug = options.strip_debug |
| 247 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' | 225 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' |
| 248 goma_config = GetGomaConfig(options.gomadir, self.osname, arch, toolname) | 226 self.gomacc = GetGomaPath(self.osname, arch, toolname) |
| 249 self.gomacc = goma_config.get('gomacc', '') | |
| 250 self.goma_burst = goma_config.get('burst', False) | |
| 251 | 227 |
| 252 # Use unoptimized native objects for debug IRT builds for faster compiles. | 228 # Use unoptimized native objects for debug IRT builds for faster compiles. |
| 253 if (self.is_pnacl_toolchain | 229 if (self.is_pnacl_toolchain |
| 254 and (self.outtype == 'nlib' | 230 and (self.outtype == 'nlib' |
| 255 or self.outtype == 'nexe') | 231 or self.outtype == 'nexe') |
| 256 and self.arch != 'pnacl'): | 232 and self.arch != 'pnacl'): |
| 257 if (options.build_config is not None | 233 if (options.build_config is not None |
| 258 and options.build_config == 'Debug'): | 234 and options.build_config == 'Debug'): |
| 259 self.compile_options.extend(['--pnacl-allow-translate', | 235 self.compile_options.extend(['--pnacl-allow-translate', |
| 260 '--pnacl-allow-native', | 236 '--pnacl-allow-native', |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 parser.add_option('--defines', dest='defines', | 690 parser.add_option('--defines', dest='defines', |
| 715 help='Set defines') | 691 help='Set defines') |
| 716 parser.add_option('--link_flags', dest='link_flags', | 692 parser.add_option('--link_flags', dest='link_flags', |
| 717 help='Set link flags.') | 693 help='Set link flags.') |
| 718 parser.add_option('-v', '--verbose', dest='verbose', default=False, | 694 parser.add_option('-v', '--verbose', dest='verbose', default=False, |
| 719 help='Enable verbosity', action='store_true') | 695 help='Enable verbosity', action='store_true') |
| 720 parser.add_option('-t', '--toolpath', dest='toolpath', | 696 parser.add_option('-t', '--toolpath', dest='toolpath', |
| 721 help='Set the path for of the toolchains.') | 697 help='Set the path for of the toolchains.') |
| 722 parser.add_option('--config-name', dest='build_config', | 698 parser.add_option('--config-name', dest='build_config', |
| 723 help='GYP build configuration name (Release/Debug)') | 699 help='GYP build configuration name (Release/Debug)') |
| 724 parser.add_option('--gomadir', dest='gomadir', | |
| 725 help='Path of the goma directory.') | |
| 726 options, files = parser.parse_args(argv[1:]) | 700 options, files = parser.parse_args(argv[1:]) |
| 727 | 701 |
| 728 if not argv: | 702 if not argv: |
| 729 parser.print_help() | 703 parser.print_help() |
| 730 return 1 | 704 return 1 |
| 731 | 705 |
| 732 try: | 706 try: |
| 733 if options.source_list: | 707 if options.source_list: |
| 734 source_list_handle = open(options.source_list, 'r') | 708 source_list_handle = open(options.source_list, 'r') |
| 735 source_list = source_list_handle.read().splitlines() | 709 source_list = source_list_handle.read().splitlines() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 750 build = Builder(options) | 724 build = Builder(options) |
| 751 objs = [] | 725 objs = [] |
| 752 | 726 |
| 753 if build.outtype == 'translate': | 727 if build.outtype == 'translate': |
| 754 # Just translate a pexe to a nexe | 728 # Just translate a pexe to a nexe |
| 755 if len(files) != 1: | 729 if len(files) != 1: |
| 756 parser.error('Pexe translation requires exactly one input file.') | 730 parser.error('Pexe translation requires exactly one input file.') |
| 757 build.Translate(list(files)[0]) | 731 build.Translate(list(files)[0]) |
| 758 return 0 | 732 return 0 |
| 759 | 733 |
| 760 if build.gomacc and build.goma_burst: # execute gomacc as many as possible. | 734 if build.gomacc: # use goma build. |
| 761 returns = Queue.Queue() | 735 returns = Queue.Queue() |
| 762 def CompileThread(filename, queue): | 736 def CompileThread(filename, queue): |
| 763 try: | 737 try: |
| 764 queue.put(build.Compile(filename)) | 738 queue.put(build.Compile(filename)) |
| 765 except Exception: | 739 except Exception: |
| 766 # Put current exception info to the queue. | 740 # Put current exception info to the queue. |
| 767 queue.put(sys.exc_info()) | 741 queue.put(sys.exc_info()) |
| 768 build_threads = [] | 742 build_threads = [] |
| 769 # Start parallel build. | 743 # Start parallel build. |
| 770 for filename in files: | 744 for filename in files: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 795 shutil.copy(objs[0], options.name) | 769 shutil.copy(objs[0], options.name) |
| 796 else: | 770 else: |
| 797 build.Generate(objs) | 771 build.Generate(objs) |
| 798 return 0 | 772 return 0 |
| 799 except Error as e: | 773 except Error as e: |
| 800 sys.stderr.write('%s\n' % e) | 774 sys.stderr.write('%s\n' % e) |
| 801 return 1 | 775 return 1 |
| 802 | 776 |
| 803 if __name__ == '__main__': | 777 if __name__ == '__main__': |
| 804 sys.exit(Main(sys.argv)) | 778 sys.exit(Main(sys.argv)) |
| OLD | NEW |