zerg_xcode 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +22 -14
  3. data/Rakefile +6 -0
  4. data/lib/zerg_xcode.rb +8 -3
  5. data/lib/zerg_xcode/builder/runner.rb +51 -0
  6. data/lib/zerg_xcode/builder/sdks.rb +34 -0
  7. data/lib/zerg_xcode/file_format/archiver.rb +15 -2
  8. data/lib/zerg_xcode/file_format/encoder.rb +15 -2
  9. data/lib/zerg_xcode/file_format/lexer.rb +15 -2
  10. data/lib/zerg_xcode/file_format/parser.rb +15 -2
  11. data/lib/zerg_xcode/file_format/paths.rb +15 -2
  12. data/lib/zerg_xcode/objects/pbx_build_file.rb +16 -3
  13. data/lib/zerg_xcode/objects/pbx_build_phase.rb +14 -2
  14. data/lib/zerg_xcode/objects/pbx_container_item_proxy.rb +14 -2
  15. data/lib/zerg_xcode/objects/pbx_group.rb +43 -3
  16. data/lib/zerg_xcode/objects/pbx_native_target.rb +15 -3
  17. data/lib/zerg_xcode/objects/pbx_project.rb +20 -4
  18. data/lib/zerg_xcode/objects/pbx_target_dependency.rb +15 -3
  19. data/lib/zerg_xcode/objects/xc_configuration_list.rb +14 -2
  20. data/lib/zerg_xcode/objects/xcode_object.rb +14 -3
  21. data/lib/zerg_xcode/plugins/addlibrary.rb +15 -2
  22. data/lib/zerg_xcode/plugins/core/core.rb +15 -6
  23. data/lib/zerg_xcode/plugins/help.rb +15 -2
  24. data/lib/zerg_xcode/plugins/import.rb +15 -2
  25. data/lib/zerg_xcode/plugins/irb.rb +16 -2
  26. data/lib/zerg_xcode/plugins/ls.rb +15 -2
  27. data/lib/zerg_xcode/plugins/lstargets.rb +16 -2
  28. data/lib/zerg_xcode/plugins/retarget.rb +15 -2
  29. data/lib/zerg_xcode/shortcuts.rb +10 -2
  30. data/test/builder/runner_test.rb +35 -0
  31. data/test/builder/sdk_test.rb +17 -0
  32. data/test/file_format/archiver_test.rb +6 -2
  33. data/test/file_format/encoder_test.rb +7 -3
  34. data/test/file_format/lexer_test.rb +7 -3
  35. data/test/file_format/parser_test.rb +6 -2
  36. data/test/file_format/path_test.rb +30 -24
  37. data/test/fixtures/ClosedLib/ClosedLib.xcodeproj/project.pbxproj +225 -0
  38. data/test/fixtures/ClosedLib/ClosedLib_Prefix.pch +7 -0
  39. data/test/fixtures/ClosedLib/ClosedNative.c +20 -0
  40. data/test/fixtures/ClosedLib/ClosedNative.h +12 -0
  41. data/{testdata → test/fixtures}/FlatTestApp/FlatTestApp.xcodeproj/project.pbxproj +0 -0
  42. data/{testdata → test/fixtures}/TestApp/TestApp.xcodeproj/project.pbxproj +0 -0
  43. data/{testdata → test/fixtures}/TestApp30.xcodeproj/project.pbxproj +0 -0
  44. data/{testdata → test/fixtures}/TestLib30.xcodeproj/project.pbxproj +0 -0
  45. data/{testdata → test/fixtures}/ZergSupport.xcodeproj/project.pbxproj +0 -0
  46. data/{testdata → test/fixtures}/project.pbxproj +0 -0
  47. data/{testdata → test/fixtures}/project.pbxproj.compat +0 -0
  48. data/test/objects/pbx_build_file_test.rb +7 -4
  49. data/test/objects/pbx_build_phase_test.rb +5 -2
  50. data/test/objects/pbx_container_item_proxy_test.rb +6 -2
  51. data/test/objects/pbx_group_test.rb +35 -3
  52. data/test/objects/pbx_native_target_test.rb +5 -2
  53. data/test/objects/pbx_project_test.rb +21 -9
  54. data/test/objects/pbx_target_dependency_test.rb +6 -2
  55. data/test/objects/xc_configuration_list_test.rb +5 -2
  56. data/test/objects/xcode_object_test.rb +5 -2
  57. data/test/plugins/addlibrary_test.rb +6 -3
  58. data/test/plugins/core/core_test.rb +5 -2
  59. data/test/plugins/helper.rb +4 -0
  60. data/test/plugins/import_test.rb +76 -72
  61. data/test/plugins/irb_test.rb +9 -4
  62. data/test/plugins/ls_test.rb +7 -4
  63. data/test/plugins/lstargets_test.rb +7 -4
  64. data/test/plugins/retarget_test.rb +7 -4
  65. data/test/shortcuts_test.rb +7 -3
  66. data/zerg_xcode.gemspec +6 -6
  67. metadata +32 -20
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.3.5. Under-the-hood functionality.
2
+
1
3
  v0.3.4. Removed warnings, improved tests.
