Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Workspace] Support file reference types #150

Merged
merged 6 commits into from

2 participants

Kyle Fuller Fabio Pelosin
Kyle Fuller
Owner

The following types are supported by Xcode:

  • Absolute Path (absolute)
  • Relative to Group (group)
  • Relative to Workspace (container)
  • Relative to Developer Directory (developer)

Fixes #118

Kyle Fuller
Owner

Please look at this in extra detail because I don't remember why I didn't make a pull request already.

kylef and others added some commits
Kyle Fuller kylef [Workspace] Support file reference types
The following types are supported by Xcode:

- Absolute Path (absolute)
- Relative to Group (group)
- Relative to Workspace (container)
- Relative to Developer Directory (developer)
4222947
Fabio Pelosin fabiopelosin Merge branch 'master' into file_reference_type
* master: (38 commits)
  Release 0.16.1
  Fixed issue #147
  Support .ipp files as headers
  Release 0.16.0
  [Constants] Disable errors on warnings for default build settings
  Bump version to 0.15.3.
  [rake] Fix the gem buid and release tasks to include prebuilt binaries.
  Bump version to 0.15.2
  [CHANGELOG] Prepare for 0.15.2 release.
  Fix prebuilding on OS X 10.9's Ruby.
  Revert "[Ext] Remove -multiply_definedsuppress argument from prebuilt makefiles"
  Fix Apple's breakage to Ruby's build config.
  Revert "[Ext] Fix -multiply_definedsuppress argument for system Ruby"
  Release 0.15.1
  [Rakefile] Add title to build task
  [Ext] Fix -multiply_definedsuppress argument for system Ruby
  [Ext] Remove -multiply_definedsuppress argument from prebuilt makefiles
  [Rakefile] Adopt Rainforest & streamline
  Revert "Remove empty OTHER_LDFLAGS setting"
  Update README.md
  ...
6fbd2ee
Fabio Pelosin fabiopelosin [Workspace] Use dedicated file for FileReferences class f9b42c8
Fabio Pelosin fabiopelosin [Workspace] Minor editing to FileReference class 1e4fb98
Fabio Pelosin fabiopelosin [Workspace] Minor editing to FileReference class 2 526891b
Fabio Pelosin fabiopelosin [Workspace::FileReference] Fix equality comparison 1a034fc
Fabio Pelosin

@kylef 1a034fc might be of interest to you.

Fabio Pelosin fabiopelosin merged commit 60c297e into from
Fabio Pelosin fabiopelosin deleted the branch
Fabio Pelosin fabiopelosin referenced this pull request in CocoaPods/CocoaPods
Closed

Move Podfile to the workspace #2063

Kyle Fuller
Owner

Nice, thanks @irrationalfab :beers:. I had no idea how to do that :)

Kyle Fuller
Owner

And thanks for cleaning this up :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 15, 2014
  1. Kyle Fuller

    [Workspace] Support file reference types

    kylef authored
    The following types are supported by Xcode:
    
    - Absolute Path (absolute)
    - Relative to Group (group)
    - Relative to Workspace (container)
    - Relative to Developer Directory (developer)
Commits on Apr 17, 2014
  1. Fabio Pelosin

    Merge branch 'master' into file_reference_type

    fabiopelosin authored
    * master: (38 commits)
      Release 0.16.1
      Fixed issue #147
      Support .ipp files as headers
      Release 0.16.0
      [Constants] Disable errors on warnings for default build settings
      Bump version to 0.15.3.
      [rake] Fix the gem buid and release tasks to include prebuilt binaries.
      Bump version to 0.15.2
      [CHANGELOG] Prepare for 0.15.2 release.
      Fix prebuilding on OS X 10.9's Ruby.
      Revert "[Ext] Remove -multiply_definedsuppress argument from prebuilt makefiles"
      Fix Apple's breakage to Ruby's build config.
      Revert "[Ext] Fix -multiply_definedsuppress argument for system Ruby"
      Release 0.15.1
      [Rakefile] Add title to build task
      [Ext] Fix -multiply_definedsuppress argument for system Ruby
      [Ext] Remove -multiply_definedsuppress argument from prebuilt makefiles
      [Rakefile] Adopt Rainforest & streamline
      Revert "Remove empty OTHER_LDFLAGS setting"
      Update README.md
      ...
  2. Fabio Pelosin
  3. Fabio Pelosin
  4. Fabio Pelosin
  5. Fabio Pelosin
