configure 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env python
  2. # Copyright (c) 2011 Google Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following disclaimer
  12. # in the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. import os
  30. import subprocess
  31. from optparse import OptionParser
  32. def chdir_to_source():
  33. source_directory = os.path.abspath(os.path.join(__file__, '..', '..'))
  34. os.chdir(source_directory)
  35. def gyp():
  36. return os.path.join('ThirdParty', 'gyp', 'gyp')
  37. class Project:
  38. def __init__(self, name):
  39. self._name = name
  40. def name(self):
  41. return self._name
  42. def _gyp_directory(self):
  43. return os.path.join(self._name, 'gyp')
  44. def _gyp_file_for_port(self, port):
  45. # Gyp uses the gyp file name as the XCode proj file name, so for now "apple-mac" must be ProjectName.gyp
  46. if port == "mac":
  47. return '%s.gyp' % self._name
  48. return "%s.gyp" % port
  49. def inputs(self, port):
  50. return [
  51. os.path.join(self._gyp_directory(), self._gyp_file_for_port(port)),
  52. os.path.join(self._name, self._name + '.gypi'),
  53. os.path.join('gyp', 'common.gypi'),
  54. ]
  55. def _output_for_port(self, port):
  56. format = format_for_port(port)
  57. return {
  58. 'filelist': '%s.am' % port,
  59. 'xcode': os.path.join(self._name + '.xcodeproj', 'project.pbxproj'),
  60. }[format]
  61. def output(self, port):
  62. return os.path.join(self._gyp_directory(), self._output_for_port(port))
  63. def should_generate(self, port):
  64. if not os.path.exists(self.output(port)):
  65. return True
  66. return os.path.getmtime(self.output(port)) < self._newest(self.inputs(port))
  67. def _extra_args_for_format(self, format):
  68. if format == "xcode":
  69. return ['-G', 'xcode_list_excluded_files=0']
  70. return []
  71. def generate(self, port):
  72. args = [
  73. gyp(),
  74. self.inputs(port)[0],
  75. '--depth=.',
  76. ]
  77. format = format_for_port(port)
  78. args.append('--format=%s' % format)
  79. args += self._extra_args_for_format(format)
  80. subprocess.call(args)
  81. # GYP doesn't always touch the output file, but we want to touch the
  82. # file so that we don't keep trying to regenerate it.
  83. os.utime(self.output(port), None)
  84. @staticmethod
  85. def _newest(paths):
  86. return max([os.path.getmtime(path) for path in paths])
  87. def format_for_port(port):
  88. return {
  89. 'mac': 'xcode',
  90. 'gtk': 'filelist',
  91. 'win': 'msvs',
  92. }[port] # Valid port is required.
  93. PROJECTS = [
  94. Project("JavaScriptCore"),
  95. Project("WebCore"),
  96. ]
  97. def projects_to_generate(port):
  98. should_generate = [project for project in PROJECTS if project.should_generate(port)]
  99. already_generated = [project.name() for project in set(PROJECTS) - set(should_generate)]
  100. if already_generated:
  101. print "Not generating %s because the generated files exist and are newer than the GYP files." % ', '.join(already_generated)
  102. print "Pass --regenerate-projects to override."
  103. return should_generate
  104. def main():
  105. chdir_to_source()
  106. parser = OptionParser()
  107. parser.add_option("--port", dest="port", action="store", default="mac", # Default to Mac for now
  108. help="Which port to generate for.")
  109. parser.add_option("--regenerate-projects", dest="regenerate_projects",
  110. default=False, action="store_true",
  111. help="Generate all project files even if they appear to be up to date.")
  112. (options, args) = parser.parse_args()
  113. projects = PROJECTS
  114. if not options.regenerate_projects:
  115. projects = projects_to_generate(options.port)
  116. for project in projects:
  117. print "Generating %s." % project.name()
  118. project.generate(options.port)
  119. if __name__ == "__main__":
  120. main()