Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
bf963342
Commit
bf963342
authored
Oct 29, 2011
by
Eloy Duran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor a bit by introducing has_one and has_many association macros.
parent
694a7047
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
57 deletions
+108
-57
project.rb
lib/cocoapods/xcode/project.rb
+60
-57
project_spec.rb
spec/unit/xcode/project_spec.rb
+48
-0
No files found.
lib/cocoapods/xcode/project.rb
View file @
bf963342
...
@@ -5,11 +5,36 @@ module Pod
...
@@ -5,11 +5,36 @@ module Pod
module
Xcode
module
Xcode
class
Project
class
Project
class
PBXObject
class
PBXObject
def
self
.
attributes_accessor
(
*
names
)
def
self
.
attribute
(
attribute_name
,
accessor_name
=
nil
)
names
.
each
do
|
name
|
attribute_name
=
attribute_name
.
to_s
name
=
name
.
to_s
name
=
(
accessor_name
||
attribute_name
).
to_s
define_method
(
name
)
{
@attributes
[
name
]
}
define_method
(
name
)
{
@attributes
[
attribute_name
]
}
define_method
(
"
#{
name
}
="
)
{
|
value
|
@attributes
[
name
]
=
value
}
define_method
(
"
#{
name
}
="
)
{
|
value
|
@attributes
[
attribute_name
]
=
value
}
end
def
self
.
has_many
(
plural_attr_name
,
options
)
klass
=
options
[
:class
]
singular_attr_name
=
plural_attr_name
.
to_s
[
0
..-
2
]
# strip off 's'
uuid_list_name
=
"
#{
singular_attr_name
}
UUIDs"
attribute
(
plural_attr_name
,
uuid_list_name
)
define_method
(
plural_attr_name
)
do
uuids
=
send
(
uuid_list_name
)
list_by_class
(
uuids
,
klass
)
end
define_method
(
"
#{
plural_attr_name
}
="
)
do
|
objects
|
send
(
"
#{
uuid_list_name
}
="
,
objects
.
map
(
&
:uuid
))
end
end
def
self
.
has_one
(
singular_attr_name
,
options
=
{})
uuid_name
=
options
[
:uuid
]
||
"
#{
singular_attr_name
}
UUID"
# TODO change UUID to Reference?
attribute
(
options
[
:uuid
]
||
singular_attr_name
,
uuid_name
)
define_method
(
singular_attr_name
)
do
uuid
=
send
(
uuid_name
)
@project
.
objects
[
uuid
]
end
define_method
(
"
#{
singular_attr_name
}
="
)
do
|
object
|
send
(
"
#{
uuid_name
}
="
,
object
.
uuid
)
end
end
end
end
...
@@ -18,7 +43,8 @@ module Pod
...
@@ -18,7 +43,8 @@ module Pod
end
end
attr_reader
:uuid
,
:attributes
attr_reader
:uuid
,
:attributes
attributes_accessor
:isa
,
:name
attribute
:isa
attribute
:name
def
initialize
(
project
,
uuid
,
attributes
)
def
initialize
(
project
,
uuid
,
attributes
)
@project
,
@uuid
,
@attributes
=
project
,
uuid
||
generate_uuid
,
attributes
@project
,
@uuid
,
@attributes
=
project
,
uuid
||
generate_uuid
,
attributes
...
@@ -52,7 +78,8 @@ module Pod
...
@@ -52,7 +78,8 @@ module Pod
end
end
class
PBXGroup
<
PBXObject
class
PBXGroup
<
PBXObject
attributes_accessor
:sourceTree
,
:children
attribute
:sourceTree
attribute
:children
def
initialize
(
project
,
uuid
,
attributes
)
def
initialize
(
project
,
uuid
,
attributes
)
super
super
...
@@ -95,7 +122,8 @@ module Pod
...
@@ -95,7 +122,8 @@ module Pod
end
end
class
PBXFileReference
<
PBXObject
class
PBXFileReference
<
PBXObject
attributes_accessor
:path
,
:sourceTree
attribute
:path
attribute
:sourceTree
def
initialize
(
project
,
uuid
,
attributes
)
def
initialize
(
project
,
uuid
,
attributes
)
is_new
=
uuid
.
nil?
is_new
=
uuid
.
nil?
...
@@ -117,7 +145,8 @@ module Pod
...
@@ -117,7 +145,8 @@ module Pod
end
end
class
PBXBuildFile
<
PBXObject
class
PBXBuildFile
<
PBXObject
attributes_accessor
:fileRef
,
:settings
attribute
:fileRef
attribute
:settings
# Takes a PBXFileReference instance and assigns its uuid to the fileRef attribute.
# Takes a PBXFileReference instance and assigns its uuid to the fileRef attribute.
def
file
=
(
file
)
def
file
=
(
file
)
...
@@ -131,25 +160,23 @@ module Pod
...
@@ -131,25 +160,23 @@ module Pod
end
end
class
PBXBuildPhase
<
PBXObject
class
PBXBuildPhase
<
PBXObject
attributes_accessor
:files
,
:buildActionMask
,
:runOnlyForDeploymentPostprocessing
has_many
:files
,
:class
=>
PBXBuildFile
alias_method
:file_uuids
,
:files
alias_method
:file_uuids
=
,
:files
=
attribute
:buildActionMask
attribute
:runOnlyForDeploymentPostprocessing
def
initialize
(
*
)
def
initialize
(
*
)
super
super
self
.
file
_uuid
s
||=
[]
self
.
file
UUID
s
||=
[]
# These are always the same, no idea what they are.
# These are always the same, no idea what they are.
self
.
buildActionMask
||=
"2147483647"
self
.
buildActionMask
||=
"2147483647"
self
.
runOnlyForDeploymentPostprocessing
||=
"0"
self
.
runOnlyForDeploymentPostprocessing
||=
"0"
end
end
def
files
list_by_class
(
file_uuids
,
PBXBuildFile
)
end
end
end
class
PBXCopyFilesBuildPhase
<
PBXBuildPhase
class
PBXCopyFilesBuildPhase
<
PBXBuildPhase
attributes_accessor
:dstPath
,
:dstSubfolderSpec
attribute
:dstPath
attribute
:dstSubfolderSpec
def
initialize
(
*
)
def
initialize
(
*
)
super
super
...
@@ -160,62 +187,38 @@ module Pod
...
@@ -160,62 +187,38 @@ module Pod
class
PBXSourcesBuildPhase
<
PBXBuildPhase
;
end
class
PBXSourcesBuildPhase
<
PBXBuildPhase
;
end
class
PBXFrameworksBuildPhase
<
PBXBuildPhase
;
end
class
PBXFrameworksBuildPhase
<
PBXBuildPhase
;
end
class
PBXShellScriptBuildPhase
<
PBXBuildPhase
class
PBXShellScriptBuildPhase
<
PBXBuildPhase
attribute
s_accessor
:shellScript
attribute
:shellScript
end
end
class
PBXNativeTarget
<
PBXObject
class
PBXNativeTarget
<
PBXObject
attributes_accessor
:productName
,
:productReference
,
:productType
,
:buildPhases
,
:buildRules
,
:dependencies
,
:buildConfigurationList
attribute
:productName
alias_method
:build_phase_uuids
,
:buildPhases
attribute
:productReference
alias_method
:build_phase_uuids
=
,
:buildPhases
=
attribute
:productType
alias_method
:build_configuration_list_uuid
,
:buildConfigurationList
attribute
:buildRules
alias_method
:build_configuration_list_uuid
=
,
:buildConfigurationList
=
attribute
:dependencies
has_many
:buildPhases
,
:class
=>
PBXBuildPhase
has_one
:buildConfigurationList
def
initialize
(
project
,
uuid
,
attributes
)
def
initialize
(
project
,
uuid
,
attributes
)
super
super
self
.
buildPhases
||=
[]
self
.
buildPhase
UUID
s
||=
[]
# TODO self.buildConfigurationList ||= new list?
# TODO self.buildConfigurationList ||= new list?
#self.buildRules ||= []
#self.buildRules ||= []
#self.dependencies ||= []
#self.dependencies ||= []
end
end
def
buildPhases
list_by_class
(
build_phase_uuids
,
PBXBuildPhase
)
end
def
buildConfigurationList
@project
.
objects
[
build_configuration_list_uuid
]
end
def
buildConfigurationList
=
(
config_list
)
self
.
build_configuration_list_uuid
=
config_list
.
uuid
end
end
end
class
XCBuildConfiguration
<
PBXObject
class
XCBuildConfiguration
<
PBXObject
attributes_accessor
:baseConfigurationReference
has_one
:baseConfiguration
,
:uuid
=>
:baseConfigurationReference
alias_method
:base_configuration_reference_uuid
,
:baseConfigurationReference
alias_method
:base_configuration_reference_uuid
=
,
:baseConfigurationReference
=
def
baseConfigurationReference
@project
.
objects
[
base_configuration_reference_uuid
]
end
def
baseConfigurationReference
=
(
config
)
self
.
base_configuration_reference_uuid
=
config
.
uuid
end
end
end
class
XCConfigurationList
<
PBXObject
class
XCConfigurationList
<
PBXObject
attributes_accessor
:buildConfigurations
has_many
:buildConfigurations
,
:class
=>
XCBuildConfiguration
alias_method
:build_configuration_uuids
,
:buildConfigurations
alias_method
:build_configuration_uuids
=
,
:buildConfigurations
=
def
buildConfigurations
list_by_class
(
build_configuration_uuids
,
XCBuildConfiguration
)
end
def
buildConfigurations
=
(
configs
)
def
initialize
(
*
)
self
.
build_configuration_uuids
=
configs
.
map
(
&
:uuid
)
super
self
.
buildConfigurationUUIDs
||=
[]
end
end
end
end
...
...
spec/unit/xcode/project_spec.rb
View file @
bf963342
...
@@ -106,11 +106,59 @@ describe "Pod::Xcode::Project" do
...
@@ -106,11 +106,59 @@ describe "Pod::Xcode::Project" do
end
end
end
end
describe
"a new XCBuildConfiguration"
do
before
do
@configuration
=
@project
.
objects
.
add
(
Pod
::
Xcode
::
Project
::
XCBuildConfiguration
)
end
it
"returns the xcconfig that this configuration is based on (baseConfigurationReference)"
do
p
@project
.
objects
[
'515160D0141EC5D100EBB823'
]
xcconfig
=
@project
.
objects
.
new
@configuration
.
baseConfiguration
=
xcconfig
@configuration
.
baseConfigurationReference
.
should
==
xcconfig
.
uuid
end
end
describe
"a new XCConfigurationList"
do
before
do
@list
=
@project
.
objects
.
add
(
Pod
::
Xcode
::
Project
::
XCConfigurationList
)
end
it
"returns the configurations"
do
configuration
=
@project
.
objects
.
add
(
Pod
::
Xcode
::
Project
::
XCBuildConfiguration
)
@list
.
buildConfigurations
.
to_a
.
should
==
[]
@list
.
buildConfigurations
=
[
configuration
]
@list
.
buildConfigurationUUIDs
.
should
==
[
configuration
.
uuid
]
end
end
describe
"a new PBXNativeTarget"
do
describe
"a new PBXNativeTarget"
do
before
do
before
do
@target
=
@project
.
targets
.
first
@target
=
@project
.
targets
.
first
end
end
it
"returns the product name, which is the name of the binary"
do
@target
.
productName
.
should
==
"Pods"
end
it
"returns the product"
do
product
=
@target
.
product
product
.
uuid
.
should
==
@target
.
productReference
end
it
"returns that product type is a static library"
do
@target
.
productType
.
should
==
"com.apple.product-type.library.static"
end
it
"returns the buildConfigurationList"
do
list
=
@target
.
buildConfigurationList
list
.
should
.
be
.
instance_of
Pod
::
Xcode
::
Project
::
XCConfigurationList
@target
.
buildConfigurationListUUID
=
nil
@target
.
buildConfigurationList
.
should
==
nil
@target
.
buildConfigurationListUUID
=
list
.
uuid
@target
.
buildConfigurationList
.
attributes
.
should
==
list
.
attributes
end
describe
"concerning its build phases"
do
describe
"concerning its build phases"
do
extend
SpecHelper
::
TemporaryDirectory
extend
SpecHelper
::
TemporaryDirectory
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment