forked from facebookarchive/three20
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttmodule.py
More file actions
194 lines (144 loc) · 6.08 KB
/
Copy pathttmodule.py
File metadata and controls
194 lines (144 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
# encoding: utf-8
"""
ttmodule.py
Most of the documentation is found in Pbxproj.py.
Created by Jeff Verkoeyen on 2010-10-18.
Copyright 2009-2010 Facebook
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
import re
import os
import sys
from optparse import OptionParser
# Three20 Python Objects
import Paths
from Pbxproj import Pbxproj
# Print the given project's dependencies to stdout.
def print_dependencies(name):
pbxproj = Pbxproj.get_pbxproj_by_name(name)
print str(pbxproj)+"..."
if pbxproj.dependencies():
[sys.stdout.write("\t"+x+"\n") for x in pbxproj.dependencies()]
def get_dependency_modules(dependency_names):
dependency_modules = {}
if not dependency_names:
return dependency_modules
for name in dependency_names:
project = Pbxproj.get_pbxproj_by_name(name)
dependency_modules[project.uniqueid()] = project
dependencies = project.dependencies()
if dependencies is None:
print "Failed to get dependencies; it's possible that the given target doesn't exist."
sys.exit(0)
submodules = get_dependency_modules(dependencies)
for guid, submodule in submodules.items():
dependency_modules[guid] = submodule
return dependency_modules
def add_modules_to_project(module_names, project, configs):
logging.info(project)
logging.info("Checking dependencies...")
if project.dependencies() is None:
logging.error("Failed to get dependencies. Check the error logs for more details.")
sys.exit(0)
if len(project.dependencies()) == 0:
logging.info("\tNo dependencies.")
else:
logging.info("Existing dependencies:")
[logging.info("\t"+x) for x in project.dependencies()]
modules = get_dependency_modules(module_names)
logging.info("Requested dependency list:")
[logging.info("\t"+str(x)) for k,x in modules.items()]
logging.info("Adding dependencies...")
failed = []
for k,v in modules.items():
if v.name == 'Three20UI':
project.add_framework('QuartzCore.framework')
if v.name == 'Three20Core':
project.add_bundle()
if not project.add_dependency(v):
failed.append(k)
if configs:
for config in configs:
project.add_header_search_path(config)
project.add_build_setting(config, 'OTHER_LDFLAGS', '-ObjC')
else:
for configuration in project.configurations:
project.add_header_search_path(configuration[1])
for k,v in modules.items():
project.add_build_setting(configuration[1], 'OTHER_LDFLAGS', '-ObjC')
if len(failed) > 0:
logging.error("Some dependencies failed to be added:")
[logging.error("\t"+str(x)+"\n") for x in failed]
def main():
usage = '''%prog [options] module(s)
The Three20 Module Script.
Easily add Three20 modules to your projects.
MODULES:
Modules may take the form <module-name>(:<module-target>)
<module-target> defaults to <module-name> if it is not specified
<module-name> may be a path to a .pbxproj file.
EXAMPLES:
Most common use case:
> %prog -p path/to/myApp/myApp.xcodeproj Three20
For adding Xcode 4 support to an Xcode 3.2.# project:
> %prog -p path/to/myApp/myApp.xcodeproj Three20 --xcode-version=4
Print all dependencies for the Three20UI module
> %prog -d Three20UI
Print all dependencies for the extThree20JSON module's extThree20JSON+SBJSON target.
> %prog -d extThree20JSON:extThree20JSON+SBJSON
Add the Three20 project settings specifically to the Debug and Release configurations.
By default, all Three20 settings are added to all project configurations.
This includes adding the header search path and linker flags.
> %prog -p path/to/myApp.xcodeproj -c Debug -c Release
Add the extThree20XML module and all of its dependencies to the myApp project.
> %prog -p path/to/myApp.xcodeproj extThree20XML
Add a specific target of a module to a project.
> %prog -p path/to/myApp.xcodeproj extThree20JSON:extThree20JSON+SBJSON'''
parser = OptionParser(usage = usage)
parser.add_option("-d", "--dependencies", dest="print_dependencies",
help="Print dependencies for the given modules",
action="store_true")
parser.add_option("-v", "--verbose", dest="verbose",
help="Display verbose output",
action="store_true")
parser.add_option("-p", "--project", dest="projects",
help="Add the given modules to this project", action="append")
parser.add_option("--xcode-version", dest="xcode_version",
help="Set the xcode version you plan to open this project in. By default uses xcodebuild to determine your latest Xcode version.")
parser.add_option("-c", "--config", dest="configs",
help="Explicit configurations to add Three20 settings to (example: Debug). By default, ttmodule will add configuration settings to every configuration for the given target", action="append")
(options, args) = parser.parse_args()
if options.verbose:
log_level = logging.INFO
else:
log_level = logging.WARNING
logging.basicConfig(level=log_level)
did_anything = False
if options.print_dependencies:
[print_dependencies(x) for x in args]
did_anything = True
if options.projects is not None:
did_anything = True
if not options.xcode_version:
f=os.popen("xcodebuild -version")
xcodebuild_version = f.readlines()[0]
match = re.search('Xcode ([a-zA-Z0-9.]+)', xcodebuild_version)
if match:
(options.xcode_version, ) = match.groups()
for name in options.projects:
project = Pbxproj.get_pbxproj_by_name(name, xcode_version = options.xcode_version)
add_modules_to_project(args, project, options.configs)
if not did_anything:
parser.print_help()
if __name__ == "__main__":
sys.exit(main())