| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # This script is wrapper for Chromium that adds some support for how GYP | 7 # This script is wrapper for Chromium that adds some support for how GYP |
| 8 # is invoked by Chromium beyond what can be done in the gclient hooks. | 8 # is invoked by Chromium beyond what can be done in the gclient hooks. |
| 9 | 9 |
| 10 import glob | 10 import glob |
| 11 import gyp_helper | 11 import gyp_helper |
| 12 import os | 12 import os |
| 13 import pipes | 13 import pipes |
| 14 import shlex | 14 import shlex |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 | 17 |
| 18 script_dir = os.path.dirname(os.path.realpath(__file__)) | 18 script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 19 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 19 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
| 20 | 20 |
| 21 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 21 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
| 22 import gyp | 22 import gyp |
| 23 | 23 |
| 24 # Assume this file is in a one-level-deep subdirectory of the source root. | |
| 25 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| 26 | |
| 27 # Add paths so that pymod_do_main(...) can import files. | 24 # Add paths so that pymod_do_main(...) can import files. |
| 28 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers')) | 25 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers')) |
| 29 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit')) | 26 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit')) |
| 30 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build')) | 27 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build')) |
| 31 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build')) | 28 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build')) |
| 32 sys.path.insert(1, os.path.join(chrome_src, 'native_client_sdk', 'src', | 29 sys.path.insert(1, os.path.join(chrome_src, 'native_client_sdk', 'src', |
| 33 'build_tools')) | 30 'build_tools')) |
| 34 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build')) | 31 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build')) |
| 35 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', | 32 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', |
| 36 'Source', 'build', 'scripts')) | 33 'Source', 'build', 'scripts')) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 # may not be worth it). | 44 # may not be worth it). |
| 48 if sys.platform == 'win32': | 45 if sys.platform == 'win32': |
| 49 try: | 46 try: |
| 50 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) | 47 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) |
| 51 import psyco | 48 import psyco |
| 52 except: | 49 except: |
| 53 psyco = None | 50 psyco = None |
| 54 else: | 51 else: |
| 55 psyco = None | 52 psyco = None |
| 56 | 53 |
| 57 | 54 def additional_include_files(args=[]): |
| 58 def GetSupplementalFiles(): | |
| 59 """Returns a list of the supplemental files that are included in all GYP | |
| 60 sources.""" | |
| 61 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) | |
| 62 | |
| 63 | |
| 64 def GetVarsStringForGN(supplemental_files): | |
| 65 vars_dict = {} | |
| 66 | |
| 67 for supplement in supplemental_files: | |
| 68 with open(supplement, 'r') as f: | |
| 69 try: | |
| 70 file_data = eval(f.read(), {'__builtins__': None}, None) | |
| 71 except SyntaxError, e: | |
| 72 e.filename = os.path.abspath(supplement) | |
| 73 raise | |
| 74 variables = file_data.get('variables') | |
| 75 for v in variables: | |
| 76 vars_dict[v] = '"' + variables[v] + '"' | |
| 77 | |
| 78 env_string = os.environ.get('GYP_DEFINES', []) | |
| 79 items = shlex.split(env_string) | |
| 80 for item in items: | |
| 81 tokens = item.split('=', 1) | |
| 82 if len(tokens) == 2: | |
| 83 # Escape $ characters which have special meaning to GN. | |
| 84 vars_dict[tokens[0]] = '"' + tokens[1].replace("$", "\\$") + '"' | |
| 85 else: | |
| 86 # No value supplied, treat it as a boolean and set it. | |
| 87 vars_dict[tokens[0]] = 'true' | |
| 88 | |
| 89 vars_string = '' | |
| 90 for v in vars_dict: | |
| 91 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' | |
| 92 return vars_string.strip() # Remove trailing space. | |
| 93 | |
| 94 | |
| 95 def additional_include_files(supplemental_files, args=[]): | |
| 96 """ | 55 """ |
| 97 Returns a list of additional (.gypi) files to include, without duplicating | 56 Returns a list of additional (.gypi) files to include, without |
| 98 ones that are already specified on the command line. The list of supplemental | 57 duplicating ones that are already specified on the command line. |
| 99 include files is passed in as an argument. | |
| 100 """ | 58 """ |
| 101 # Determine the include files specified on the command line. | 59 # Determine the include files specified on the command line. |
| 102 # This doesn't cover all the different option formats you can use, | 60 # This doesn't cover all the different option formats you can use, |
| 103 # but it's mainly intended to avoid duplicating flags on the automatic | 61 # but it's mainly intended to avoid duplicating flags on the automatic |
| 104 # makefile regeneration which only uses this format. | 62 # makefile regeneration which only uses this format. |
| 105 specified_includes = set() | 63 specified_includes = set() |
| 106 for arg in args: | 64 for arg in args: |
| 107 if arg.startswith('-I') and len(arg) > 2: | 65 if arg.startswith('-I') and len(arg) > 2: |
| 108 specified_includes.add(os.path.realpath(arg[2:])) | 66 specified_includes.add(os.path.realpath(arg[2:])) |
| 109 | 67 |
| 110 result = [] | 68 result = [] |
| 111 def AddInclude(path): | 69 def AddInclude(path): |
| 112 if os.path.realpath(path) not in specified_includes: | 70 if os.path.realpath(path) not in specified_includes: |
| 113 result.append(path) | 71 result.append(path) |
| 114 | 72 |
| 115 # Always include common.gypi. | 73 # Always include common.gypi. |
| 116 AddInclude(os.path.join(script_dir, 'common.gypi')) | 74 AddInclude(os.path.join(script_dir, 'common.gypi')) |
| 117 | 75 |
| 118 # Optionally add supplemental .gypi files if present. | 76 # Optionally add supplemental .gypi files if present. |
| 119 for supplement in supplemental_files: | 77 supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) |
| 78 for supplement in supplements: |
| 120 AddInclude(supplement) | 79 AddInclude(supplement) |
| 121 | 80 |
| 122 return result | 81 return result |
| 123 | 82 |
| 124 | |
| 125 def RunGN(supplemental_includes): | |
| 126 """Runs GN, returning True if it succeeded, printing an error and returning | |
| 127 false if not.""" | |
| 128 | |
| 129 # The binaries in platform-specific subdirectories in src/tools/gn/bin. | |
| 130 gnpath = SRC_DIR + '/tools/gn/bin/' | |
| 131 if sys.platform == 'win32': | |
| 132 gnpath += 'win/gn.exe' | |
| 133 elif sys.platform.startswith('linux'): | |
| 134 # On Linux we have 32-bit and 64-bit versions. Checking /sbin/init avoids | |
| 135 # uname's confusion when running a 32-bit userland on a 64-bit kernel. | |
| 136 if subprocess.check_output(["file", "/sbin/init"]).find("ELF 64-bit") >= 0: | |
| 137 gnpath += 'linux/gn' | |
| 138 else: | |
| 139 gnpath += 'linux/gn32' | |
| 140 elif sys.platform == 'darwin': | |
| 141 gnpath += 'mac/gn' | |
| 142 else: | |
| 143 print 'Unknown platform for GN: ', sys.platform | |
| 144 return False | |
| 145 | |
| 146 print 'Generating gyp files from GN...' | |
| 147 gyp_vars = GetVarsStringForGN(supplemental_includes) | |
| 148 | |
| 149 # Need to pass both the source root (the bots don't run this command from | |
| 150 # within the source tree) as well as set the is_gyp value so the BUILD files | |
| 151 # to know they're being run under GYP. | |
| 152 args = [gnpath, 'gyp', '-q', | |
| 153 '--root=' + chrome_src, | |
| 154 '--args=is_gyp=true', | |
| 155 '--gyp_vars=' + gyp_vars + ''] | |
| 156 return subprocess.call(args) == 0 | |
| 157 | |
| 158 | |
| 159 if __name__ == '__main__': | 83 if __name__ == '__main__': |
| 160 args = sys.argv[1:] | 84 args = sys.argv[1:] |
| 161 | 85 |
| 162 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): | 86 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): |
| 163 print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.' | 87 print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.' |
| 164 sys.exit(0) | 88 sys.exit(0) |
| 165 | 89 |
| 166 # Use the Psyco JIT if available. | 90 # Use the Psyco JIT if available. |
| 167 if psyco: | 91 if psyco: |
| 168 psyco.profile() | 92 psyco.profile() |
| (...skipping 26 matching lines...) Expand all Loading... |
| 195 # assuming 'all.gyp' from the same directory as the script. | 119 # assuming 'all.gyp' from the same directory as the script. |
| 196 if not gyp_file_specified: | 120 if not gyp_file_specified: |
| 197 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') | 121 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') |
| 198 if gyp_file: | 122 if gyp_file: |
| 199 # Note that CHROMIUM_GYP_FILE values can't have backslashes as | 123 # Note that CHROMIUM_GYP_FILE values can't have backslashes as |
| 200 # path separators even on Windows due to the use of shlex.split(). | 124 # path separators even on Windows due to the use of shlex.split(). |
| 201 args.extend(shlex.split(gyp_file)) | 125 args.extend(shlex.split(gyp_file)) |
| 202 else: | 126 else: |
| 203 args.append(os.path.join(script_dir, 'all.gyp')) | 127 args.append(os.path.join(script_dir, 'all.gyp')) |
| 204 | 128 |
| 205 supplemental_includes = GetSupplementalFiles() | 129 args.extend(['-I' + i for i in additional_include_files(args)]) |
| 206 | |
| 207 if not RunGN(supplemental_includes): | |
| 208 sys.exit(1) | |
| 209 | |
| 210 args.extend( | |
| 211 ['-I' + i for i in additional_include_files(supplemental_includes, args)]) | |
| 212 | 130 |
| 213 # There shouldn't be a circular dependency relationship between .gyp files, | 131 # There shouldn't be a circular dependency relationship between .gyp files, |
| 214 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships | 132 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships |
| 215 # currently exist. The check for circular dependencies is currently | 133 # currently exist. The check for circular dependencies is currently |
| 216 # bypassed on other platforms, but is left enabled on the Mac, where a | 134 # bypassed on other platforms, but is left enabled on the Mac, where a |
| 217 # violation of the rule causes Xcode to misbehave badly. | 135 # violation of the rule causes Xcode to misbehave badly. |
| 218 # TODO(mark): Find and kill remaining circular dependencies, and remove this | 136 # TODO(mark): Find and kill remaining circular dependencies, and remove this |
| 219 # option. http://crbug.com/35878. | 137 # option. http://crbug.com/35878. |
| 220 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the | 138 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the |
| 221 # list. | 139 # list. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 # to enfore syntax checking. | 183 # to enfore syntax checking. |
| 266 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') | 184 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') |
| 267 if syntax_check and int(syntax_check): | 185 if syntax_check and int(syntax_check): |
| 268 args.append('--check') | 186 args.append('--check') |
| 269 | 187 |
| 270 print 'Updating projects from gyp files...' | 188 print 'Updating projects from gyp files...' |
| 271 sys.stdout.flush() | 189 sys.stdout.flush() |
| 272 | 190 |
| 273 # Off we go... | 191 # Off we go... |
| 274 sys.exit(gyp.main(args)) | 192 sys.exit(gyp.main(args)) |
| OLD | NEW |