14a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com#!/usr/bin/env python
24a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com#
34a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# Copyright 2014 The LibYuv Project Authors. All rights reserved.
44a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com#
54a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# Use of this source code is governed by a BSD-style license
64a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# that can be found in the LICENSE file in the root of the source
74a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# tree. An additional intellectual property rights grant can be found
84a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# in the file PATENTS. All contributing project authors may
94a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# be found in the AUTHORS file in the root of the source tree.
104a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
114a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# This script is used to run GYP for libyuv. It contains selected parts of the
124a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com# main function from the src/build/gyp_chromium file.
134a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
144a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport glob
154a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport os
164a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport shlex
174a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport sys
184a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
194a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comcheckout_root = os.path.dirname(os.path.realpath(__file__))
204a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
214a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comsys.path.insert(0, os.path.join(checkout_root, 'build'))
224a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comsys.path.insert(0, os.path.join(checkout_root, 'tools', 'find_depot_tools'))
234a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport gyp_chromium
244a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport gyp_helper
25973da212e68359566401f8733d415aae2fbbe756kjellander@google.comimport vs_toolchain
264a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
274a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comsys.path.insert(0, os.path.join(checkout_root, 'tools', 'gyp', 'pylib'))
284a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comimport gyp
294a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
304a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
314a1836050df3cd554f68708e0097769386e74f40fbarchard@google.comif __name__ == '__main__':
324a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  args = sys.argv[1:]
334a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
344a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # This could give false positives since it doesn't actually do real option
354a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # parsing.  Oh well.
364a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  gyp_file_specified = False
374a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  for arg in args:
384a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com    if arg.endswith('.gyp'):
394a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com      gyp_file_specified = True
404a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com      break
414a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
424a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # If we didn't get a file, assume 'all.gyp' in the root of the checkout.
434a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  if not gyp_file_specified:
444a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com    args.append(os.path.join(checkout_root, 'all.gyp'))
454a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
464a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # There shouldn't be a circular dependency relationship between .gyp files,
474a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  args.append('--no-circular-check')
484a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
494a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # Default to ninja unless GYP_GENERATORS is set.
504a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  if not os.environ.get('GYP_GENERATORS'):
514a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com    os.environ['GYP_GENERATORS'] = 'ninja'
524a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
5305c4c715090dd1ffdd3b9bbc52cc078e6398ac3afbarchard@google.com  vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs()
544a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
554a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # Enforce gyp syntax checking. This adds about 20% execution time.
564a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  args.append('--check')
574a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
584a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  supplemental_includes = gyp_chromium.GetSupplementalFiles()
59973da212e68359566401f8733d415aae2fbbe756kjellander@google.com  gyp_vars_dict = gyp_chromium.GetGypVars(supplemental_includes)
604a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
614a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # Automatically turn on crosscompile support for platforms that need it.
624a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  if all(('ninja' in os.environ.get('GYP_GENERATORS', ''),
63973da212e68359566401f8733d415aae2fbbe756kjellander@google.com          gyp_vars_dict.get('OS') in ['android', 'ios'],
644a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com          'GYP_CROSSCOMPILE' not in os.environ)):
654a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com    os.environ['GYP_CROSSCOMPILE'] = '1'
664a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
674a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  args.extend(['-I' + i for i in
684a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com               gyp_chromium.additional_include_files(supplemental_includes,
694a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com                                                     args)])
704a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
714a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # Set the gyp depth variable to the root of the checkout.
724a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  args.append('--depth=' + os.path.relpath(checkout_root))
734a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
744a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  print 'Updating projects from gyp files...'
754a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  sys.stdout.flush()
764a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
774a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  # Off we go...
784a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  gyp_rc = gyp.main(args)
794a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
804a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  if vs2013_runtime_dll_dirs:
814a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com    x64_runtime, x86_runtime = vs2013_runtime_dll_dirs
82973da212e68359566401f8733d415aae2fbbe756kjellander@google.com    vs_toolchain.CopyVsRuntimeDlls(
834a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com        os.path.join(checkout_root, gyp_chromium.GetOutputDirectory()),
844a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com        (x86_runtime, x64_runtime))
854a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com
864a1836050df3cd554f68708e0097769386e74f40fbarchard@google.com  sys.exit(gyp_rc)
87