OLD | NEW |
1 # Copyright (c) 2013 Google Inc. All rights reserved. | 1 # Copyright (c) 2013 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import collections | 5 import collections |
6 import copy | 6 import copy |
7 import hashlib | 7 import hashlib |
8 import json | 8 import json |
9 import multiprocessing | 9 import multiprocessing |
10 import os.path | 10 import os.path |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 cflags_c = config.get('cflags_c', []) | 914 cflags_c = config.get('cflags_c', []) |
915 cflags_cc = config.get('cflags_cc', []) | 915 cflags_cc = config.get('cflags_cc', []) |
916 | 916 |
917 # Respect environment variables related to build, but target-specific | 917 # Respect environment variables related to build, but target-specific |
918 # flags can still override them. | 918 # flags can still override them. |
919 if self.toolset == 'target': | 919 if self.toolset == 'target': |
920 cflags_c = (os.environ.get('CPPFLAGS', '').split() + | 920 cflags_c = (os.environ.get('CPPFLAGS', '').split() + |
921 os.environ.get('CFLAGS', '').split() + cflags_c) | 921 os.environ.get('CFLAGS', '').split() + cflags_c) |
922 cflags_cc = (os.environ.get('CPPFLAGS', '').split() + | 922 cflags_cc = (os.environ.get('CPPFLAGS', '').split() + |
923 os.environ.get('CXXFLAGS', '').split() + cflags_cc) | 923 os.environ.get('CXXFLAGS', '').split() + cflags_cc) |
924 elif self.toolset == 'host': | |
925 cflags_c = (os.environ.get('CPPFLAGS_host', '').split() + | |
926 os.environ.get('CFLAGS_host', '').split() + cflags_c) | |
927 cflags_cc = (os.environ.get('CPPFLAGS_host', '').split() + | |
928 os.environ.get('CXXFLAGS_host', '').split() + cflags_cc) | |
929 | 924 |
930 defines = config.get('defines', []) + extra_defines | 925 defines = config.get('defines', []) + extra_defines |
931 self.WriteVariableList(ninja_file, 'defines', | 926 self.WriteVariableList(ninja_file, 'defines', |
932 [Define(d, self.flavor) for d in defines]) | 927 [Define(d, self.flavor) for d in defines]) |
933 if self.flavor == 'win': | 928 if self.flavor == 'win': |
934 self.WriteVariableList(ninja_file, 'asmflags', | 929 self.WriteVariableList(ninja_file, 'asmflags', |
935 map(self.ExpandSpecial, asmflags)) | 930 map(self.ExpandSpecial, asmflags)) |
936 self.WriteVariableList(ninja_file, 'rcflags', | 931 self.WriteVariableList(ninja_file, 'rcflags', |
937 [QuoteShellArgument(self.ExpandSpecial(f), self.flavor) | 932 [QuoteShellArgument(self.ExpandSpecial(f), self.flavor) |
938 for f in self.msvs_settings.GetRcflags(config_name, | 933 for f in self.msvs_settings.GetRcflags(config_name, |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 | 1665 |
1671 def CommandWithWrapper(cmd, wrappers, prog): | 1666 def CommandWithWrapper(cmd, wrappers, prog): |
1672 wrapper = wrappers.get(cmd, '') | 1667 wrapper = wrappers.get(cmd, '') |
1673 if wrapper: | 1668 if wrapper: |
1674 return wrapper + ' ' + prog | 1669 return wrapper + ' ' + prog |
1675 return prog | 1670 return prog |
1676 | 1671 |
1677 | 1672 |
1678 def GetDefaultConcurrentLinks(): | 1673 def GetDefaultConcurrentLinks(): |
1679 """Returns a best-guess for a number of concurrent links.""" | 1674 """Returns a best-guess for a number of concurrent links.""" |
1680 pool_size = int(os.environ.get('GYP_LINK_CONCURRENCY', 0)) | 1675 pool_size = int(os.getenv('GYP_LINK_CONCURRENCY', 0)) |
1681 if pool_size: | 1676 if pool_size: |
1682 return pool_size | 1677 return pool_size |
1683 | 1678 |
1684 if sys.platform in ('win32', 'cygwin'): | 1679 if sys.platform in ('win32', 'cygwin'): |
1685 import ctypes | 1680 import ctypes |
1686 | 1681 |
1687 class MEMORYSTATUSEX(ctypes.Structure): | 1682 class MEMORYSTATUSEX(ctypes.Structure): |
1688 _fields_ = [ | 1683 _fields_ = [ |
1689 ("dwLength", ctypes.c_ulong), | 1684 ("dwLength", ctypes.c_ulong), |
1690 ("dwMemoryLoad", ctypes.c_ulong), | 1685 ("dwMemoryLoad", ctypes.c_ulong), |
1691 ("ullTotalPhys", ctypes.c_ulonglong), | 1686 ("ullTotalPhys", ctypes.c_ulonglong), |
1692 ("ullAvailPhys", ctypes.c_ulonglong), | 1687 ("ullAvailPhys", ctypes.c_ulonglong), |
1693 ("ullTotalPageFile", ctypes.c_ulonglong), | 1688 ("ullTotalPageFile", ctypes.c_ulonglong), |
1694 ("ullAvailPageFile", ctypes.c_ulonglong), | 1689 ("ullAvailPageFile", ctypes.c_ulonglong), |
1695 ("ullTotalVirtual", ctypes.c_ulonglong), | 1690 ("ullTotalVirtual", ctypes.c_ulonglong), |
1696 ("ullAvailVirtual", ctypes.c_ulonglong), | 1691 ("ullAvailVirtual", ctypes.c_ulonglong), |
1697 ("sullAvailExtendedVirtual", ctypes.c_ulonglong), | 1692 ("sullAvailExtendedVirtual", ctypes.c_ulonglong), |
1698 ] | 1693 ] |
1699 | 1694 |
1700 stat = MEMORYSTATUSEX() | 1695 stat = MEMORYSTATUSEX() |
1701 stat.dwLength = ctypes.sizeof(stat) | 1696 stat.dwLength = ctypes.sizeof(stat) |
1702 ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat)) | 1697 ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat)) |
1703 | 1698 |
1704 # VS 2015 uses 20% more working set than VS 2013 and can consume all RAM | 1699 # VS 2015 uses 20% more working set than VS 2013 and can consume all RAM |
1705 # on a 64 GB machine. | 1700 # on a 64 GB machine. |
1706 mem_limit = max(1, stat.ullTotalPhys / (5 * (2 ** 30))) # total / 5GB | 1701 mem_limit = max(1, stat.ullTotalPhys / (5 * (2 ** 30))) # total / 5GB |
1707 hard_cap = max(1, int(os.environ.get('GYP_LINK_CONCURRENCY_MAX', 2**32))) | 1702 hard_cap = max(1, int(os.getenv('GYP_LINK_CONCURRENCY_MAX', 2**32))) |
1708 return min(mem_limit, hard_cap) | 1703 return min(mem_limit, hard_cap) |
1709 elif sys.platform.startswith('linux'): | 1704 elif sys.platform.startswith('linux'): |
1710 if os.path.exists("/proc/meminfo"): | 1705 if os.path.exists("/proc/meminfo"): |
1711 with open("/proc/meminfo") as meminfo: | 1706 with open("/proc/meminfo") as meminfo: |
1712 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB') | 1707 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB') |
1713 for line in meminfo: | 1708 for line in meminfo: |
1714 match = memtotal_re.match(line) | 1709 match = memtotal_re.match(line) |
1715 if not match: | 1710 if not match: |
1716 continue | 1711 continue |
1717 # Allow 8Gb per link on Linux because Gold is quite memory hungry | 1712 # Allow 8Gb per link on Linux because Gold is quite memory hungry |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 arglists.append( | 2384 arglists.append( |
2390 (target_list, target_dicts, data, params, config_name)) | 2385 (target_list, target_dicts, data, params, config_name)) |
2391 pool.map(CallGenerateOutputForConfig, arglists) | 2386 pool.map(CallGenerateOutputForConfig, arglists) |
2392 except KeyboardInterrupt, e: | 2387 except KeyboardInterrupt, e: |
2393 pool.terminate() | 2388 pool.terminate() |
2394 raise e | 2389 raise e |
2395 else: | 2390 else: |
2396 for config_name in config_names: | 2391 for config_name in config_names: |
2397 GenerateOutputForConfig(target_list, target_dicts, data, params, | 2392 GenerateOutputForConfig(target_list, target_dicts, data, params, |
2398 config_name) | 2393 config_name) |
OLD | NEW |