blob: 9ac4c1413689320b24382334d5bbc75395cd4dbb [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'))
23sys.path.insert(0, os.path.join(checkout_root, 'tools', 'find_depot_tools'))
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000024import gyp_chromium
25import gyp_helper
kjellander@webrtc.orgd10bdd32014-04-01 10:40:03 +000026import vs_toolchain
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000027
28sys.path.insert(0, os.path.join(checkout_root, 'tools', 'gyp', 'pylib'))
29import gyp
30
31
32if __name__ == '__main__':
33 args = sys.argv[1:]
34
35 if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)):
36 print 'Skipping gyp_webrtc due to GYP_CHROMIUM_NO_ACTION env var.'
37 sys.exit(0)
38
39 if 'SKIP_WEBRTC_GYP_ENV' not in os.environ:
40 # Update the environment based on webrtc.gyp_env
41 gyp_env_path = os.path.join(os.path.dirname(checkout_root),
42 'webrtc.gyp_env')
43 gyp_helper.apply_gyp_environment_from_file(gyp_env_path)
44
45 # This could give false positives since it doesn't actually do real option
46 # parsing. Oh well.
47 gyp_file_specified = False
48 for arg in args:
49 if arg.endswith('.gyp'):
50 gyp_file_specified = True
51 break
52
53 # If we didn't get a file, assume 'all.gyp' in the root of the checkout.
54 if not gyp_file_specified:
55 args.append(os.path.join(checkout_root, 'all.gyp'))
56
57 # There shouldn't be a circular dependency relationship between .gyp files,
58 args.append('--no-circular-check')
59
60 # Default to ninja unless GYP_GENERATORS is set.
61 if not os.environ.get('GYP_GENERATORS'):
62 os.environ['GYP_GENERATORS'] = 'ninja'
63
kjellander@webrtc.orgd10bdd32014-04-01 10:40:03 +000064 vs2013_runtime_dll_dirs = vs_toolchain.DownloadVsToolchain()
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000065
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000066 # Enforce gyp syntax checking. This adds about 20% execution time.
67 args.append('--check')
68
69 supplemental_includes = gyp_chromium.GetSupplementalFiles()
kjellander@webrtc.orgd10bdd32014-04-01 10:40:03 +000070 gn_vars_dict = gyp_chromium.GetGypVars(supplemental_includes)
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000071
72 # Automatically turn on crosscompile support for platforms that need it.
73 if all(('ninja' in os.environ.get('GYP_GENERATORS', ''),
74 gn_vars_dict.get('OS') in ['android', 'ios'],
75 'GYP_CROSSCOMPILE' not in os.environ)):
76 os.environ['GYP_CROSSCOMPILE'] = '1'
77
kjellander@webrtc.org7d7f0892014-01-31 09:34:51 +000078 args.extend(['-I' + i for i in
79 gyp_chromium.additional_include_files(supplemental_includes,
80 args)])
81
82 # Set the gyp depth variable to the root of the checkout.
83 args.append('--depth=' + os.path.relpath(checkout_root))
84
85 print 'Updating projects from gyp files...'
86 sys.stdout.flush()
87
88 # Off we go...
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000089 gyp_rc = gyp.main(args)
90
91 if vs2013_runtime_dll_dirs:
92 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs
kjellander@webrtc.orgd10bdd32014-04-01 10:40:03 +000093 vs_toolchain.CopyVsRuntimeDlls(
kjellander@webrtc.org6b0cbcb2014-03-10 09:51:17 +000094 os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()),
95 (x86_runtime, x64_runtime))
96
97 sys.exit(gyp_rc)