| 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 shlex | 13 import shlex |
| 14 import subprocess | 14 import subprocess |
| 15 import sys | 15 import sys |
| 16 | 16 |
| 17 script_dir = os.path.dirname(os.path.realpath(__file__)) | 17 script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 18 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 18 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
| 19 | 19 |
| 20 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 20 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
| 21 import gyp | 21 import gyp |
| 22 | 22 |
| 23 # Assume this file is in a one-level-deep subdirectory of the source root. | |
| 24 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| 25 | |
| 26 # Add paths so that pymod_do_main(...) can import files. | 23 # Add paths so that pymod_do_main(...) can import files. |
| 27 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers')) | 24 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'generate_shim_headers')) |
| 28 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit')) | 25 sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit')) |
| 29 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build')) | 26 sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build')) |
| 30 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build')) | 27 sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build')) |
| 31 sys.path.insert(1, os.path.join(chrome_src, 'native_client_sdk', 'src', | 28 sys.path.insert(1, os.path.join(chrome_src, 'native_client_sdk', 'src', |
| 32 'build_tools')) | 29 'build_tools')) |
| 33 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build')) | 30 sys.path.insert(1, os.path.join(chrome_src, 'remoting', 'tools', 'build')) |
| 34 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', | 31 sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit', |
| 35 'Source', 'build', 'scripts')) | 32 'Source', 'build', 'scripts')) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 # may not be worth it). | 43 # may not be worth it). |
| 47 if sys.platform == 'win32': | 44 if sys.platform == 'win32': |
| 48 try: | 45 try: |
| 49 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) | 46 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32')) |
| 50 import psyco | 47 import psyco |
| 51 except: | 48 except: |
| 52 psyco = None | 49 psyco = None |
| 53 else: | 50 else: |
| 54 psyco = None | 51 psyco = None |
| 55 | 52 |
| 56 | |
| 57 def additional_include_files(args=[]): | 53 def additional_include_files(args=[]): |
| 58 """ | 54 """ |
| 59 Returns a list of additional (.gypi) files to include, without | 55 Returns a list of additional (.gypi) files to include, without |
| 60 duplicating ones that are already specified on the command line. | 56 duplicating ones that are already specified on the command line. |
| 61 """ | 57 """ |
| 62 # Determine the include files specified on the command line. | 58 # Determine the include files specified on the command line. |
| 63 # This doesn't cover all the different option formats you can use, | 59 # 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 | 60 # but it's mainly intended to avoid duplicating flags on the automatic |
| 65 # makefile regeneration which only uses this format. | 61 # makefile regeneration which only uses this format. |
| 66 specified_includes = set() | 62 specified_includes = set() |
| 67 for arg in args: | 63 for arg in args: |
| 68 if arg.startswith('-I') and len(arg) > 2: | 64 if arg.startswith('-I') and len(arg) > 2: |
| 69 specified_includes.add(os.path.realpath(arg[2:])) | 65 specified_includes.add(os.path.realpath(arg[2:])) |
| 70 | 66 |
| 71 result = [] | 67 result = [] |
| 72 def AddInclude(path): | 68 def AddInclude(path): |
| 73 if os.path.realpath(path) not in specified_includes: | 69 if os.path.realpath(path) not in specified_includes: |
| 74 result.append(path) | 70 result.append(path) |
| 75 | 71 |
| 76 # Always include common.gypi. | 72 # Always include common.gypi. |
| 77 AddInclude(os.path.join(script_dir, 'common.gypi')) | 73 AddInclude(os.path.join(script_dir, 'common.gypi')) |
| 78 | 74 |
| 79 # Optionally add supplemental .gypi files if present. | 75 # Optionally add supplemental .gypi files if present. |
| 80 supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) | 76 supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi')) |
| 81 for supplement in supplements: | 77 for supplement in supplements: |
| 82 AddInclude(supplement) | 78 AddInclude(supplement) |
| 83 | 79 |
| 84 return result | 80 return result |
| 85 | 81 |
| 86 | |
| 87 def RunGN(): | |
| 88 """Runs GN, returning True if it succeeded, printing an error and returning | |
| 89 false if not.""" | |
| 90 # The binaries in platform-specific subdirectories in src/tools/gn/bin. | |
| 91 gnpath = SRC_DIR + '/tools/gn/bin/' | |
| 92 if sys.platform == 'win32': | |
| 93 gnpath += 'win/gn.exe' | |
| 94 elif sys.platform.startswith('linux'): | |
| 95 gnpath += 'linux/gn' | |
| 96 elif sys.platform == 'darwin': | |
| 97 gnpath += 'mac/gn' | |
| 98 else: | |
| 99 print 'Unknown platform for GN: ', sys.platform | |
| 100 return False | |
| 101 | |
| 102 print 'Generating gyp files from GN...' | |
| 103 print 'platform = ', sys.platform | |
| 104 print 'binary = ', gnpath | |
| 105 | |
| 106 # 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 | |
| 108 # to know they're being run under GYP. | |
| 109 args = [gnpath, 'gyp', '-q', '--root=' + chrome_src, '--args=is_gyp=true'] | |
| 110 return subprocess.call(args) == 0 | |
| 111 | |
| 112 | |
| 113 if __name__ == '__main__': | 82 if __name__ == '__main__': |
| 114 args = sys.argv[1:] | 83 args = sys.argv[1:] |
| 115 | 84 |
| 116 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): | 85 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): |
| 117 print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.' | 86 print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.' |
| 118 sys.exit(0) | 87 sys.exit(0) |
| 119 | 88 |
| 120 # Use the Psyco JIT if available. | 89 # Use the Psyco JIT if available. |
| 121 if psyco: | 90 if psyco: |
| 122 psyco.profile() | 91 psyco.profile() |
| 123 print "Enabled Psyco JIT." | 92 print "Enabled Psyco JIT." |
| 124 | 93 |
| 125 if not RunGN(): | |
| 126 sys.exit(1) | |
| 127 | |
| 128 # Fall back on hermetic python if we happen to get run under cygwin. | 94 # Fall back on hermetic python if we happen to get run under cygwin. |
| 129 # TODO(bradnelson): take this out once this issue is fixed: | 95 # TODO(bradnelson): take this out once this issue is fixed: |
| 130 # http://code.google.com/p/gyp/issues/detail?id=177 | 96 # http://code.google.com/p/gyp/issues/detail?id=177 |
| 131 if sys.platform == 'cygwin': | 97 if sys.platform == 'cygwin': |
| 132 python_dir = os.path.join(chrome_src, 'third_party', 'python_26') | 98 python_dir = os.path.join(chrome_src, 'third_party', 'python_26') |
| 133 env = os.environ.copy() | 99 env = os.environ.copy() |
| 134 env['PATH'] = python_dir + os.pathsep + env.get('PATH', '') | 100 env['PATH'] = python_dir + os.pathsep + env.get('PATH', '') |
| 135 p = subprocess.Popen( | 101 p = subprocess.Popen( |
| 136 [os.path.join(python_dir, 'python.exe')] + sys.argv, | 102 [os.path.join(python_dir, 'python.exe')] + sys.argv, |
| 137 env=env, shell=False) | 103 env=env, shell=False) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 # to enfore syntax checking. | 154 # to enfore syntax checking. |
| 189 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') | 155 syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK') |
| 190 if syntax_check and int(syntax_check): | 156 if syntax_check and int(syntax_check): |
| 191 args.append('--check') | 157 args.append('--check') |
| 192 | 158 |
| 193 print 'Updating projects from gyp files...' | 159 print 'Updating projects from gyp files...' |
| 194 sys.stdout.flush() | 160 sys.stdout.flush() |
| 195 | 161 |
| 196 # Off we go... | 162 # Off we go... |
| 197 sys.exit(gyp.main(args)) | 163 sys.exit(gyp.main(args)) |
| OLD | NEW |