gyp_crashpad.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env python
  2. # Copyright 2014 The Crashpad Authors. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os
  16. import sys
  17. def ChooseDependencyPath(local_path, external_path):
  18. """Chooses between a dependency located at local path and an external path.
  19. The local path, used in standalone builds, is preferred. If it is not present
  20. but the external path is, the external path will be used. If neither path is
  21. present, the local path will be used, so that error messages uniformly refer
  22. to the local path.
  23. Args:
  24. local_path: The preferred local path to use for a standalone build.
  25. external_path: The external path to fall back to.
  26. Returns:
  27. A 2-tuple. The first element is None or 'external', depending on whether
  28. local_path or external_path was chosen. The second element is the chosen
  29. path.
  30. """
  31. if os.path.exists(local_path) or not os.path.exists(external_path):
  32. return (None, local_path)
  33. return ('external', external_path)
  34. script_dir = os.path.dirname(__file__)
  35. crashpad_dir = (os.path.dirname(script_dir) if script_dir not in ('', os.curdir)
  36. else os.pardir)
  37. sys.path.insert(0,
  38. ChooseDependencyPath(os.path.join(crashpad_dir, 'third_party', 'gyp', 'gyp',
  39. 'pylib'),
  40. os.path.join(crashpad_dir, os.pardir, os.pardir, 'gyp',
  41. 'pylib'))[1])
  42. import gyp
  43. def main(args):
  44. if 'GYP_GENERATORS' not in os.environ:
  45. os.environ['GYP_GENERATORS'] = 'ninja'
  46. crashpad_dir_or_dot = crashpad_dir if crashpad_dir is not '' else os.curdir
  47. (dependencies, mini_chromium_common_gypi) = (ChooseDependencyPath(
  48. os.path.join(crashpad_dir, 'third_party', 'mini_chromium',
  49. 'mini_chromium', 'build', 'common.gypi'),
  50. os.path.join(crashpad_dir, os.pardir, os.pardir, 'mini_chromium',
  51. 'mini_chromium', 'build', 'common.gypi')))
  52. if dependencies is not None:
  53. args.extend(['-D', 'crashpad_dependencies=%s' % dependencies])
  54. args.extend(['--include', mini_chromium_common_gypi])
  55. args.extend(['--depth', crashpad_dir_or_dot])
  56. args.append(os.path.join(crashpad_dir, 'crashpad.gyp'))
  57. result = gyp.main(args)
  58. if result != 0:
  59. return result
  60. if sys.platform == 'win32':
  61. # Check to make sure that no target_arch was specified. target_arch may be
  62. # set during a cross build, such as a cross build for Android.
  63. has_target_arch = False
  64. for arg_index in xrange(0, len(args)):
  65. arg = args[arg_index]
  66. if (arg.startswith('-Dtarget_arch=') or
  67. (arg == '-D' and arg_index + 1 < len(args) and
  68. args[arg_index + 1].startswith('target_arch='))):
  69. has_target_arch = True
  70. break
  71. if not has_target_arch:
  72. # Also generate the x86 build.
  73. result = gyp.main(args + ['-D', 'target_arch=ia32', '-G', 'config=Debug'])
  74. if result != 0:
  75. return result
  76. result = gyp.main(
  77. args + ['-D', 'target_arch=ia32', '-G', 'config=Release'])
  78. return result
  79. if __name__ == '__main__':
  80. sys.exit(main(sys.argv[1:]))