This page is out of date. Refresh to see the latest.
6 CHANGELOG.md
View
@@ -66,6 +66,12 @@
## 0.14.1
+###### Enhancements
+
+* Add support for absolute, group and container project references in workspaces
+ [Kyle Fuller](https://github.com/kylef)
+ [#118](https://github.com/CocoaPods/Xcodeproj/issues/118)
+
###### Bug Fixes
* [Gem] On MRI 1.8.7 /dev/tty is considered writable when not configured,
41 lib/xcodeproj/workspace.rb
View
@@ -1,5 +1,6 @@
require 'fileutils'
require 'rexml/document'
+require 'xcodeproj/workspace/file_reference'
module Xcodeproj
@@ -9,15 +10,16 @@ module Xcodeproj
class Workspace
# @return [Array<String>] the paths of the projects contained in the
+ # @return [Array<FileReference>] the paths of the projects contained in the
# workspace.
#
- attr_reader :projpaths
+ attr_reader :file_references
attr_reader :schemes
- # @param [Array] projpaths @see projpaths
+ # @param [Array] file_references @see file_references
#
- def initialize(*projpaths)
- @projpaths = projpaths.flatten
+ def initialize(*file_references)
+ @file_references = file_references.flatten
@schemes = {}
end
@@ -50,10 +52,10 @@ def self.new_from_xcworkspace(path)
#
def self.from_s(xml, workspace_path='')
document = REXML::Document.new(xml)
- projpaths = document.get_elements("/Workspace/FileRef").map do |node|
- node.attribute("location").value.sub(/^group:/, '')
+ file_references = document.get_elements("/Workspace/FileRef").map do |node|
+ FileReference.from_node(node)
end
- instance = new(projpaths)
+ instance = new(file_references)
instance.load_schemes(workspace_path)
instance
end
@@ -69,19 +71,20 @@ def self.from_s(xml, workspace_path='')
# @return [void]
#
def <<(projpath)
- @projpaths << projpath
+ @file_references << projpath
load_schemes_from_project File.expand_path(projpath)
end
- # Checks if the workspace contains the project with the given path.
+ # Checks if the workspace contains the project with the given file
+ # reference.
#
- # @param [String] projpath
- # The path of the project to add.
+ # @param [FileReference] file_reference
+ # The file_reference to the project.
#
# @return [Boolean] whether the project is contained in the workspace.
#
- def include?(projpath)
- @projpaths.include?(projpath)
+ def include?(file_reference)
+ @file_references.include?(file_reference)
end
# The template to generate a workspace XML representation.
@@ -92,10 +95,8 @@ def include?(projpath)
#
def to_s
REXML::Document.new(TEMPLATE).tap do |document|
- @projpaths.each do |projpath|
- document.root << REXML::Element.new("FileRef").tap do |el|
- el.attributes['location'] = "group:#{projpath}"
- end
+ @file_references.each do |file_reference|
+ document.root << file_reference.to_node
end
end.to_s
end
@@ -124,9 +125,9 @@ def save_as(path)
# @return [void]
#
def load_schemes workspace_dir_path
- @projpaths.each do |projpath|
- project_full_path = File.expand_path(File.join(workspace_dir_path, projpath))
- load_schemes_from_project project_full_path
+ @file_references.each do |file_reference|
+ project_full_path = file_reference.absolute_path(workspace_dir_path)
+ load_schemes_from_project(project_full_path)
end
end
87 lib/xcodeproj/workspace/file_reference.rb
View
@@ -0,0 +1,87 @@
+module Xcodeproj
+ class Workspace
+ # Describes a file reference of a Workspace.
+ #
+ class FileReference
+ # @return [String] the path to the project
+ #
+ attr_reader :path
+
+ # @return [String] the type of reference to the project
+ #
+ # This can be of the following values:
+ # - absolute
+ # - group
+ # - container
+ # - developer (unsupported)
+ #
+ attr_reader :type
+
+ # @param [#to_s] path @see path
+ # @param [#to_s] type @see type
+ #
+ def initialize(path, type="group")
+ @path = path.to_s
+ @type = type.to_s
+ end
+
+ # @return [Bool] Wether a file reference is equal to another.
+ #
+ def ==(other)
+ path == other.path && type == other.type
+ end
+ alias_method :eql?, :==
+
+ # @return [Fixnum] A hash identical for equals objects.
+ #
+ def hash
+ [path, type].hash
+ end
+
+ # Returns a file reference given XML representation.
+ #
+ # @param [REXML::Element] xml_node
+ # the XML representation.
+ #
+ # @return [FileReference] The new file reference instance.
+ #
+ def self.from_node(xml_node)
+ type, path = xml_node.attribute('location').value.split(':', 2)
+ new(path, type)
+ end
+
+ # @return [REXML::Element] the XML representation of the file reference.
+ #
+ def to_node
+ REXML::Element.new("FileRef").tap do |element|
+ element.attributes['location'] = "#{type}:#{path}"
+ end
+ end
+
+ # Returns the absolute path of a file reference given the path of the
+ # directory containing workspace.
+ #
+ # @param [#to_s] workspace_dir_path
+ # The Path of the directory containing the workspace.
+ #
+ # @return [String] The absolute path to the project.
+ #
+ def absolute_path(workspace_dir_path)
+ workspace_dir_path = workspace_dir_path.to_s
+ case type
+ when 'group'
+ File.expand_path(File.join(workspace_dir_path, path))
+ when 'container'
+ File.expand_path(File.join(workspace_dir_path, path))
+ when 'absolute'
+ File.expand_path(path)
+ when 'developer'
+ raise "Developer workspace file reference type is not yet " \
+ "#{self}"
+ else
+ raise "Unsupported workspace file reference type #{type}"
+ end
+ end
+ end
+ end
+end
50 spec/workspace/file_reference_spec.rb
View
@@ -0,0 +1,50 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+module Xcodeproj
+ describe Workspace do
+ before do
+ @subject = Workspace::FileReference.new('project.xcodeproj', 'group')
+ end
+
+ it 'properly implements equality comparison' do
+ @subject.should == @subject.dup
+ @subject.should.eql @subject.dup
+ @subject.hash.should == @subject.dup.hash
+ end
+
+ it 'can be initialized by the XML representation' do
+ node = REXML::Element.new("FileRef")
+ node.attributes['location'] = "group:project.xcodeproj"
+ result = Workspace::FileReference.from_node(node)
+ result.should == @subject
+ end
+
+ it 'returns the XML representation' do
+ result = @subject.to_node
+ result.class.should == REXML::Element
+ result.to_s.should == "<FileRef location='group:project.xcodeproj'/>"
+ end
+
+ it 'can be converted back and forth without loss of information' do
+ result = Workspace::FileReference.from_node(@subject.to_node)
+ result.should == @subject
+ end
+
+ it 'returns the absolute path for group types' do
+ result = @subject.absolute_path('/path/to/')
+ result.should == "/path/to/project.xcodeproj"
+ end
+
+ it 'returns the absolute path for container types' do
+ @subject.stubs(:type).returns('container')
+ result = @subject.absolute_path('/path/to/')
+ result.should == "/path/to/project.xcodeproj"
+ end
+
+ it 'returns the absolute path for absolute types' do
+ @subject.stubs(:type).returns('absolute')
+ result = @subject.absolute_path('/path/to/')
+ result.should == File.expand_path(@subject.path)
+ end
+ end
+end
34 spec/workspace_spec.rb
View
@@ -1,6 +1,6 @@
require File.expand_path('../spec_helper', __FILE__)
-describe "Xcodeproj::Workspace" do
+describe Xcodeproj::Workspace do
describe "from new" do
before do
@workspace = Xcodeproj::Workspace.new('Pods/Pods.xcodeproj', 'App.xcodeproj')
@@ -8,13 +8,15 @@
it "accepts new projects" do
@workspace << 'Framework.xcodeproj'
- @workspace.projpaths.should.include 'Framework.xcodeproj'
+ @workspace.file_references.should.include 'Framework.xcodeproj'
end
end
describe "converted to XML" do
before do
- @workspace = Xcodeproj::Workspace.new('Pods/Pods.xcodeproj', 'App.xcodeproj')
+ pods_project_file_reference = Xcodeproj::Workspace::FileReference.new('Pods/Pods.xcodeproj')
+ project_file_reference = Xcodeproj::Workspace::FileReference.new('App.xcodeproj')
+ @workspace = Xcodeproj::Workspace.new(pods_project_file_reference, project_file_reference)
@doc = REXML::Document.new(@workspace.to_s)
end
@@ -35,9 +37,9 @@
end
it "contains all of the projects in the workspace" do
- @workspace.projpaths.should.include "libPusher.xcodeproj"
- @workspace.projpaths.should.include "libPusher-OSX/libPusher-OSX.xcodeproj"
- @workspace.projpaths.should.include "Pods/Pods.xcodeproj"
+ @workspace.file_references.should.include Xcodeproj::Workspace::FileReference.new("libPusher.xcodeproj")
+ @workspace.file_references.should.include Xcodeproj::Workspace::FileReference.new("libPusher-OSX/libPusher-OSX.xcodeproj")
+ @workspace.file_references.should.include Xcodeproj::Workspace::FileReference.new("Pods/Pods.xcodeproj")
end
end
@@ -47,36 +49,36 @@
end
it "contains no projects" do
- @workspace.projpaths.should.be.empty
+ @workspace.file_references.should.be.empty
end
end
-
+
describe "load schemes for all projects from workspace file" do
before do
@workspace = Xcodeproj::Workspace.new_from_xcworkspace(fixture_path("SharedSchemes/SharedSchemes.xcworkspace"))
end
-
+
it "returns data type should be hash" do
@workspace.schemes.should.instance_of Hash
end
-
- it "schemes count should be greater or equal to projpaths count" do
- @workspace.schemes.count.should >= @workspace.projpaths.count
+
+ it "schemes count should be greater or equal to file_references count" do
+ @workspace.schemes.count.should >= @workspace.file_references.count
end
-
+
it "contains only test data schemes" do
@workspace.schemes.keys.sort.should == ['Pods', 'SharedSchemes', 'SharedSchemesForTest']
end
end
-
+
describe "built from a workspace file with XML entities in a project path" do
before do
@workspace = Xcodeproj::Workspace.new_from_xcworkspace(fixture_path("Otto's Remote.xcworkspace"))
end
it "contains all of the projects in the workspace" do
- @workspace.projpaths.should.include "Otto's Remote.xcodeproj"
- @workspace.projpaths.should.include "Pods/Pods.xcodeproj"
+ @workspace.file_references.should.include Xcodeproj::Workspace::FileReference.new("Otto's Remote.xcodeproj")
+ @workspace.file_references.should.include Xcodeproj::Workspace::FileReference.new("Pods/Pods.xcodeproj")
end
end
end
Something went wrong with that request. Please try again.