kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 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 |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 11 | # This script is used to run GYP for WebRTC. It contains selected parts of the |
| 12 | # main function from the src/build/gyp_chromium.py file while other parts are |
| 13 | # reused to minimize code duplication. |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 14 | |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 15 | import gc |
| 16 | import glob |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 17 | import os |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 18 | import sys |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 19 | |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 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 | |
| 23 | sys.path.insert(0, os.path.join(checkout_root, 'build')) |
| 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 | |
kjellander@webrtc.org | 0026dd8 | 2016-05-19 13:30:09 +0200 | [diff] [blame^] | 89 | vs2013_runtime_dll_dirs = None |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 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: |
kjellander@webrtc.org | 0026dd8 | 2016-05-19 13:30:09 +0200 | [diff] [blame^] | 119 | # pylint: disable=unpacking-non-sequence |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 120 | x64_runtime, x86_runtime = vs2013_runtime_dll_dirs |
| 121 | vs_toolchain.CopyVsRuntimeDlls( |
| 122 | os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()), |
| 123 | (x86_runtime, x64_runtime)) |
| 124 | |
| 125 | sys.exit(gyp_rc) |
| 126 | |
| 127 | |
| 128 | if __name__ == '__main__': |
| 129 | sys.exit(main()) |
| 130 | |