blob: cfe9ace1fc4a4fd13b9f3f4291c223dc225ff919 [file] [log] [blame]
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +00001#!/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
14import glob
15import os
16import shlex
17import sys
18
19script_dir = os.path.dirname(os.path.realpath(__file__))
20checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir, os.pardir))
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000021
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000022sys.path.insert(0, os.path.join(checkout_root, 'build'))
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000023import gyp_chromium
24import gyp_helper
kjellander@webrtc.orgd10bdd32014-04-01 10:40:03 +000025import vs_toolchain
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000026
27sys.path.insert(0, os.path.join(checkout_root, 'tools', 'gyp', 'pylib'))
28import gyp
29
kjellander@webrtc.org89256622014-08-20 12:10:11 +000030def 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.org7d7f0892014-01-31 09:34:51 +000037
38if __name__ == '__main__':
39 args = sys.argv[1:]
40
Henrik Kjellander81087642015-09-28 21:56:40 +020041 use_analyzer = len(args) and args[0] == '--analyzer'
42 if use_analyzer:
43 args.pop(0)
44 os.environ['GYP_GENERATORS'] = 'analyzer'
45 args.append('-Gconfig_path=' + args.pop(0))
46 args.append('-Ganalyzer_output_path=' + args.pop(0))
47
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000048 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)):
49 print 'Skipping gyp_webrtc due to GYP_CHROMIUM_NO_ACTION env var.'
50 sys.exit(0)
51
52 if 'SKIP_WEBRTC_GYP_ENV' not in os.environ:
53 # Update the environment based on webrtc.gyp_env
54 gyp_env_path = os.path.join(os.path.dirname(checkout_root),
55 'webrtc.gyp_env')
56 gyp_helper.apply_gyp_environment_from_file(gyp_env_path)
57
58 # This could give false positives since it doesn't actually do real option
59 # parsing. Oh well.
60 gyp_file_specified = False
61 for arg in args:
62 if arg.endswith('.gyp'):
63 gyp_file_specified = True
64 break
65
66 # If we didn't get a file, assume 'all.gyp' in the root of the checkout.
67 if not gyp_file_specified:
kjellander@webrtc.org89256622014-08-20 12:10:11 +000068 # Because of a bug in gyp, simply adding the abspath to all.gyp doesn't
69 # work, but chdir'ing and adding the relative path does. Spooky :/
70 os.chdir(checkout_root)
71 args.append('all.gyp')
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000072
73 # There shouldn't be a circular dependency relationship between .gyp files,
74 args.append('--no-circular-check')
75
76 # Default to ninja unless GYP_GENERATORS is set.
77 if not os.environ.get('GYP_GENERATORS'):
78 os.environ['GYP_GENERATORS'] = 'ninja'
79
Henrik Kjellander06c577f2015-05-13 15:00:14 +020080 # Enable check for missing sources in GYP files on Windows.
81 if sys.platform.startswith('win'):
82 gyp_generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '')
83 if not 'msvs_error_on_missing_sources' in gyp_generator_flags:
84 os.environ['GYP_GENERATOR_FLAGS'] = (
85 gyp_generator_flags + ' msvs_error_on_missing_sources=1')
86
andrew@webrtc.org1152fe22014-04-28 15:46:32 +000087 vs2013_runtime_dll_dirs = None
88 if int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')):
kjellander@webrtc.org59343ee2014-04-29 09:36:40 +000089 vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs()
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000090
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000091 # Enforce gyp syntax checking. This adds about 20% execution time.
92 args.append('--check')
93
kjellander@webrtc.org89256622014-08-20 12:10:11 +000094 supplemental_includes = GetSupplementalFiles()
Henrik Kjellander06c80132015-04-08 15:28:49 +020095 gyp_vars = gyp_chromium.GetGypVars(supplemental_includes)
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000096
97 # Automatically turn on crosscompile support for platforms that need it.
98 if all(('ninja' in os.environ.get('GYP_GENERATORS', ''),
Henrik Kjellander06c80132015-04-08 15:28:49 +020099 gyp_vars.get('OS') in ['android', 'ios'],
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +0000100 'GYP_CROSSCOMPILE' not in os.environ)):
101 os.environ['GYP_CROSSCOMPILE'] = '1'
102
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +0000103 args.extend(['-I' + i for i in
104 gyp_chromium.additional_include_files(supplemental_includes,
105 args)])
106
107 # Set the gyp depth variable to the root of the checkout.
108 args.append('--depth=' + os.path.relpath(checkout_root))
109
Henrik Kjellander81087642015-09-28 21:56:40 +0200110 if not use_analyzer:
111 print 'Updating projects from gyp files...'
112 sys.stdout.flush()
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +0000113
114 # Off we go...
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +0000115 gyp_rc = gyp.main(args)
116
Henrik Kjellander81087642015-09-28 21:56:40 +0200117 if vs2013_runtime_dll_dirs and not use_analyzer:
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +0000118 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs
kjellander@webrtc.orgd10bdd32014-04-01 10:40:03 +0000119 vs_toolchain.CopyVsRuntimeDlls(
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +0000120 os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()),
121 (x86_runtime, x64_runtime))
122
123 sys.exit(gyp_rc)