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 GetGomaPath(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'): |
108 return None | 108 return None |
109 | 109 |
110 try: | 110 try: |
111 gomacc_base = 'gomacc.exe' if os.name == 'nt' else 'gomacc' | 111 gomacc_base = 'gomacc.exe' if os.name == 'nt' else 'gomacc' |
112 for directory in os.environ.get('PATH', '').split(os.path.pathsep): | 112 # Search order of gomacc: |
| 113 # --gomadir command argument -> GOMA_DIR env. -> PATH env. |
| 114 search_path = [] |
| 115 # 1. --gomadir in the command argument. |
| 116 if gomadir: |
| 117 search_path.append(gomadir) |
| 118 # 2. Use GOMA_DIR environment variable if exist. |
| 119 goma_dir_env = os.environ.get('GOMA_DIR') |
| 120 if goma_dir_env: |
| 121 search_path.append(gomadir_env) |
| 122 # 3. Append PATH env. |
| 123 path_env = os.environ.get('PATH') |
| 124 if path_env: |
| 125 search_path.extend(path_env.split(os.path.pathsep)) |
| 126 |
| 127 for directory in search_path: |
113 gomacc = os.path.join(directory, gomacc_base) | 128 gomacc = os.path.join(directory, gomacc_base) |
114 if os.path.isfile(gomacc): | 129 if os.path.isfile(gomacc): |
115 port = subprocess.Popen( | 130 port = subprocess.Popen( |
116 [gomacc, 'port'], stdout=subprocess.PIPE).communicate()[0].strip() | 131 [gomacc, 'port'], stdout=subprocess.PIPE).communicate()[0].strip() |
117 if port: | 132 if port: |
118 status = urllib2.urlopen( | 133 status = urllib2.urlopen( |
119 'http://127.0.0.1:%s/healthz' % port).read().strip() | 134 'http://127.0.0.1:%s/healthz' % port).read().strip() |
120 if status == 'ok': | 135 if status == 'ok': |
121 return gomacc | 136 return gomacc |
122 except Exception: | 137 except Exception: |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 self.BuildCompileOptions(options.compile_flags, self.define_list) | 231 self.BuildCompileOptions(options.compile_flags, self.define_list) |
217 self.BuildLinkOptions(options.link_flags) | 232 self.BuildLinkOptions(options.link_flags) |
218 self.BuildArchiveOptions() | 233 self.BuildArchiveOptions() |
219 self.verbose = options.verbose | 234 self.verbose = options.verbose |
220 self.suffix = options.suffix | 235 self.suffix = options.suffix |
221 self.strip = options.strip | 236 self.strip = options.strip |
222 self.empty = options.empty | 237 self.empty = options.empty |
223 self.strip_all = options.strip_all | 238 self.strip_all = options.strip_all |
224 self.strip_debug = options.strip_debug | 239 self.strip_debug = options.strip_debug |
225 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' | 240 self.finalize_pexe = options.finalize_pexe and arch == 'pnacl' |
226 self.gomacc = GetGomaPath(self.osname, arch, toolname) | 241 self.gomacc = GetGomaPath(options.gomadir, self.osname, arch, toolname) |
227 | 242 |
228 # Use unoptimized native objects for debug IRT builds for faster compiles. | 243 # Use unoptimized native objects for debug IRT builds for faster compiles. |
229 if (self.is_pnacl_toolchain | 244 if (self.is_pnacl_toolchain |
230 and (self.outtype == 'nlib' | 245 and (self.outtype == 'nlib' |
231 or self.outtype == 'nexe') | 246 or self.outtype == 'nexe') |
232 and self.arch != 'pnacl'): | 247 and self.arch != 'pnacl'): |
233 if (options.build_config is not None | 248 if (options.build_config is not None |
234 and options.build_config == 'Debug'): | 249 and options.build_config == 'Debug'): |
235 self.compile_options.extend(['--pnacl-allow-translate', | 250 self.compile_options.extend(['--pnacl-allow-translate', |
236 '--pnacl-allow-native', | 251 '--pnacl-allow-native', |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 parser.add_option('--defines', dest='defines', | 705 parser.add_option('--defines', dest='defines', |
691 help='Set defines') | 706 help='Set defines') |
692 parser.add_option('--link_flags', dest='link_flags', | 707 parser.add_option('--link_flags', dest='link_flags', |
693 help='Set link flags.') | 708 help='Set link flags.') |
694 parser.add_option('-v', '--verbose', dest='verbose', default=False, | 709 parser.add_option('-v', '--verbose', dest='verbose', default=False, |
695 help='Enable verbosity', action='store_true') | 710 help='Enable verbosity', action='store_true') |
696 parser.add_option('-t', '--toolpath', dest='toolpath', | 711 parser.add_option('-t', '--toolpath', dest='toolpath', |
697 help='Set the path for of the toolchains.') | 712 help='Set the path for of the toolchains.') |
698 parser.add_option('--config-name', dest='build_config', | 713 parser.add_option('--config-name', dest='build_config', |
699 help='GYP build configuration name (Release/Debug)') | 714 help='GYP build configuration name (Release/Debug)') |
| 715 parser.add_option('--gomadir', dest='gomadir', |
| 716 help='Path of the goma directory.') |
700 options, files = parser.parse_args(argv[1:]) | 717 options, files = parser.parse_args(argv[1:]) |
701 | 718 |
702 if not argv: | 719 if not argv: |
703 parser.print_help() | 720 parser.print_help() |
704 return 1 | 721 return 1 |
705 | 722 |
706 try: | 723 try: |
707 if options.source_list: | 724 if options.source_list: |
708 source_list_handle = open(options.source_list, 'r') | 725 source_list_handle = open(options.source_list, 'r') |
709 source_list = source_list_handle.read().splitlines() | 726 source_list = source_list_handle.read().splitlines() |
(...skipping 14 matching lines...) Expand all Loading... |
724 build = Builder(options) | 741 build = Builder(options) |
725 objs = [] | 742 objs = [] |
726 | 743 |
727 if build.outtype == 'translate': | 744 if build.outtype == 'translate': |
728 # Just translate a pexe to a nexe | 745 # Just translate a pexe to a nexe |
729 if len(files) != 1: | 746 if len(files) != 1: |
730 parser.error('Pexe translation requires exactly one input file.') | 747 parser.error('Pexe translation requires exactly one input file.') |
731 build.Translate(list(files)[0]) | 748 build.Translate(list(files)[0]) |
732 return 0 | 749 return 0 |
733 | 750 |
734 if build.gomacc: # use goma build. | 751 if build.gomacc: # execute gomacc as many as possible. |
735 returns = Queue.Queue() | 752 returns = Queue.Queue() |
736 def CompileThread(filename, queue): | 753 def CompileThread(filename, queue): |
737 try: | 754 try: |
738 queue.put(build.Compile(filename)) | 755 queue.put(build.Compile(filename)) |
739 except Exception: | 756 except Exception: |
740 # Put current exception info to the queue. | 757 # Put current exception info to the queue. |
741 queue.put(sys.exc_info()) | 758 queue.put(sys.exc_info()) |
742 build_threads = [] | 759 build_threads = [] |
743 # Start parallel build. | 760 # Start parallel build. |
744 for filename in files: | 761 for filename in files: |
(...skipping 24 matching lines...) Expand all Loading... |
769 shutil.copy(objs[0], options.name) | 786 shutil.copy(objs[0], options.name) |
770 else: | 787 else: |
771 build.Generate(objs) | 788 build.Generate(objs) |
772 return 0 | 789 return 0 |
773 except Error as e: | 790 except Error as e: |
774 sys.stderr.write('%s\n' % e) | 791 sys.stderr.write('%s\n' % e) |
775 return 1 | 792 return 1 |
776 | 793 |
777 if __name__ == '__main__': | 794 if __name__ == '__main__': |
778 sys.exit(Main(sys.argv)) | 795 sys.exit(Main(sys.argv)) |
OLD | NEW |