OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license | 5 # Use of this source code is governed by a BSD-style license |
6 # that can be found in the LICENSE file in the root of the source | 6 # that can be found in the LICENSE file in the root of the source |
7 # tree. An additional intellectual property rights grant can be found | 7 # tree. An additional intellectual property rights grant can be found |
8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
10 | 10 |
11 # This file is (possibly, depending on python version) imported by | 11 # This script is used to run GYP for WebRTC. It contains selected parts of the |
12 # gyp_webrtc when GYP_PARALLEL=1 and it creates sub-processes | 12 # main function from the src/build/gyp_chromium.py file while other parts are |
13 # through the multiprocessing library. | 13 # reused to minimize code duplication. |
14 | 14 |
15 # Importing in Python 2.6 (fixed in 2.7) on Windows doesn't search for | 15 import gc |
16 # imports that don't end in .py (and aren't directories with an | 16 import glob |
17 # __init__.py). This wrapper makes "import gyp_webrtc" work with | 17 import os |
18 # those old versions and makes it possible to execute gyp_webrtc.py | 18 import sys |
19 # directly on Windows where the extension is useful. | |
20 | 19 |
21 import os | 20 script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 21 checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir, os.pardir)) |
22 | 22 |
23 path = os.path.abspath(os.path.split(__file__)[0]) | 23 sys.path.insert(0, os.path.join(checkout_root, 'build')) |
24 execfile(os.path.join(path, 'gyp_webrtc')) | 24 import gyp_chromium |
| 25 import gyp_helper |
| 26 import vs_toolchain |
| 27 |
| 28 sys.path.insert(0, os.path.join(checkout_root, 'tools', 'gyp', 'pylib')) |
| 29 import gyp |
| 30 |
| 31 |
| 32 def GetSupplementalFiles(): |
| 33 """Returns a list of the supplemental files. |
| 34 |
| 35 A supplemental file is included in all GYP sources. Such files can be used to |
| 36 override default values. |
| 37 """ |
| 38 # Can't use the one in gyp_chromium since the directory location of the root |
| 39 # is different. |
| 40 return glob.glob(os.path.join(checkout_root, '*', 'supplement.gypi')) |
| 41 |
| 42 |
| 43 def main(): |
| 44 # Disabling garbage collection saves about 5% processing time. Since this is a |
| 45 # short-lived process it's not a problem. |
| 46 gc.disable() |
| 47 |
| 48 args = sys.argv[1:] |
| 49 |
| 50 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): |
| 51 print 'Skipping gyp_webrtc.py due to GYP_CHROMIUM_NO_ACTION env var.' |
| 52 sys.exit(0) |
| 53 |
| 54 if 'SKIP_WEBRTC_GYP_ENV' not in os.environ: |
| 55 # Update the environment based on webrtc.gyp_env. |
| 56 gyp_env_path = os.path.join(os.path.dirname(checkout_root), |
| 57 'webrtc.gyp_env') |
| 58 gyp_helper.apply_gyp_environment_from_file(gyp_env_path) |
| 59 |
| 60 # This could give false positives since it doesn't actually do real option |
| 61 # parsing. Oh well. |
| 62 gyp_file_specified = False |
| 63 for arg in args: |
| 64 if arg.endswith('.gyp'): |
| 65 gyp_file_specified = True |
| 66 break |
| 67 |
| 68 # If we didn't get a file, assume 'all.gyp' in the root of the checkout. |
| 69 if not gyp_file_specified: |
| 70 # Because of a bug in gyp, simply adding the abspath to all.gyp doesn't |
| 71 # work, but chdir'ing and adding the relative path does. Spooky :/ |
| 72 os.chdir(checkout_root) |
| 73 args.append('all.gyp') |
| 74 |
| 75 # There shouldn't be a circular dependency relationship between .gyp files, |
| 76 args.append('--no-circular-check') |
| 77 |
| 78 # Default to ninja unless GYP_GENERATORS is set. |
| 79 if not os.environ.get('GYP_GENERATORS'): |
| 80 os.environ['GYP_GENERATORS'] = 'ninja' |
| 81 |
| 82 # Enable check for missing sources in GYP files on Windows. |
| 83 if sys.platform.startswith('win'): |
| 84 gyp_generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '') |
| 85 if not 'msvs_error_on_missing_sources' in gyp_generator_flags: |
| 86 os.environ['GYP_GENERATOR_FLAGS'] = ( |
| 87 gyp_generator_flags + ' msvs_error_on_missing_sources=1') |
| 88 |
| 89 vs2013_runtime_dll_dirs = None, None |
| 90 if int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')): |
| 91 vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() |
| 92 |
| 93 # Enforce gyp syntax checking. This adds about 20% execution time. |
| 94 args.append('--check') |
| 95 |
| 96 supplemental_includes = GetSupplementalFiles() |
| 97 gyp_vars = gyp_chromium.GetGypVars(supplemental_includes) |
| 98 |
| 99 # Automatically turn on crosscompile support for platforms that need it. |
| 100 if all(('ninja' in os.environ.get('GYP_GENERATORS', ''), |
| 101 gyp_vars.get('OS') in ['android', 'ios'], |
| 102 'GYP_CROSSCOMPILE' not in os.environ)): |
| 103 os.environ['GYP_CROSSCOMPILE'] = '1' |
| 104 |
| 105 args.extend(['-I' + i for i in |
| 106 gyp_chromium.additional_include_files(supplemental_includes, |
| 107 args)]) |
| 108 |
| 109 # Set the gyp depth variable to the root of the checkout. |
| 110 args.append('--depth=' + os.path.relpath(checkout_root)) |
| 111 |
| 112 print 'Updating projects from gyp files...' |
| 113 sys.stdout.flush() |
| 114 |
| 115 # Off we go... |
| 116 gyp_rc = gyp.main(args) |
| 117 |
| 118 if vs2013_runtime_dll_dirs: |
| 119 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs |
| 120 vs_toolchain.CopyVsRuntimeDlls( |
| 121 os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()), |
| 122 (x86_runtime, x64_runtime)) |
| 123 |
| 124 sys.exit(gyp_rc) |
| 125 |
| 126 |
| 127 if __name__ == '__main__': |
| 128 sys.exit(main()) |
| 129 |
OLD | NEW |