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 not in ['linux'] |
bradn
2013/11/12 22:32:56
why this change?
Yoshisato Yanagisawa
2013/11/12 23:01:24
For ease of adding new OS but I understand one cha
| |
106 or arch not in ['x86-32', 'x86-64'] | |
106 or toolname not in ['newlib', 'glibc'] | 107 or toolname not in ['newlib', 'glibc'] |
107 or os.environ.get('NO_NACL_GOMA', None)): | 108 or os.environ.get('NO_NACL_GOMA', None)): |
108 return None | 109 return {} |
109 | 110 |
111 goma_config = {} | |
110 try: | 112 try: |
111 gomacc_base = 'gomacc.exe' if os.name == 'nt' else 'gomacc' | 113 gomacc_base = 'gomacc.exe' if os.name == 'nt' else 'gomacc' |
112 for directory in os.environ.get('PATH', '').split(os.path.pathsep): | 114 search_path = os.environ.get('PATH', '').split(os.path.pathsep) |
115 # Use GOMA_DIR environmental variable if exist. | |
116 goma_dir_env = os.environ.get('GOMA_DIR', None) | |
117 if goma_dir_env: | |
118 search_path.insert(0, gomadir_env) | |
119 # Use gomadir in the command argument. | |
bradn
2013/11/12 22:32:56
Maybe make clear that the command line trumps the
Yoshisato Yanagisawa
2013/11/12 23:01:24
Done.
| |
120 if gomadir: | |
121 search_path.insert(0, gomadir) | |
122 for directory in search_path: | |
113 gomacc = os.path.join(directory, gomacc_base) | 123 gomacc = os.path.join(directory, gomacc_base) |
114 if os.path.isfile(gomacc): | 124 if os.path.isfile(gomacc): |
115 port = subprocess.Popen( | 125 port = subprocess.Popen( |
116 [gomacc, 'port'], stdout=subprocess.PIPE).communicate()[0].strip() | 126 [gomacc, 'port'], stdout=subprocess.PIPE).communicate()[0].strip() |
117 if port: | 127 if port: |
118 status = urllib2.urlopen( | 128 status = urllib2.urlopen( |
119 'http://127.0.0.1:%s/healthz' % port).read().strip() | 129 'http://127.0.0.1:%s/healthz' % port).read().strip() |
120 if status == 'ok': | 130 if status == 'ok': |
121 return gomacc | 131 goma_config['gomacc'] = gomacc |
132 break | |
122 except Exception: | 133 except Exception: |
123 # Anyway, fallbacks to non-goma mode. | 134 # Anyway, fallbacks to non-goma mode. |
124 pass | 135 pass |
125 return None | 136 |
137 if goma_config: | |
138 goma_config['burst'] = False | |
139 if osname == 'linux' and not os.environ.get('NO_NACL_GOMA_BURST', None): | |
140 goma_config['burst'] = True | |
141 return goma_config | |
126 | 142 |
127 | 143 |
128 class Builder(object): | 144 class Builder(object): |
129 """Builder object maintains options and generates build command-lines. | 145 """Builder object maintains options and generates build command-lines. |
130 | 146 |
131 The Builder object takes a set of script command-line options, and generates | 147 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. | 148 a set of paths, and command-line options for the NaCl toolchain. |
133 """ | 149 """ |
134 def __init__(self, options): | 150 def __init__(self, options): |
135 arch = options.arch | 151 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) | 232 self.BuildCompileOptions(options.compile_flags, self.define_list) |
217 self.BuildLinkOptions(options.link_flags) | 233 self.BuildLinkOptions(options.link_flags) |
218 self.BuildArchiveOptions() | 234 self.BuildArchiveOptions() |
219 self.verbose = options.verbose | 235 self.verbose = options.verbose |
220 self.suffix = options.suffix | 236 self.suffix = options.suffix |
221 self.strip = options.strip | 237 self.strip = options.strip |
222 self.empty = options.empty | 238 self.empty = options.empty |
223 self.strip_all = options.strip_all | 239 self.strip_all = options.strip_all |
224 self.strip_debug = options.strip_debug | 240 self.strip_debug = options.strip_debug |
225 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' | 241 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' |
226 self.gomacc = GetGomaPath(self.osname, arch, toolname) | 242 goma_config = GetGomaConfig(options.gomadir, self.osname, arch, toolname) |
243 self.gomacc = goma_config.get('gomacc', '') | |
244 self.goma_burst = goma_config.get('burst', False) | |
227 | 245 |
228 # Use unoptimized native objects for debug IRT builds for faster compiles. | 246 # Use unoptimized native objects for debug IRT builds for faster compiles. |
229 if (self.is_pnacl_toolchain | 247 if (self.is_pnacl_toolchain |
230 and (self.outtype == 'nlib' | 248 and (self.outtype == 'nlib' |
231 or self.outtype == 'nexe') | 249 or self.outtype == 'nexe') |
232 and self.arch != 'pnacl'): | 250 and self.arch != 'pnacl'): |
233 if (options.build_config is not None | 251 if (options.build_config is not None |
234 and options.build_config == 'Debug'): | 252 and options.build_config == 'Debug'): |
235 self.compile_options.extend(['--pnacl-allow-translate', | 253 self.compile_options.extend(['--pnacl-allow-translate', |
236 '--pnacl-allow-native', | 254 '--pnacl-allow-native', |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 parser.add_option('--defines', dest='defines', | 708 parser.add_option('--defines', dest='defines', |
691 help='Set defines') | 709 help='Set defines') |
692 parser.add_option('--link_flags', dest='link_flags', | 710 parser.add_option('--link_flags', dest='link_flags', |
693 help='Set link flags.') | 711 help='Set link flags.') |
694 parser.add_option('-v', '--verbose', dest='verbose', default=False, | 712 parser.add_option('-v', '--verbose', dest='verbose', default=False, |
695 help='Enable verbosity', action='store_true') | 713 help='Enable verbosity', action='store_true') |
696 parser.add_option('-t', '--toolpath', dest='toolpath', | 714 parser.add_option('-t', '--toolpath', dest='toolpath', |
697 help='Set the path for of the toolchains.') | 715 help='Set the path for of the toolchains.') |
698 parser.add_option('--config-name', dest='build_config', | 716 parser.add_option('--config-name', dest='build_config', |
699 help='GYP build configuration name (Release/Debug)') | 717 help='GYP build configuration name (Release/Debug)') |
718 parser.add_option('--gomadir', dest='gomadir', | |
719 help='Path of the goma directory.') | |
700 options, files = parser.parse_args(argv[1:]) | 720 options, files = parser.parse_args(argv[1:]) |
701 | 721 |
702 if not argv: | 722 if not argv: |
703 parser.print_help() | 723 parser.print_help() |
704 return 1 | 724 return 1 |
705 | 725 |
706 try: | 726 try: |
707 if options.source_list: | 727 if options.source_list: |
708 source_list_handle = open(options.source_list, 'r') | 728 source_list_handle = open(options.source_list, 'r') |
709 source_list = source_list_handle.read().splitlines() | 729 source_list = source_list_handle.read().splitlines() |
(...skipping 14 matching lines...) Expand all Loading... | |
724 build = Builder(options) | 744 build = Builder(options) |
725 objs = [] | 745 objs = [] |
726 | 746 |
727 if build.outtype == 'translate': | 747 if build.outtype == 'translate': |
728 # Just translate a pexe to a nexe | 748 # Just translate a pexe to a nexe |
729 if len(files) != 1: | 749 if len(files) != 1: |
730 parser.error('Pexe translation requires exactly one input file.') | 750 parser.error('Pexe translation requires exactly one input file.') |
731 build.Translate(list(files)[0]) | 751 build.Translate(list(files)[0]) |
732 return 0 | 752 return 0 |
733 | 753 |
734 if build.gomacc: # use goma build. | 754 if build.gomacc and build.goma_burst: # execute gomacc as many as possible. |
735 returns = Queue.Queue() | 755 returns = Queue.Queue() |
736 def CompileThread(filename, queue): | 756 def CompileThread(filename, queue): |
737 try: | 757 try: |
738 queue.put(build.Compile(filename)) | 758 queue.put(build.Compile(filename)) |
739 except Exception: | 759 except Exception: |
740 # Put current exception info to the queue. | 760 # Put current exception info to the queue. |
741 queue.put(sys.exc_info()) | 761 queue.put(sys.exc_info()) |
742 build_threads = [] | 762 build_threads = [] |
743 # Start parallel build. | 763 # Start parallel build. |
744 for filename in files: | 764 for filename in files: |
(...skipping 24 matching lines...) Expand all Loading... | |
769 shutil.copy(objs[0], options.name) | 789 shutil.copy(objs[0], options.name) |
770 else: | 790 else: |
771 build.Generate(objs) | 791 build.Generate(objs) |
772 return 0 | 792 return 0 |
773 except Error as e: | 793 except Error as e: |
774 sys.stderr.write('%s\n' % e) | 794 sys.stderr.write('%s\n' % e) |
775 return 1 | 795 return 1 |
776 | 796 |
777 if __name__ == '__main__': | 797 if __name__ == '__main__': |
778 sys.exit(Main(sys.argv)) | 798 sys.exit(Main(sys.argv)) |
OLD | NEW |