gyp_chromium 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/usr/bin/env python
  2. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # This script is wrapper for Chromium that adds some support for how GYP
  6. # is invoked by Chromium beyond what can be done in the gclient hooks.
  7. import glob
  8. import os
  9. import shlex
  10. import subprocess
  11. import sys
  12. script_dir = os.path.dirname(os.path.realpath(__file__))
  13. chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
  14. sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
  15. import gyp
  16. # Add paths so that pymod_do_main(...) can import files.
  17. sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
  18. sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))
  19. sys.path.insert(1, os.path.join(chrome_src, 'native_client', 'build'))
  20. # On Windows, Psyco shortens warm runs of build/gyp_chromium by about
  21. # 20 seconds on a z600 machine with 12 GB of RAM, from 90 down to 70
  22. # seconds. Conversely, memory usage of build/gyp_chromium with Psyco
  23. # maxes out at about 158 MB vs. 132 MB without it.
  24. #
  25. # Psyco uses native libraries, so we need to load a different
  26. # installation depending on which OS we are running under. It has not
  27. # been tested whether using Psyco on our Mac and Linux builds is worth
  28. # it (the GYP running time is a lot shorter, so the JIT startup cost
  29. # may not be worth it).
  30. if sys.platform == 'win32':
  31. try:
  32. sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'psyco_win32'))
  33. import psyco
  34. except:
  35. psyco = None
  36. else:
  37. psyco = None
  38. def apply_gyp_environment(file_path=None):
  39. """
  40. Reads in a *.gyp_env file and applies the valid keys to os.environ.
  41. """
  42. if not file_path or not os.path.exists(file_path):
  43. return
  44. file_contents = open(file_path).read()
  45. try:
  46. file_data = eval(file_contents, {'__builtins__': None}, None)
  47. except SyntaxError, e:
  48. e.filename = os.path.abspath(file_path)
  49. raise
  50. supported_vars = ( 'CC',
  51. 'CHROMIUM_GYP_FILE',
  52. 'CHROMIUM_GYP_SYNTAX_CHECK',
  53. 'CXX',
  54. 'GYP_DEFINES',
  55. 'GYP_GENERATOR_FLAGS',
  56. 'GYP_GENERATOR_OUTPUT',
  57. 'GYP_GENERATORS', )
  58. for var in supported_vars:
  59. val = file_data.get(var)
  60. if val:
  61. if var in os.environ:
  62. print 'INFO: Environment value for "%s" overrides value in %s.' % (
  63. var, os.path.abspath(file_path)
  64. )
  65. else:
  66. os.environ[var] = val
  67. def additional_include_files(args=[]):
  68. """
  69. Returns a list of additional (.gypi) files to include, without
  70. duplicating ones that are already specified on the command line.
  71. """
  72. # Determine the include files specified on the command line.
  73. # This doesn't cover all the different option formats you can use,
  74. # but it's mainly intended to avoid duplicating flags on the automatic
  75. # makefile regeneration which only uses this format.
  76. specified_includes = set()
  77. for arg in args:
  78. if arg.startswith('-I') and len(arg) > 2:
  79. specified_includes.add(os.path.realpath(arg[2:]))
  80. result = []
  81. def AddInclude(path):
  82. if os.path.realpath(path) not in specified_includes:
  83. result.append(path)
  84. # Always include common.gypi.
  85. AddInclude(os.path.join(script_dir, 'common.gypi'))
  86. # Optionally add supplemental .gypi files if present.
  87. supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
  88. for supplement in supplements:
  89. AddInclude(supplement)
  90. return result
  91. if __name__ == '__main__':
  92. args = sys.argv[1:]
  93. # Use the Psyco JIT if available.
  94. if psyco:
  95. psyco.profile()
  96. print "Enabled Psyco JIT."
  97. # Fall back on hermetic python if we happen to get run under cygwin.
  98. # TODO(bradnelson): take this out once this issue is fixed:
  99. # http://code.google.com/p/gyp/issues/detail?id=177
  100. if sys.platform == 'cygwin':
  101. python_dir = os.path.join(chrome_src, 'third_party', 'python_26')
  102. env = os.environ.copy()
  103. env['PATH'] = python_dir + os.pathsep + env.get('PATH', '')
  104. p = subprocess.Popen(
  105. [os.path.join(python_dir, 'python.exe')] + sys.argv,
  106. env=env, shell=False)
  107. p.communicate()
  108. sys.exit(p.returncode)
  109. if 'SKIP_CHROMIUM_GYP_ENV' not in os.environ:
  110. # Update the environment based on chromium.gyp_env
  111. gyp_env_path = os.path.join(os.path.dirname(chrome_src), 'chromium.gyp_env')
  112. apply_gyp_environment(gyp_env_path)
  113. # This could give false positives since it doesn't actually do real option
  114. # parsing. Oh well.
  115. gyp_file_specified = False
  116. for arg in args:
  117. if arg.endswith('.gyp'):
  118. gyp_file_specified = True
  119. break
  120. # If we didn't get a file, check an env var, and then fall back to
  121. # assuming 'all.gyp' from the same directory as the script.
  122. if not gyp_file_specified:
  123. gyp_file = os.environ.get('CHROMIUM_GYP_FILE')
  124. if gyp_file:
  125. # Note that CHROMIUM_GYP_FILE values can't have backslashes as
  126. # path separators even on Windows due to the use of shlex.split().
  127. args.extend(shlex.split(gyp_file))
  128. else:
  129. args.append(os.path.join(script_dir, 'all.gyp'))
  130. args.extend(['-I' + i for i in additional_include_files(args)])
  131. # There shouldn't be a circular dependency relationship between .gyp files,
  132. # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
  133. # currently exist. The check for circular dependencies is currently
  134. # bypassed on other platforms, but is left enabled on the Mac, where a
  135. # violation of the rule causes Xcode to misbehave badly.
  136. # TODO(mark): Find and kill remaining circular dependencies, and remove this
  137. # option. http://crbug.com/35878.
  138. # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
  139. # list.
  140. if sys.platform not in ('darwin',):
  141. args.append('--no-circular-check')
  142. # If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
  143. # to enfore syntax checking.
  144. syntax_check = os.environ.get('CHROMIUM_GYP_SYNTAX_CHECK')
  145. if syntax_check and int(syntax_check):
  146. args.append('--check')
  147. print 'Updating projects from gyp files...'
  148. sys.stdout.flush()
  149. # Off we go...
  150. sys.exit(gyp.main(args))