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 | |
| 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 file. |
| 13 | |
| 14 | import glob |
| 15 | import os |
| 16 | import shlex |
| 17 | import sys |
| 18 | |
| 19 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 20 | checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir, os.pardir)) |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 21 | |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 22 | sys.path.insert(0, os.path.join(checkout_root, 'build')) |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 23 | import gyp_chromium |
| 24 | import gyp_helper |
kjellander@webrtc.org | d10bdd3 | 2014-04-01 10:40:03 +0000 | [diff] [blame] | 25 | import vs_toolchain |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 26 | |
| 27 | sys.path.insert(0, os.path.join(checkout_root, 'tools', 'gyp', 'pylib')) |
| 28 | import gyp |
| 29 | |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 30 | def GetSupplementalFiles(): |
| 31 | """Returns a list of the supplemental files that are included in all GYP |
| 32 | sources.""" |
| 33 | # Can't use the one in gyp_chromium since the directory location of the root |
| 34 | # is different. |
| 35 | return glob.glob(os.path.join(checkout_root, '*', 'supplement.gypi')) |
| 36 | |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 37 | |
| 38 | if __name__ == '__main__': |
| 39 | args = sys.argv[1:] |
| 40 | |
| 41 | if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)): |
| 42 | print 'Skipping gyp_webrtc due to GYP_CHROMIUM_NO_ACTION env var.' |
| 43 | sys.exit(0) |
| 44 | |
| 45 | if 'SKIP_WEBRTC_GYP_ENV' not in os.environ: |
| 46 | # Update the environment based on webrtc.gyp_env |
| 47 | gyp_env_path = os.path.join(os.path.dirname(checkout_root), |
| 48 | 'webrtc.gyp_env') |
| 49 | gyp_helper.apply_gyp_environment_from_file(gyp_env_path) |
| 50 | |
| 51 | # This could give false positives since it doesn't actually do real option |
| 52 | # parsing. Oh well. |
| 53 | gyp_file_specified = False |
| 54 | for arg in args: |
| 55 | if arg.endswith('.gyp'): |
| 56 | gyp_file_specified = True |
| 57 | break |
| 58 | |
| 59 | # If we didn't get a file, assume 'all.gyp' in the root of the checkout. |
| 60 | if not gyp_file_specified: |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 61 | # Because of a bug in gyp, simply adding the abspath to all.gyp doesn't |
| 62 | # work, but chdir'ing and adding the relative path does. Spooky :/ |
| 63 | os.chdir(checkout_root) |
| 64 | args.append('all.gyp') |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 65 | |
| 66 | # There shouldn't be a circular dependency relationship between .gyp files, |
| 67 | args.append('--no-circular-check') |
| 68 | |
| 69 | # Default to ninja unless GYP_GENERATORS is set. |
| 70 | if not os.environ.get('GYP_GENERATORS'): |
| 71 | os.environ['GYP_GENERATORS'] = 'ninja' |
| 72 | |
Henrik Kjellander | 06c577f | 2015-05-13 15:00:14 +0200 | [diff] [blame] | 73 | # Enable check for missing sources in GYP files on Windows. |
| 74 | if sys.platform.startswith('win'): |
| 75 | gyp_generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '') |
| 76 | if not 'msvs_error_on_missing_sources' in gyp_generator_flags: |
| 77 | os.environ['GYP_GENERATOR_FLAGS'] = ( |
| 78 | gyp_generator_flags + ' msvs_error_on_missing_sources=1') |
| 79 | |
andrew@webrtc.org | 1152fe2 | 2014-04-28 15:46:32 +0000 | [diff] [blame] | 80 | vs2013_runtime_dll_dirs = None |
| 81 | if int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')): |
kjellander@webrtc.org | 59343ee | 2014-04-29 09:36:40 +0000 | [diff] [blame] | 82 | vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 83 | |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 84 | # Enforce gyp syntax checking. This adds about 20% execution time. |
| 85 | args.append('--check') |
| 86 | |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 87 | supplemental_includes = GetSupplementalFiles() |
Henrik Kjellander | 06c8013 | 2015-04-08 15:28:49 +0200 | [diff] [blame] | 88 | gyp_vars = gyp_chromium.GetGypVars(supplemental_includes) |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 89 | |
| 90 | # Automatically turn on crosscompile support for platforms that need it. |
| 91 | if all(('ninja' in os.environ.get('GYP_GENERATORS', ''), |
Henrik Kjellander | 06c8013 | 2015-04-08 15:28:49 +0200 | [diff] [blame] | 92 | gyp_vars.get('OS') in ['android', 'ios'], |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 93 | 'GYP_CROSSCOMPILE' not in os.environ)): |
| 94 | os.environ['GYP_CROSSCOMPILE'] = '1' |
| 95 | |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 96 | args.extend(['-I' + i for i in |
| 97 | gyp_chromium.additional_include_files(supplemental_includes, |
| 98 | args)]) |
| 99 | |
| 100 | # Set the gyp depth variable to the root of the checkout. |
| 101 | args.append('--depth=' + os.path.relpath(checkout_root)) |
| 102 | |
kjellander | 7ae5e52 | 2016-02-08 23:46:34 -0800 | [diff] [blame] | 103 | print 'Updating projects from gyp files...' |
| 104 | sys.stdout.flush() |
kjellander@webrtc.org | 7d7f089 | 2014-01-31 09:34:51 +0000 | [diff] [blame] | 105 | |
| 106 | # Off we go... |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 107 | gyp_rc = gyp.main(args) |
| 108 | |
kjellander | 7ae5e52 | 2016-02-08 23:46:34 -0800 | [diff] [blame] | 109 | if vs2013_runtime_dll_dirs: |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 110 | x64_runtime, x86_runtime = vs2013_runtime_dll_dirs |
kjellander@webrtc.org | d10bdd3 | 2014-04-01 10:40:03 +0000 | [diff] [blame] | 111 | vs_toolchain.CopyVsRuntimeDlls( |
kjellander@webrtc.org | 6b0cbcb | 2014-03-10 09:51:17 +0000 | [diff] [blame] | 112 | os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()), |
| 113 | (x86_runtime, x64_runtime)) |
| 114 | |
| 115 | sys.exit(gyp_rc) |