2
4
 
3
5
  v0.3.3. Fixed wrong error message in addtarget.
data/Manifest CHANGED
@@ -1,5 +1,13 @@
1
- bin/zerg-xcode
2
1
  CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README.textile
5
+ RUBYFORGE
6
+ Rakefile
7
+ bin/zerg-xcode
8
+ lib/zerg_xcode.rb
9
+ lib/zerg_xcode/builder/runner.rb
10
+ lib/zerg_xcode/builder/sdks.rb
3
11
  lib/zerg_xcode/file_format/archiver.rb
4
12
  lib/zerg_xcode/file_format/encoder.rb
5
13
  lib/zerg_xcode/file_format/lexer.rb
@@ -23,17 +31,24 @@ lib/zerg_xcode/plugins/ls.rb
23
31
  lib/zerg_xcode/plugins/lstargets.rb
24
32
  lib/zerg_xcode/plugins/retarget.rb
25
33
  lib/zerg_xcode/shortcuts.rb
26
- lib/zerg_xcode.rb
27
- LICENSE
28
- Manifest
29
- Rakefile
30
- README.textile
31
- RUBYFORGE
34
+ test/builder/runner_test.rb
35
+ test/builder/sdk_test.rb
32
36
  test/file_format/archiver_test.rb
33
37
  test/file_format/encoder_test.rb
34
38
  test/file_format/lexer_test.rb
35
39
  test/file_format/parser_test.rb
36
40
  test/file_format/path_test.rb
41
+ test/fixtures/ClosedLib/ClosedLib.xcodeproj/project.pbxproj
42
+ test/fixtures/ClosedLib/ClosedLib_Prefix.pch
43
+ test/fixtures/ClosedLib/ClosedNative.c
44
+ test/fixtures/ClosedLib/ClosedNative.h
45
+ test/fixtures/FlatTestApp/FlatTestApp.xcodeproj/project.pbxproj
46
+ test/fixtures/TestApp/TestApp.xcodeproj/project.pbxproj
47
+ test/fixtures/TestApp30.xcodeproj/project.pbxproj
48
+ test/fixtures/TestLib30.xcodeproj/project.pbxproj
49
+ test/fixtures/ZergSupport.xcodeproj/project.pbxproj
50
+ test/fixtures/project.pbxproj
51
+ test/fixtures/project.pbxproj.compat
37
52
  test/objects/pbx_build_file_test.rb
38
53
  test/objects/pbx_build_phase_test.rb
39
54
  test/objects/pbx_container_item_proxy_test.rb
@@ -52,10 +67,3 @@ test/plugins/ls_test.rb
52
67
  test/plugins/lstargets_test.rb
53
68
  test/plugins/retarget_test.rb
54
69
  test/shortcuts_test.rb
55
- testdata/FlatTestApp/FlatTestApp.xcodeproj/project.pbxproj
56
- testdata/project.pbxproj
57
- testdata/project.pbxproj.compat
58
- testdata/TestApp/TestApp.xcodeproj/project.pbxproj
59
- testdata/TestApp30.xcodeproj/project.pbxproj
60
- testdata/TestLib30.xcodeproj/project.pbxproj
61
- testdata/ZergSupport.xcodeproj/project.pbxproj
data/Rakefile CHANGED
@@ -1,3 +1,9 @@
1
+ # Rakefile for the zerg_xcode gem.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
1
7
  require 'rubygems'
