Class: Xcake::Xcode::Project

Inherits:
Xcodeproj::Project show all
Defined in:
lib/xcake/xcode/project.rb

Overview

Special subclass of the Xcodeproj::Project which adds capabilities and helper methods xcake need

Instance Method Summary collapse

Instance Method Details

#attributesHash

Returns the attributes of the project.

Returns:

  • (Hash)

    the attributes of the project



12
13
14
# File 'lib/xcake/xcode/project.rb', line 12

def attributes
  root_object.attributes
end

#class_prefixString

Returns the class name for the project.

Returns:

  • (String)

    the class name for the project



18
19
20
# File 'lib/xcake/xcode/project.rb', line 18

def class_prefix
  attributes['CLASSPREFIX']
end

#class_prefix=(class_prefix) ⇒ String

Sets the class prefix for the project

Parameters:

Returns:

  • (String)

    the class name for the project



28
29
30
# File 'lib/xcake/xcode/project.rb', line 28

def class_prefix=(class_prefix)
  attributes['CLASSPREFIX'] = class_prefix
end

#file_reference_for_path(path) ⇒ PBXFileReference

Creates a new xcode file reference for a path

=> path of the file reference from the source root

Parameters:

  • path (Pathname)

Returns:

  • (PBXFileReference)

    new xcode file refrence



116
117
118
119
120
121
122
123
124
125
# File 'lib/xcake/xcode/project.rb', line 116

def file_reference_for_path(path)
  group = group_for_file_reference_path(path)
  group_path = Pathname.new group.dirname
  file_path = path.cleanpath.relative_path_from group_path

  ref = group.find_file_by_path file_path.to_s
  return ref if ref

  group.new_reference(file_path.to_s)
end

#find_unit_test_target_for_target(target) ⇒ Target

Finds a unit test target for a xcode target

Parameters:

  • target (Target)

    target to find a xcode target for.

Returns:

  • (Target)

    unit test target



188
189
190
191
192
# File 'lib/xcake/xcode/project.rb', line 188

def find_unit_test_target_for_target(target)
  targets.find do |t|
    t.name == "#{target.name}Tests"
  end
end

#group_for_file_reference_path(path) ⇒ PBXGroup

Finds or Creates a new xcode group for a path

=> path of the group from the source root

Parameters:

  • path (Pathname)

Returns:

  • (PBXGroup)

    existing or new xcode group



134
135
136
137
138
139
# File 'lib/xcake/xcode/project.rb', line 134

def group_for_file_reference_path(path)
  clean_path = path.cleanpath
  group = variant_group_for_path(path)
  group = group_for_path(path) unless group
  group
end

#group_for_path(path) ⇒ Object (private)



172
173
174
175
176
177
# File 'lib/xcake/xcode/project.rb', line 172

def group_for_path(path)
  group_path = path.dirname.cleanpath

  return main_group unless group_path.to_s != '.'
  main_group.child_for_path(group_path.to_s)
end

#new_configuration(_configuration) ⇒ Configurarion

Creates a new xcode configuration from the configuration DSL

Parameters:

  • configuration (Configurarion)

    configuration DSL to create target from

Returns:

  • (Configurarion)

    new xcode configuration



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

def new_configuration(_configuration)
  new(Xcodeproj::Project::Object::XCBuildConfiguration)
end

#new_target(target) ⇒ Target

Creates a new xcode target from the target DSL

Parameters:

  • target (Target)

    target DSL to create target from

Returns:

  • (Target)

    new xcode target



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/xcake/xcode/project.rb', line 77

def new_target(target)
  native_target = new(Xcodeproj::Project::Object::PBXNativeTarget)
  native_target.name = target.name
  native_target.product_name = target.name

  case target.type
  when Symbol
    native_target.product_type = Xcodeproj::Constants::PRODUCT_TYPE_UTI[target.type]
  when String
    native_target.product_type = target.type
  end

  native_target.build_configuration_list = new(Xcodeproj::Project::Object::XCConfigurationList)

  product = products_group.new_product_ref_for_target(native_target.product_name, native_target.product_type)
  native_target.product_reference = product

  targets << native_target
  native_target
end

#object_versionObject



48
49
50
# File 'lib/xcake/xcode/project.rb', line 48

def object_version
  Xcodeproj::Constants::DEFAULT_OBJECT_VERSION.to_s
end

#organizationString

Returns the organization for the project.

Returns:

  • (String)

    the organization for the project



34
35
36
# File 'lib/xcake/xcode/project.rb', line 34

def organization
  attributes['ORGANIZATIONNAME']
end

#organization=(organization) ⇒ SchemeList

Sets the organization for the project

Parameters:

Returns:

  • (SchemeList)

    the organization for the project



44
45
46
# File 'lib/xcake/xcode/project.rb', line 44

def organization=(organization)
  attributes['ORGANIZATIONNAME'] = organization
end

#setup_for_xcakeObject

Configures the Project for use with Xcake. This makes sure we have sensible defaults and it as clean as possible.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/xcake/xcode/project.rb', line 56

def setup_for_xcake
  root_object.remove_referrer(self) if root_object
  root_object = new(Project::Object::PBXProject)
  root_object.add_referrer(self)

  config_list = new(XCConfigurationList)
  root_object.build_configuration_list = config_list

  root_object.main_group = new(PBXGroup)
  root_object.product_ref_group = root_object.main_group.new_group('Products')

  @root_object = root_object
end

#variant_group_for_path(path) ⇒ PBXVariantGroup (private)

Note:

this method will return nil if the path isn't a valid

Creates or finds a new xcode variant group for a path

variant group path

=> path of the variant group from the source root

Parameters:

  • path (Pathname)

Returns:

  • (PBXVariantGroup)

    existing or new xcode variant group



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/xcake/xcode/project.rb', line 153

def variant_group_for_path(path)
  group_path = path.dirname.cleanpath
  base_name = group_path.basename

  return nil unless base_name.to_s.include?('.lproj')
  parent_group = group_for_path(group_path)

  group = parent_group[path.basename.to_s]

  unless group
    group = new(PBXVariantGroup)
    group.name = path.basename.to_s
    group.set_source_tree(:group)
    parent_group.children << group
  end

  group
end