Class: Pod::Project

Inherits:
Xcodeproj::Project
  • Object
show all
Defined in:
lib/cocoapods/project.rb

Overview

The Pods project.

Model class which provides helpers for working with the Pods project through the installation process.

Legacy Xcode build root collapse

LEGACY_BUILD_ROOT =

————————————————————————-#

'${SRCROOT}/../build'

Pod Groups collapse

SPEC_SUBGROUPS =
{
  :resources  => 'Resources',
  :frameworks => 'Frameworks',
}

Instance Attribute Summary collapse

Legacy Xcode build root collapse

Pod Groups collapse

File references collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, skip_initialization = false, object_version = Xcodeproj::Constants::DEFAULT_OBJECT_VERSION) ⇒ Project

Initialize a new instance



18
19
20
21
22
23
24
25
26
# File 'lib/cocoapods/project.rb', line 18

def initialize(path, skip_initialization = false,
    object_version = Xcodeproj::Constants::DEFAULT_OBJECT_VERSION)
  super(path, skip_initialization, object_version)
  @support_files_group = new_group('Targets Support Files')
  @refs_by_absolute_path = {}
  @pods = new_group('Pods')
  @development_pods = new_group('Development Pods')
  self.symroot = LEGACY_BUILD_ROOT
end

Instance Attribute Details

#development_podsPBXGroup (readonly)



39
40
41
# File 'lib/cocoapods/project.rb', line 39

def development_pods
  @development_pods
end

#podsPBXGroup (readonly)



35
36
37
# File 'lib/cocoapods/project.rb', line 35

def pods
  @pods
end

#support_files_groupPBXGroup (readonly)



31
32
33
# File 'lib/cocoapods/project.rb', line 31

def support_files_group
  @support_files_group
end

Instance Method Details

#add_build_configuration(name, type) ⇒ XCBuildConfiguration

Note:

This method extends the original Xcodeproj implementation to include a preprocessor definition named after the build setting. This is done to support the TargetEnvironmentHeader specification of Pods available only on certain build configurations.

Adds a new build configuration to the project and populates it with default settings according to the provided type.



251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/cocoapods/project.rb', line 251

def add_build_configuration(name, type)
  build_configuration = super
  values = ["#{name.gsub(/[^a-zA-Z0-9_]/, '_').sub(/(^[0-9])/, '_\1').upcase}=1"]
  settings = build_configuration.build_settings
  definitions = Array(settings['GCC_PREPROCESSOR_DEFINITIONS'])
  values.each do |value|
    unless definitions.include?(value)
      definitions << value
    end
  end
  settings['GCC_PREPROCESSOR_DEFINITIONS'] = definitions
  build_configuration
end

#add_file_reference(absolute_path, group, reflect_file_system_structure = false) ⇒ PBXFileReference

Adds a file reference to given path as a child of the given group.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/cocoapods/project.rb', line 180

def add_file_reference(absolute_path, group, reflect_file_system_structure = false)
  file_path_name = Pathname.new(absolute_path)
  unless file_path_name.absolute?
    raise ArgumentError, "Paths must be absolute #{absolute_path}"
  end

  if reflect_file_system_structure
    relative_path = file_path_name.relative_path_from(group.real_path)
    relative_dir = relative_path.dirname
    relative_dir.each_filename do|name|
      next if name == '.'
      group = group[name] || group.new_group(name, name)
    end
  end

  if ref = reference_for_path(absolute_path)
    ref
  else
    ref = group.new_file(absolute_path)
    @refs_by_absolute_path[absolute_path.to_s] = ref
  end
end

#add_pod_group(pod_name, path, development = false, absolute = false) ⇒ PBXGroup

Creates a new group for the Pod with the given name and configures its path.



82
83
84
85
86
87
88
89
90
# File 'lib/cocoapods/project.rb', line 82

def add_pod_group(pod_name, path, development = false, absolute = false)
  raise '[BUG]' if pod_group(pod_name)

  parent_group = development ? development_pods : pods
  source_tree = absolute ? :absolute : :group

  group = parent_group.new_group(pod_name, path, source_tree)
  group
end

#add_podfile(podfile_path) ⇒ PBXFileReference

Adds a file reference to the Podfile.



226
227
228
229
230
231
# File 'lib/cocoapods/project.rb', line 226

def add_podfile(podfile_path)
  podfile_ref = new_file(podfile_path, :project)
  podfile_ref.xc_language_specification_identifier = 'xcode.lang.ruby'
  podfile_ref.last_known_file_type = 'text'
  podfile_ref
end

#group_for_spec(spec_name, subgroup_key = nil) ⇒ PBXGroup

Returns the group for the specification with the give name creating it if needed.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cocoapods/project.rb', line 124

def group_for_spec(spec_name, subgroup_key = nil)
  pod_name = Specification.root_name(spec_name)
  group = pod_group(pod_name)
  raise "[Bug] Unable to locate group for Pod named `#{pod_name}`" unless group
  if spec_name != pod_name
    subspecs_names = spec_name.gsub(pod_name + '/', '').split('/')
    subspecs_names.each do |name|
      group = group[name] || group.new_group(name)
    end
  end

  if subgroup_key
    subgroup_name = SPEC_SUBGROUPS[subgroup_key]
    raise ArgumentError, "Unrecognized subgroup key `#{subgroup_key}`" unless subgroup_name
    group = group[subgroup_name] || group.new_group(subgroup_name)
  end

  group
end

#pod_group(pod_name) ⇒ PBXGroup

Returns the group for the Pod with the given name.



105
106
107
# File 'lib/cocoapods/project.rb', line 105

def pod_group(pod_name)
  pod_groups.find { |group| group.name == pod_name }
end

#pod_groupsArray<PBXGroup>



94
95
96
# File 'lib/cocoapods/project.rb', line 94

def pod_groups
  pods.children.objects + development_pods.children.objects
end

#pod_support_files_group(pod_name, dir) ⇒ PBXGroup

Returns the support files group for the Pod with the given name.



151
152
153
154
155
156
157
158
# File 'lib/cocoapods/project.rb', line 151

def pod_support_files_group(pod_name, dir)
  group = pod_group(pod_name)
  support_files_group = group['Support Files']
  unless support_files_group
    support_files_group = group.new_group('Support Files', dir)
  end
  support_files_group
end

#reference_for_path(absolute_path) ⇒ PBXFileReference, Nil

Returns the file reference for the given absolute path.



211
212
213
214
215
216
217
# File 'lib/cocoapods/project.rb', line 211

def reference_for_path(absolute_path)
  unless Pathname.new(absolute_path).absolute?
    raise ArgumentError, "Paths must be absolute #{absolute_path}"
  end

  refs_by_absolute_path[absolute_path.to_s]
end

#symroot=(symroot) ⇒ void



54
55
56
57
58
# File 'lib/cocoapods/project.rb', line 54

def symroot=(symroot)
  root_object.build_configuration_list.build_configurations.each do |config|
    config.build_settings['SYMROOT'] = symroot
  end
end