2
8
  require 'echoe'
3
9
 
data/lib/zerg_xcode.rb CHANGED
@@ -1,6 +1,8 @@
1
- module ZergXcode; end
2
- module ZergXcode::Objects; end
3
-
1
+ # Main include file for the zerg_xcode gem.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
4
6
 
5
7
  require 'zerg_xcode/file_format/archiver.rb'
6
8
  require 'zerg_xcode/file_format/encoder.rb'
@@ -8,6 +10,9 @@ require 'zerg_xcode/file_format/lexer.rb'
8
10
  require 'zerg_xcode/file_format/parser.rb'
9
11
  require 'zerg_xcode/file_format/paths.rb'
10
12
 
13
+ require 'zerg_xcode/builder/runner.rb'
14
+ require 'zerg_xcode/builder/sdks.rb'
15
+
11
16
  require 'zerg_xcode/objects/xcode_object.rb'
12
17
  require 'zerg_xcode/objects/pbx_build_file.rb'
13
18
  require 'zerg_xcode/objects/pbx_build_phase.rb'
@@ -0,0 +1,51 @@
1
+ # Runs the Xcode build process.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ require 'fileutils'
8
+
9
+ # :nodoc: namespace
10
+ module ZergXcode::Builder
11
+
12
+
13
+ # Runs the Xcode build process.
14
+ module Runner
15
+ # Builds an Xcode project.
16
+ #
17
+ # Returns the directory containing the build products, or nil if the build
18
+ # failed.
19
+ def self.build(project, sdk, configuration, options = {})
20
+ return nil unless action(project, sdk, configuration, options, 'build')
21
+ Dir.glob(File.join(project.root_path, 'build', configuration + '-*')).first
22
+ end
23
+
24
+ # Removes the build products for an Xcode project.
25
+ #
26
+ # Returns true for success, or false if the removal failed.
27
+ def self.clean(project, sdk, configuration, options = {})
28
+ return_value = action(project, sdk, configuration, options, 'clean')
29
+ FileUtils.rm_rf File.join(project.root_path, 'build')
30
+ return_value
31
+ end
32
+
33
+ # Executes an action using the Xcode builder.
34
+ #
35
+ # Returns true if the action suceeded, and false otherwise.
36
+ def self.action(project, sdk, configuration, options, verb)
37
+ # NOTE: not using -parallelizeTargets so the command line is less brittle,
38
+ # and to accomodate projects with bad dependencies
39
+ command = 'xcodebuild -project ' +
40
+ File.dirname(project.source_filename).inspect +
41
+ %Q| -sdk #{sdk[:arg]} -configuration #{configuration.inspect} | +
42
+ '-alltargets ' + options.map { "#{k}=#{v}".inspect }.join(' ') + ' ' +
43
+ verb.inspect + ' 2>&1'
44
+ begin
45
+ output = Kernel.`(command)
46
+ return (/\*\* .* SUCCEEDED \*\*/ =~ output) ? true : false
47
+ end
48
+ end
49
+ end # module ZergXcode::Builder::Sdk
50
+
51
+ end # namespace ZergXcode::Builder
@@ -0,0 +1,34 @@
1
+ # Logic for the multiple SDKs in an Xcode installation.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode::Builder
9
+
10
+
11
+ # Logic for the multiple SDKs in an Xcode installation.
12
+ module Sdk
13
+ @all = nil
14
+
15
+ # All the SDKs installed.
16
+ def self.all
17
+ return @all if @all
18
+
19
+ output = `xcodebuild -showsdks`
20
+ @all = []
21
+ group = ''
22
+ output.each_line do |line|
23
+ if line.index '-sdk '
24
+ name, arg = *line.split('-sdk ').map { |token| token.strip }
25
+ @all << { :group => group, :name => name, :arg => arg }
26
+ elsif line.index ':'
27
+ group = line.split(':').first.strip
28
+ end
29
+ end
30
+ @all
31
+ end
32
+ end # module ZergXcode::Builder::Sdk
33
+
34
+ end # namespace ZergXcode::Builder
@@ -1,4 +1,15 @@
1
- module ZergXcode::Archiver
1
+ # Logic for flattening and restoring PBX (Xcode project) object graphs.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode
9
+
10
+
11
+ # Flattens and restores PBX (Xcode project) object graphs.
12
+ module Archiver
2
13
  # Unarchives an Xcode object graph from the contents of a file.
3
14
  def self.unarchive(string)
4
15
  proj_hash = ZergXcode::Parser.parse string
@@ -84,4 +95,6 @@ module ZergXcode::Archiver
84
95
  end
85
96
  end
86
97
  end
87
- end
98
+ end # module ZergXcode::Archiver
99
+
100
+ end # namespace ZergXcode
@@ -1,4 +1,15 @@
1
- module ZergXcode::Encoder
1
+ # Logic for writing flattened object graphs to .pbxproj files.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode
9
+
10
+
11
+ # Writes flattened object graphs to .xcodeproj files.
12
+ module Encoder
2
13
  def self.encode(project)
3
14
  "// !$*UTF8*$!\n" + encode_hash(project, 0) + "\n"
4
15
  end
@@ -37,4 +48,6 @@ module ZergXcode::Encoder
37
48
  def self.encode_indentation(indentation)
38
49
  "\t" * indentation
39
50
  end
40
- end
51
+ end # module ZergXcode::Encoder
52
+
53
+ end # namespace ZergXcode
@@ -1,4 +1,15 @@
1
- module ZergXcode::Lexer
1
+ # Lexer for flattened object graphs stored in .pbxproj files.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode
9
+
10
+
11
+ # Lexer for flattened object graphs stored in .xcodeproj files.
12
+ module Lexer
2
13
  def self.tokenize(string)
3
14
 
4
15
  encoding_match = string.match(/^\/\/ \!\$\*(.*?)\*\$\!/)
@@ -57,4 +68,6 @@ module ZergXcode::Lexer
57
68
  end
58
69
  return tokens
59
70
  end
60
- end
71
+ end # module ZergXcode::Lexer
72
+
73
+ end # namespace ZergXcode
@@ -1,4 +1,15 @@
1
- module ZergXcode::Parser
1
+ # Parser for flattened object graphs stored in .pbxproj files.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode
9
+
10
+
11
+ # Parser for flattened object graphs stored in .xcodeproj files.
12
+ module Parser
2
13
  def self.parse(project_string)
3
14
  tokens = ZergXcode::Lexer.tokenize project_string
4
15
 
@@ -43,4 +54,6 @@ module ZergXcode::Parser
43
54
  end
44
55
  return context[0][0]
45
56
  end
46
- end
57
+ end # module ZergXcode::Parser
58
+
59
+ end # namespace ZergXcode
@@ -1,4 +1,15 @@
1
- module ZergXcode::Paths
1
+ # Xcode project path resolver.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode
9
+
10
+
11
+ # Finds the .pbxproj file inside an Xcode project.
12
+ module Paths
2
13
  # The most likely project file name for the given path.
3
14
  def self.project_file_at(base_path)
4
15
  return base_path if File.exist?(base_path) and File.file?(base_path)
@@ -41,4 +52,6 @@ module ZergXcode::Paths
41
52
  file = project_file_at base_path
42
53
  File.dirname File.dirname(file)
43
54
  end
44
- end
55
+ end # module ZergXcode::Paths
56
+
57
+ end # module ZergXcode
@@ -1,5 +1,15 @@
1
- # A file used for building. Points to a PBXFileRef.
2
- class ZergXcode::Objects::PBXBuildFile < ZergXcode::XcodeObject
1
+ # A build input.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode::Objects
9
+
10
+
11
+ # A build input. Points to a PBXFileRef.
12
+ class PBXBuildFile < ZergXcode::XcodeObject
3
13
  # The name of the referenced file.
4
14
  def filename
5
15
  self['fileRef']['path']
@@ -34,4 +44,7 @@ class ZergXcode::Objects::PBXBuildFile < ZergXcode::XcodeObject
34
44
  def xref_name
35
45
  self['fileRef'].xref_name
36
46
  end
37
- end
47
+ end # class ZergXcode::Objects:PBXBuildFile
48
+
49
+ end # namespace ZergXcode::Objects
50
+
@@ -1,12 +1,24 @@
1
+ # The superclass for all the phases of the Xcode build process.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode::Objects
9
+
10
+
1
11
  # Superclass for all the Xcode build phases.
2
12
  #
3
13
  # Subclasses include PBXHeadersBuildPhase, PBXSourcesBuildPhase,
4
14
  # PBXFrameworksBuildPhase, and PBXResourcesBuildPhase.
5
- class ZergXcode::Objects::PBXBuildPhase < ZergXcode::XcodeObject
15
+ class PBXBuildPhase < ZergXcode::XcodeObject
6
16
  # Creates a new build phase with the given isa type.
7
17
  def self.new_phase(isa_type)
8
18
  self.new 'isa' => isa_type.to_s, 'dependencies' => [], 'files' => [],
9
19
  'buildActionMask' => '2147483647',
10
20
  'runOnlyForDeploymentPostprocessing' => '0'
11
21
  end
12
- end
22
+ end # class ZergXcode::Objects::PBXBuildPhase
23
+
24
+ end # namespace ZergXcode::Objects
@@ -1,8 +1,18 @@
1
+ # Proxy for another Xcode object.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode::Objects
9
+
10
+
1
11
  # Proxy for another object.
2
12
  #
3
13
  # Unsure these are useful, since each object has an unique ID. They are probably
4
14
  # implementation artifacts.
5
- class ZergXcode::Objects::PBXContainerItemProxy < ZergXcode::XcodeObject
15
+ class PBXContainerItemProxy < ZergXcode::XcodeObject
6
16
  # The proxied object.
7
17
  def target
8
18
  self['remoteGlobalIDString']
@@ -20,4 +30,6 @@ class ZergXcode::Objects::PBXContainerItemProxy < ZergXcode::XcodeObject
20
30
  def xref_name
21
31
  self['remoteInfo']
22
32
  end
23
- end
33
+ end # class ZergXcode::Objects::PBXContainerItemProxy
34
+
35
+ end # namespace ZergXcode::Objects
@@ -1,3 +1,43 @@
1
- # A group of files.
2
- class ZergXcode::Objects::PBXGroup < ZergXcode::XcodeObject
3
- end
1
+ # A group of files (shown as a folder) in an Xcode project.
2
+ #
3
+ # Author:: Christopher Garrett
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode::Objects
9
+
10
+
11
+ # A group of files (shown as a folder) in an Xcode project.
12
+ class PBXGroup < ZergXcode::XcodeObject
13
+ def find_group_named(group_name)
14
+ self['children'].each do |child|
15
+ if child.isa == :PBXGroup
16
+ if child.xref_name == group_name
17
+ return child
18
+ elsif grandchild = child.find_group_named(group_name)
19
+ return grandchild
20
+ end
21
+ end
22
+ end
23
+ return nil
24
+ end
25
+
26
+ def children
27
+ self['children']
28
+ end
29
+
30
+ def create_group(path_name, group_name=nil, source_tree='<group>')
31
+ group_name = group_name || path_name
32
+ unless group = find_group_named(group_name)
33
+ group = ZergXcode::Objects::PBXGroup.new 'name' => group_name,
34
+ 'path' => path_name,
35
+ 'children' => [],
36
+ 'sourceTree' => source_tree
37
+ self.children << group
38
+ end
39
+ group
40
+ end
41
+ end # class ZergXcode::Objects::PBXGroup
42
+
43
+ end # namespace ZergXcode::Objects
@@ -1,5 +1,15 @@
1
- # An Xcode target.
2
- class ZergXcode::Objects::PBXNativeTarget < ZergXcode::XcodeObject
1
+ # An Xcode build target.
2
+ #
3
+ # Author:: Victor Costan
4
+ # Copyright:: Copyright (C) 2009 Zergling.Net
5
+ # License:: MIT
6
+
7
+ # :nodoc: namespace
8
+ module ZergXcode::Objects
9
+
10
+
11
+ # An Xcode build target.
12
+ class PBXNativeTarget < ZergXcode::XcodeObject
3
13
  # All the files referenced by this target.
4
14
  # Returns:
5
15
  # an array containing a hash for each file with
@@ -16,4 +26,6 @@ class ZergXcode::Objects::PBXNativeTarget < ZergXcode::XcodeObject
16
26
  end
17
27
  files
18
28
  end
19
- end
29
+ end # class ZergXcode::Objects::PBXNativeTarget
30
+
31
+ end # namespace class ZergXcode::Objects