Chromium Code Reviews| 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 if sys.platform == 'win32': | 47 if sys.platform == 'win32': |
| 48 try: | 48 try: |
| 49 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) | 49 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) |
| 50 import psyco | 50 import psyco |
| 51 except: | 51 except: |
| 52 psyco = None | 52 psyco = None |
| 53 else: | 53 else: |
| 54 psyco = None | 54 psyco = None |
| 55 | 55 |
| 56 | 56 |
| 57 def additional_include_files(args=[]): | 57 def GetSupplementalFiles(): |
| 58 """Returns a list of the supplemental files that are included in all GYP | |
|
bradn
2013/11/19 17:45:58
FWIW These are usually meant to fix on one line.
| |
| 59 sources.""" | |
| 60 return glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) | |
| 61 | |
| 62 | |
| 63 def GetVarsStringForGN(supplemental_files): | |
| 64 vars_dict = {} | |
| 65 | |
| 66 for supplement in supplemental_files: | |
| 67 with open(supplement, 'r') as f: | |
| 68 try: | |
| 69 file_data = eval(f.read(), {'__builtins__': None}, None) | |
| 70 except SyntaxError, e: | |
| 71 e.filename = os.path.abspath(supplement) | |
| 72 raise | |
| 73 variables = file_data.get('variables') | |
| 74 for v in variables: | |
| 75 vars_dict[v] = '"' + variables[v] + '"' | |
| 76 | |
| 77 env_string = os.environ.get('GYP_DEFINES', []) | |
| 78 items = shlex.split(env_string) | |
| 79 for item in items: | |
| 80 tokens = item.split('=', 1) | |
| 81 if len(tokens) == 2: | |
| 82 vars_dict[tokens[0]] = '"' + tokens[1] + '"' | |
| 83 else: | |
| 84 # No value supplied, treat it as a boolean and set it. | |
| 85 vars_dict[tokens[0]] = 'true' | |
| 86 | |
| 87 vars_string = '' | |
| 88 for v in vars_dict: | |
| 89 vars_string = vars_string + v + '=' + vars_dict[v] + ' ' | |
| 90 return vars_string.strip() # Remove trailing space. | |
| 91 | |
| 92 | |
| 93 def additional_include_files(supplemental_files, args=[]): | |
| 58 """ | 94 """ |
| 59 Returns a list of additional (.gypi) files to include, without | 95 Returns a list of additional (.gypi) files to include, without duplicating |
| 60 duplicating ones that are already specified on the command line. | 96 ones that are already specified on the command line. The list of supplemental |
| 97 include files is passed in as an argument. | |
| 61 """ | 98 """ |
| 62 # Determine the include files specified on the command line. | 99 # Determine the include files specified on the command line. |
| 63 # This doesn't cover all the different option formats you can use, | 100 # This doesn't cover all the different option formats you can use, |
| 64 # but it's mainly intended to avoid duplicating flags on the automatic | 101 # but it's mainly intended to avoid duplicating flags on the automatic |
| 65 # makefile regeneration which only uses this format. | 102 # makefile regeneration which only uses this format. |
| 66 specified_includes = set() | 103 specified_includes = set() |
| 67 for arg in args: | 104 for arg in args: |
| 68 if arg.startswith('-I') and len(arg) > 2: | 105 if arg.startswith('-I') and len(arg) > 2: |
| 69 specified_includes.add(os.path.realpath(arg[2:])) | 106 specified_includes.add(os.path.realpath(arg[2:])) |
| 70 | 107 |
| 71 result = [] | 108 result = [] |
| 72 def AddInclude(path): | 109 def AddInclude(path): |
| 73 if os.path.realpath(path) not in specified_includes: | 110 if os.path.realpath(path) not in specified_includes: |
| 74 result.append(path) | 111 result.append(path) |
| 75 | 112 |
| 76 # Always include common.gypi. | 113 # Always include common.gypi. |
| 77 AddInclude(os.path.join(script_dir, 'common.gypi')) | 114 AddInclude(os.path.join(script_dir, 'common.gypi')) |
| 78 | 115 |
| 79 # Optionally add supplemental .gypi files if present. | 116 # Optionally add supplemental .gypi files if present. |
| 80 supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) | 117 for supplement in supplemental_files: |
| 81 for supplement in supplements: | |
| 82 AddInclude(supplement) | 118 AddInclude(supplement) |
| 83 | 119 |
| 84 return result | 120 return result |
| 85 | 121 |
| 86 | 122 |
| 87 def RunGN(): | 123 def RunGN(supplemental_includes): |
| 88 """Runs GN, returning True if it succeeded, printing an error and returning | 124 """Runs GN, returning True if it succeeded, printing an error and returning |
| 89 false if not.""" | 125 false if not.""" |
| 126 | |
| 90 # The binaries in platform-specific subdirectories in src/tools/gn/bin. | 127 # The binaries in platform-specific subdirectories in src/tools/gn/bin. |
| 91 gnpath = SRC_DIR + '/tools/gn/bin/' | 128 gnpath = SRC_DIR + '/tools/gn/bin/' |
| 92 if sys.platform == 'win32': | 129 if sys.platform == 'win32': |
| 93 gnpath += 'win/gn.exe' | 130 gnpath += 'win/gn.exe' |
| 94 elif sys.platform.startswith('linux'): | 131 elif sys.platform.startswith('linux'): |
| 95 gnpath += 'linux/gn' | 132 gnpath += 'linux/gn' |
| 96 elif sys.platform == 'darwin': | 133 elif sys.platform == 'darwin': |
| 97 gnpath += 'mac/gn' | 134 gnpath += 'mac/gn' |
| 98 else: | 135 else: |
| 99 print 'Unknown platform for GN: ', sys.platform | 136 print 'Unknown platform for GN: ', sys.platform |
| 100 return False | 137 return False |
| 101 | 138 |
| 102 print 'Generating gyp files from GN...' | 139 print 'Generating gyp files from GN...' |
| 103 print 'platform = ', sys.platform | 140 gyp_vars = GetVarsStringForGN(supplemental_includes) |
| 104 print 'binary = ', gnpath | |
| 105 | 141 |
| 106 # Need to pass both the source root (the bots don't run this command from | 142 # Need to pass both the source root (the bots don't run this command from |
| 107 # within the source tree) as well as set the is_gyp value so the BUILD files | 143 # within the source tree) as well as set the is_gyp value so the BUILD files |
| 108 # to know they're being run under GYP. | 144 # to know they're being run under GYP. |
| 109 args = [gnpath, 'gyp', '-q', '--root=' + chrome_src, '--args=is_gyp=true'] | 145 args = [gnpath, 'gyp', '-q', |
| 146 '--root=' + chrome_src, | |
| 147 '--args=is_gyp=true', | |
| 148 '--gyp_vars=' + gyp_vars + ''] | |
| 110 return subprocess.call(args) == 0 | 149 return subprocess.call(args) == 0 |
| 111 | 150 |
| 112 | 151 |
| 113 if __name__ == '__main__': | 152 if __name__ == '__main__': |
| 114 args = sys.argv[1:] | 153 args = sys.argv[1:] |
| 115 | 154 |
| 116 # Use the Psyco JIT if available. | 155 # Use the Psyco JIT if available. |
| 117 if psyco: | 156 if psyco: |
| 118 psyco.profile() | 157 psyco.profile() |
| 119 print "Enabled Psyco JIT." | 158 print "Enabled Psyco JIT." |
| 120 | 159 |
| 121 if not RunGN(): | |
| 122 sys.exit(1) | |
| 123 | |
| 124 # Fall back on hermetic python if we happen to get run under cygwin. | 160 # Fall back on hermetic python if we happen to get run under cygwin. |
| 125 # TODO(bradnelson): take this out once this issue is fixed: | 161 # TODO(bradnelson): take this out once this issue is fixed: |
| 126 # http://code.google.com/p/gyp/issues/detail?id=177 | 162 # http://code.google.com/p/gyp/issues/detail?id=177 |
| 127 if sys.platform == 'cygwin': | 163 if sys.platform == 'cygwin': |
| 128 python_dir = os.path.join(chrome_src, 'third_party', 'python_26') | 164 python_dir = os.path.join(chrome_src, 'third_party', 'python_26') |
| 129 env = os.environ.copy() | 165 env = os.environ.copy() |
| 130 env['PATH'] = python_dir + os.pathsep + env.get('PATH', '') | 166 env['PATH'] = python_dir + os.pathsep + env.get('PATH', '') |
| 131 p = subprocess.Popen( | 167 p = subprocess.Popen( |
| 132 [os.path.join(python_dir, 'python.exe')] + sys.argv, | 168 [os.path.join(python_dir, 'python.exe')] + sys.argv, |
| 133 env=env, shell=False) | 169 env=env, shell=False) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 148 # assuming 'all.gyp' from the same directory as the script. | 184 # assuming 'all.gyp' from the same directory as the script. |
| 149 if not gyp_file_specified: | 185 if not gyp_file_specified: |
| 150 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') | 186 gyp_file = os.environ.get('CHROMIUM_GYP_FILE') |
| 151 if gyp_file: | 187 if gyp_file: |
| 152 # Note that CHROMIUM_GYP_FILE values can't have backslashes as | 188 # Note that CHROMIUM_GYP_FILE values can't have backslashes as |
| 153 # path separators even on Windows due to the use of shlex.split(). | 189 # path separators even on Windows due to the use of shlex.split(). |
| 154 args.extend(shlex.split(gyp_file)) | 190 args.extend(shlex.split(gyp_file)) |
| 155 else: | 191 else: |
| 156 args.append(os.path.join(script_dir, 'all.gyp')) | 192 args.append(os.path.join(script_dir, 'all.gyp')) |
| 157 | 193 |
| 158 args.extend(['-I' + i for i in additional_include_files(args)]) | 194 supplemental_includes = GetSupplementalFiles() |
| 195 | |
| 196 if not RunGN(supplemental_includes): | |
| 197 sys.exit(1) | |
| 198 | |
| 199 args.extend( | |
| 200 ['-I' + i for i in additional_include_files(supplemental_includes, args)]) | |
| 159 | 201 |
| 160 # There shouldn't be a circular dependency relationship between .gyp files, | 202 # There shouldn't be a circular dependency relationship between .gyp files, |
| 161 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships | 203 # but in Chromium's .gyp files, on non-Mac platforms, circular relationships |
| 162 # currently exist. The check for circular dependencies is currently | 204 # currently exist. The check for circular dependencies is currently |
| 163 # bypassed on other platforms, but is left enabled on the Mac, where a | 205 # bypassed on other platforms, but is left enabled on the Mac, where a |
| 164 # violation of the rule causes Xcode to misbehave badly. | 206 # violation of the rule causes Xcode to misbehave badly. |
| 165 # TODO(mark): Find and kill remaining circular dependencies, and remove this | 207 # TODO(mark): Find and kill remaining circular dependencies, and remove this |
| 166 # option. http://crbug.com/35878. | 208 # option. http://crbug.com/35878. |
| 167 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the | 209 # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the |
| 168 # list. | 210 # list. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 184 # to enfore syntax checking. | 226 # to enfore syntax checking. |
| 185 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') | 227 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') |
| 186 if syntax_check and int(syntax_check): | 228 if syntax_check and int(syntax_check): |
| 187 args.append('--check') | 229 args.append('--check') |
| 188 | 230 |
| 189 print 'Updating projects from gyp files...' | 231 print 'Updating projects from gyp files...' |
| 190 sys.stdout.flush() | 232 sys.stdout.flush() |
| 191 | 233 |
| 192 # Off we go... | 234 # Off we go... |
| 193 sys.exit(gyp.main(args)) | 235 sys.exit(gyp.main(args)) |
| OLD | NEW |