Permalink
Browse files

[ttmodule] Copy the Three20.bundle when adding Three20 to a project.

  • Loading branch information...
1 parent 564a013 commit 7724473817d10a28dbf84d5279eaa3a10fb86e92 @jverkoey jverkoey committed Oct 22, 2010
Showing with 79 additions and 23 deletions.
  1. +77 −23 src/scripts/Pbxproj.py
  2. +2 −0 src/scripts/ttmodule.py
View
@@ -160,15 +160,28 @@ def dependencies(self):
if project_data is None:
return None
- result = re.search('([A-Z0-9]+) \/\* '+re.escape(self.target)+' \*\/ = {\n[ \t]+isa = PBXNativeTarget;(?:.|\n)+?([A-Z0-9]+) \/\* Frameworks \*\/,(?:.|\n)+?dependencies = \(\n((?:[ \t]+[A-Z0-9]+ \/\* PBXTargetDependency \*\/,\n)*)[ \t]*\);\n(?:.|\n)+?productReference = ([A-Z0-9]+) \/\* (.+?) \*\/;',
+ result = re.search('([A-Z0-9]+) \/\* '+re.escape(self.target)+' \*\/ = {\n[ \t]+isa = PBXNativeTarget;(?:.|\n)+?buildPhases = \(\n((?:.|\n)+?)\);\n(?:.|\n)+?dependencies = \(\n((?:[ \t]+[A-Z0-9]+ \/\* PBXTargetDependency \*\/,\n)*)[ \t]*\);\n(?:.|\n)+?productReference = ([A-Z0-9]+) \/\* (.+?) \*\/;',
project_data)
if not result:
return None
- (self._guid, self._frameworks_guid, dependency_set, self._product_guid, self._product_name, ) = result.groups()
+ (self._guid, buildPhases, dependency_set, self._product_guid, self._product_name, ) = result.groups()
dependency_guids = re.findall('[ \t]+([A-Z0-9]+) \/\* PBXTargetDependency \*\/,\n', dependency_set)
+ match = re.search('([A-Z0-9]+) \/\* Resources \*\/', buildPhases)
+ if match:
+ (self._resources_guid, ) = match.groups()
+ else:
+ self._resources_guid = None
+
+ match = re.search('([A-Z0-9]+) \/\* Frameworks \*\/', buildPhases)
+ if not match:
+ logging.error("Couldn't find the Frameworks phase.")
+ return None
+
+ (self._frameworks_guid, ) = match.groups()
+
if not result:
return None
@@ -254,56 +267,68 @@ def add_filereference(self, name, file_type, default_guid, rel_path, source_tree
return fileref_hash
- # Add a file to the Frameworks PBXGroup.
+ # Add a file to the given PBXGroup.
#
# <guid> /* <name> */,
- def add_file_to_frameworks(self, name, guid):
+ def add_file_to_group(self, name, guid, group):
project_data = self.get_project_data()
- match = re.search('\/\* Frameworks \*\/ = \{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \(\n((?:.|\n)+?)\);', project_data)
+ match = re.search('\/\* '+re.escape(group)+' \*\/ = \{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \(\n((?:.|\n)+?)\);', project_data)
if not match:
- logging.error("Couldn't find the Frameworks children.")
+ logging.error("Couldn't find the "+group+" children.")
return False
-
+
(children,) = match.groups()
match = re.search(re.escape(guid), children)
if match:
- logging.info("This file is already a member of the Frameworks group.")
+ logging.info("This file is already a member of the "+name+" group.")
else:
- match = re.search('\/\* Frameworks \*\/ = \{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \(\n', project_data)
-
+ match = re.search('\/\* '+re.escape(group)+' \*\/ = \{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \(\n', project_data)
+
if not match:
- logging.error("Couldn't find the Frameworks group.")
+ logging.error("Couldn't find the "+group+" group.")
return False
-
+
pbxgroup = "\t\t\t\t"+guid+" /* "+name+" */,\n"
project_data = project_data[:match.end()] + pbxgroup + project_data[match.end():]
self.set_project_data(project_data)
return True
- def add_file_to_frameworks_phase(self, name, guid):
+ # Add a file to the Frameworks PBXGroup.
+ #
+ # <guid> /* <name> */,
+ def add_file_to_frameworks(self, name, guid):
+ return self.add_file_to_group(name, guid, 'Frameworks')
+
+ # Add a file to the Resources PBXGroup.
+ #
+ # <guid> /* <name> */,
+ def add_file_to_resources(self, name, guid):
+ return self.add_file_to_group(name, guid, 'Resources')
+
+ def add_file_to_phase(self, name, guid, phase_guid, phase):
project_data = self.get_project_data()
-
- match = re.search(self._frameworks_guid+" \/\* Frameworks \*\/ = {(?:.|\n)+?files = \(((?:.|\n)+?)\);", project_data)
-
+
+ match = re.search(re.escape(phase_guid)+" \/\* "+re.escape(phase)+" \*\/ = {(?:.|\n)+?files = \(((?:.|\n)+?)\);", project_data)
+
if not match:
- logging.error("Couldn't find the frameworks.")
+ logging.error("Couldn't find the "+phase+" phase.")
return False
-
+
(files, ) = match.groups()
match = re.search(re.escape(guid), files)
if match:
- logging.info("The framework has already been added.")
+ logging.info("The file has already been added.")
else:
- match = re.search(self._frameworks_guid+" \/\* Frameworks \*\/ = {(?:.|\n)+?files = \(\n", project_data)
+ match = re.search(re.escape(phase_guid)+" \/\* "+phase+" \*\/ = {(?:.|\n)+?files = \(\n", project_data)
if not match:
- logging.error("Couldn't find the framework files")
+ logging.error("Couldn't find the "+phase+" files")
return False
-
- frameworktext = "\t\t\t\t"+guid+" /* "+name+" in Frameworks */,\n"
+
+ frameworktext = "\t\t\t\t"+guid+" /* "+name+" in "+phase+" */,\n"
project_data = project_data[:match.end()] + frameworktext + project_data[match.end():]
self.set_project_data(project_data)
@@ -315,6 +340,16 @@ def get_rel_path_to_products_dir(self):
build_path = os.path.join(os.path.join(os.path.dirname(Paths.src_dir), 'Build'), 'Products')
return relpath(project_path, build_path)
+ def add_file_to_frameworks_phase(self, name, guid):
+ return self.add_file_to_phase(name, guid, self._frameworks_guid, 'Frameworks')
+
+ def add_file_to_resources_phase(self, name, guid):
+ if self._resources_guid is None:
+ logging.error("No resources build phase found in the destination project")
+ return False
+
+ return self.add_file_to_phase(name, guid, self._resources_guid, 'Resources')
+
def add_header_search_path(self, configuration):
project_path = os.path.dirname(os.path.abspath(self.xcodeprojpath()))
build_path = os.path.join(os.path.join(os.path.join(os.path.dirname(Paths.src_dir), 'Build'), 'Products'), 'three20')
@@ -380,6 +415,25 @@ def add_framework(self, framework):
return True
+ def add_bundle(self):
+ tthash_base = self.get_hash_base('Three20.bundle')
+
+ project_path = os.path.dirname(os.path.abspath(self.xcodeprojpath()))
+ build_path = os.path.join(Paths.src_dir, 'Three20.bundle')
+ rel_path = relpath(project_path, build_path)
+
+ fileref_hash = self.add_filereference('Three20.bundle', 'plug-in', tthash_base+'0', rel_path, 'SOURCE_ROOT')
+
+ libfile_hash = self.add_buildfile('Three20.bundle', fileref_hash, tthash_base+'1')
+
+ if not self.add_file_to_resources('Three20.bundle', fileref_hash):
+ return False
+
+ if not self.add_file_to_resources_phase('Three20.bundle', libfile_hash):
+ return False
+
+ return True
+
def add_dependency(self, dep):
project_data = self.get_project_data()
dep_data = dep.get_project_data()
@@ -78,6 +78,8 @@ def add_modules_to_project(module_names, project, configs):
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)

0 comments on commit 7724473

Please sign in to comment.