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