2 # Copyright (c) 2011 Google Inc. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
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
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.
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.
34 from optparse import OptionParser
36 def chdir_to_source():
37 source_directory = os.path.abspath(os.path.join(__file__, '..', '..'))
38 os.chdir(source_directory)
41 return os.path.join('ThirdParty', 'gyp', 'gyp')
45 def __init__(self, name):
51 def _gyp_directory(self):
52 return os.path.join(self._name, 'gyp')
54 def _gyp_file_for_port(self, port):
55 # Gyp uses the gyp file name as the XCode proj file name, so for now "apple-mac" must be ProjectName.gyp
57 return '%s.gyp' % self._name
58 return "%s.gyp" % port
60 def inputs(self, port):
62 os.path.join(self._gyp_directory(), self._gyp_file_for_port(port)),
63 os.path.join(self._name, self._name + '.gypi'),
64 os.path.join('gyp', 'common.gypi'),
67 def _output_for_port(self, port):
68 format = format_for_port(port)
70 'filelist': '%s.am' % port,
71 'xcode': os.path.join(self._name + '.xcodeproj', 'project.pbxproj'),
74 def output(self, port):
75 return os.path.join(self._gyp_directory(), self._output_for_port(port))
77 def should_generate(self, port):
78 if not os.path.exists(self.output(port)):
80 return os.path.getmtime(self.output(port)) < self._newest(self.inputs(port))
82 def _extra_args_for_format(self, format):
84 return ['-G', 'xcode_list_excluded_files=0']
87 def generate(self, port):
93 format = format_for_port(port)
94 args.append('--format=%s' % format)
95 args += self._extra_args_for_format(format)
98 # GYP doesn't always touch the output file, but we want to touch the
99 # file so that we don't keep trying to regenerate it.
100 os.utime(self.output(port), None)
104 return max([os.path.getmtime(path) for path in paths])
107 def format_for_port(port):
112 }[port] # Valid port is required.
116 Project("JavaScriptCore"),
120 def projects_to_generate(port):
121 should_generate = [project for project in PROJECTS if project.should_generate(port)]
122 already_generated = [project.name() for project in set(PROJECTS) - set(should_generate)]
124 if already_generated:
125 print "Not generating %s because the generated files exist and are newer than the GYP files." % ', '.join(already_generated)
126 print "Pass --regenerate-projects to override."
128 return should_generate
134 parser = OptionParser()
135 parser.add_option("--port", dest="port", action="store", default="mac", # Default to Mac for now
136 help="Which port to generate for.")
137 parser.add_option("--regenerate-projects", dest="regenerate_projects",
138 default=False, action="store_true",
139 help="Generate all project files even if they appear to be up to date.")
140 (options, args) = parser.parse_args()
143 if not options.regenerate_projects:
144 projects = projects_to_generate(options.port)
146 for project in projects:
147 print "Generating %s." % project.name()
148 project.generate(options.port)
151 if __name__ == "__main__":