You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/24 20:55:12 UTC

[2/2] ios commit: Add update_cordova_subproject script.

Add update_cordova_subproject script.

It edits the sub-project path of CordovaLib within another the parent
project.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/ebf4efa1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/ebf4efa1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/ebf4efa1

Branch: refs/heads/master
Commit: ebf4efa13bdb3c30b4f86d3549f0d5ff8806d4c6
Parents: 7ebbd83
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Aug 14 17:07:31 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 24 14:53:55 2012 -0400

----------------------------------------------------------------------
 bin/update_cordova_subproject |   71 ++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/ebf4efa1/bin/update_cordova_subproject
----------------------------------------------------------------------
diff --git a/bin/update_cordova_subproject b/bin/update_cordova_subproject
new file mode 100755
index 0000000..f7a4075
--- /dev/null
+++ b/bin/update_cordova_subproject
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+"""
+Updates the subproject path of the CordovaLib entry to point to this script's version of Cordova.
+
+Usage: CordovaVersion/bin/update_cordova_project path/to/your/app.xcodeproj
+"""
+
+import fileinput
+import os
+import re
+import sys
+
+def Usage():
+  print __doc__
+  sys.exit(1)
+
+def AbsParentPath(path):
+  return os.path.abspath(os.path.join(path, os.path.pardir))
+
+def AbsFrameworkPath(argv0):
+  script_path = argv0
+  # This can happen if the script's dir is in the user's PATH
+  if not os.path.exists(script_path):
+    raise Exception('Could not locale framework directory.')
+  return AbsParentPath(AbsParentPath(script_path))
+
+def AbsProjectPath(relative_path):
+  # Do an extra abspath here to strip off trailing / if present.
+  project_path = os.path.abspath(relative_path)
+  if project_path.endswith('.pbxproj'):
+    project_path = AbsParentPath(project_path)
+  elif project_path.endswith('.xcodeproj'):
+    pass
+  else:
+    raise Exception('The following is not a valid path to an XCode project: %s' % project_path)
+  return project_path
+
+def main(argv):
+  if len(argv) != 2:
+    Usage()
+
+  framework_path = AbsFrameworkPath(argv[0])
+  project_path = AbsProjectPath(argv[1])
+
+  parent_project_path = AbsParentPath(project_path)
+  cordova_lib_xcode_path = os.path.join(framework_path, 'CordovaLib', 'CordovaLib.xcodeproj')
+  subproject_path = os.path.relpath(cordova_lib_xcode_path, parent_project_path)
+
+  # /* CordovaLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = CordovaLib.xcodeproj; sourceTree = "<group>"; };
+  REGEX = re.compile(r'(.+PBXFileReference.+wrapper.pb-project.+)(path = .+?;)(.*)(sourceTree.+;)(.+)')
+
+  file_handle = fileinput.input(os.path.join(project_path, 'project.pbxproj'), inplace=1)
+  found = False
+  for line in file_handle:
+    if 'CordovaLib.xcodeproj' in line:
+      m = REGEX.match(line)
+      if m:
+        found = True
+        line = m.expand(r'\1path = "%s";\3sourceTree = "<group>";\5\n') % subproject_path
+        if 'name =' not in line:
+            line = line.replace('path = ', 'name = CordovaLib.xcodeproj; path = ')
+    print line,
+  file_handle.close()
+
+  if not found:
+    raise Exception('Sub-project entry not found in project file.')
+  print('CordovaLib set to path: %s' % subproject_path)
+
+
+if __name__ == '__main__':
+  main(sys.argv)