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 | |
Henrik Kjellander | f363d14 | 2016-09-28 09:44:58 +0200 | [diff] [blame] | 15 | import argparse |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 16 | import gc |
| 17 | import glob |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 18 | import os |
Henrik Kjellander | f363d14 | 2016-09-28 09:44:58 +0200 | [diff] [blame] | 19 | import shlex |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 20 | import sys |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 21 | |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 22 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 23 | checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir, os.pardir)) |
| 24 | |
| 25 | sys.path.insert(0, os.path.join(checkout_root, 'build')) |
| 26 | import gyp_chromium |
| 27 | import gyp_helper |
| 28 | import vs_toolchain |
| 29 | |
| 30 | sys.path.insert(0, os.path.join(checkout_root, 'tools', 'gyp', 'pylib')) |
| 31 | import gyp |
| 32 | |
| 33 | |
| 34 | def GetSupplementalFiles(): |
| 35 | """Returns a list of the supplemental files. |
| 36 | |
| 37 | A supplemental file is included in all GYP sources. Such files can be used to |
| 38 | override default values. |
| 39 | """ |
| 40 | # Can't use the one in gyp_chromium since the directory location of the root |
| 41 | # is different. |
| 42 | return glob.glob(os.path.join(checkout_root, '*', 'supplement.gypi')) |
| 43 | |
| 44 | |
Henrik Kjellander | f363d14 | 2016-09-28 09:44:58 +0200 | [diff] [blame] | 45 | def GetOutputDirectory(): |
| 46 | """Returns the output directory that GYP will use.""" |
| 47 | |
| 48 | # Handle command line generator flags. |
| 49 | parser = argparse.ArgumentParser() |
| 50 | parser.add_argument('-G', dest='genflags', default=[], action='append') |
| 51 | genflags = parser.parse_known_args()[0].genflags |
| 52 | |
| 53 | # Handle generator flags from the environment. |
| 54 | genflags += shlex.split(os.environ.get('GYP_GENERATOR_FLAGS', '')) |
| 55 | |
| 56 | needle = 'output_dir=' |
| 57 | for item in genflags: |
| 58 | if item.startswith(needle): |
| 59 | return item[len(needle):] |
| 60 | |
| 61 | return 'out' |
| 62 | |
| 63 | |
| 64 | def additional_include_files(supplemental_files, args=None): |
| 65 | """ |
| 66 | Returns a list of additional (.gypi) files to include, without duplicating |
| 67 | ones that are already specified on the command line. The list of supplemental |
| 68 | include files is passed in as an argument. |
| 69 | """ |
| 70 | # Determine the include files specified on the command line. |
| 71 | # This doesn't cover all the different option formats you can use, |
| 72 | # but it's mainly intended to avoid duplicating flags on the automatic |
| 73 | # makefile regeneration which only uses this format. |
| 74 | specified_includes = set() |
| 75 | args = args or [] |
| 76 | for arg in args: |
| 77 | if arg.startswith('-I') and len(arg) > 2: |
| 78 | specified_includes.add(os.path.realpath(arg[2:])) |
| 79 | result = [] |
| 80 | def AddInclude(path): |
| 81 | if os.path.realpath(path) not in specified_includes: |
| 82 | result.append(path) |
| 83 | if os.environ.get('GYP_INCLUDE_FIRST') != None: |
| 84 | AddInclude(os.path.join(checkout_root, os.environ.get('GYP_INCLUDE_FIRST'))) |
| 85 | # Always include Chromium's common.gypi, which we now have a copy of. |
| 86 | AddInclude(os.path.join(script_dir, 'chromium_common.gypi')) |
| 87 | # Optionally add supplemental .gypi files if present. |
| 88 | for supplement in supplemental_files: |
| 89 | AddInclude(supplement) |
| 90 | if os.environ.get('GYP_INCLUDE_LAST') != None: |
| 91 | AddInclude(os.path.join(checkout_root, os.environ.get('GYP_INCLUDE_LAST'))) |
| 92 | return result |
| 93 | |
| 94 | |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 95 | def main(): |
| 96 | # Disabling garbage collection saves about 5% processing time. Since this is a |
| 97 | # short-lived process it's not a problem. |
| 98 | gc.disable() |
| 99 | |
| 100 | args = sys.argv[1:] |
| 101 | |
| 102 | if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): |
| 103 | print 'Skipping gyp_webrtc.py due to GYP_CHROMIUM_NO_ACTION env var.' |
| 104 | sys.exit(0) |
| 105 | |
| 106 | if 'SKIP_WEBRTC_GYP_ENV' not in os.environ: |
| 107 | # Update the environment based on webrtc.gyp_env. |
| 108 | gyp_env_path = os.path.join(os.path.dirname(checkout_root), |
| 109 | 'webrtc.gyp_env') |
| 110 | gyp_helper.apply_gyp_environment_from_file(gyp_env_path) |
| 111 | |
| 112 | # This could give false positives since it doesn't actually do real option |
| 113 | # parsing. Oh well. |
| 114 | gyp_file_specified = False |
| 115 | for arg in args: |
| 116 | if arg.endswith('.gyp'): |
| 117 | gyp_file_specified = True |
| 118 | break |
| 119 | |
| 120 | # If we didn't get a file, assume 'all.gyp' in the root of the checkout. |
| 121 | if not gyp_file_specified: |
| 122 | # Because of a bug in gyp, simply adding the abspath to all.gyp doesn't |
| 123 | # work, but chdir'ing and adding the relative path does. Spooky :/ |
| 124 | os.chdir(checkout_root) |
| 125 | args.append('all.gyp') |
| 126 | |
| 127 | # There shouldn't be a circular dependency relationship between .gyp files, |
| 128 | args.append('--no-circular-check') |
| 129 | |
| 130 | # Default to ninja unless GYP_GENERATORS is set. |
| 131 | if not os.environ.get('GYP_GENERATORS'): |
| 132 | os.environ['GYP_GENERATORS'] = 'ninja' |
| 133 | |
| 134 | # Enable check for missing sources in GYP files on Windows. |
| 135 | if sys.platform.startswith('win'): |
| 136 | gyp_generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '') |
| 137 | if not 'msvs_error_on_missing_sources' in gyp_generator_flags: |
| 138 | os.environ['GYP_GENERATOR_FLAGS'] = ( |
| 139 | gyp_generator_flags + ' msvs_error_on_missing_sources=1') |
| 140 | |
kjellander@webrtc.org | 0026dd8 | 2016-05-19 13:30:09 +0200 | [diff] [blame] | 141 | vs2013_runtime_dll_dirs = None |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 142 | if int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')): |
| 143 | vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() |
| 144 | |
| 145 | # Enforce gyp syntax checking. This adds about 20% execution time. |
| 146 | args.append('--check') |
| 147 | |
| 148 | supplemental_includes = GetSupplementalFiles() |
| 149 | gyp_vars = gyp_chromium.GetGypVars(supplemental_includes) |
| 150 | |
| 151 | # Automatically turn on crosscompile support for platforms that need it. |
| 152 | if all(('ninja' in os.environ.get('GYP_GENERATORS', ''), |
| 153 | gyp_vars.get('OS') in ['android', 'ios'], |
| 154 | 'GYP_CROSSCOMPILE' not in os.environ)): |
| 155 | os.environ['GYP_CROSSCOMPILE'] = '1' |
| 156 | |
Henrik Kjellander | f363d14 | 2016-09-28 09:44:58 +0200 | [diff] [blame] | 157 | args.extend(['-I' + i for i in additional_include_files(supplemental_includes, |
| 158 | args)]) |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 159 | |
| 160 | # Set the gyp depth variable to the root of the checkout. |
| 161 | args.append('--depth=' + os.path.relpath(checkout_root)) |
| 162 | |
| 163 | print 'Updating projects from gyp files...' |
| 164 | sys.stdout.flush() |
| 165 | |
| 166 | # Off we go... |
| 167 | gyp_rc = gyp.main(args) |
| 168 | |
| 169 | if vs2013_runtime_dll_dirs: |
kjellander@webrtc.org | 0026dd8 | 2016-05-19 13:30:09 +0200 | [diff] [blame] | 170 | # pylint: disable=unpacking-non-sequence |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 171 | x64_runtime, x86_runtime = vs2013_runtime_dll_dirs |
| 172 | vs_toolchain.CopyVsRuntimeDlls( |
Henrik Kjellander | f363d14 | 2016-09-28 09:44:58 +0200 | [diff] [blame] | 173 | os.path.join(checkout_root, GetOutputDirectory()), |
kjellander@webrtc.org | 001c20d | 2016-04-18 16:32:52 +0200 | [diff] [blame] | 174 | (x86_runtime, x64_runtime)) |
| 175 | |
| 176 | sys.exit(gyp_rc) |
| 177 | |
| 178 | |
| 179 | if __name__ == '__main__': |
| 180 | sys.exit(main()) |
| 181 | |