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
c14cdd66
Commit
c14cdd66
authored
Sep 13, 2011
by
Eloy Duran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Untested refactoring
parent
3a8a62fc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
144 deletions
+167
-144
cocoa_pods.rb
lib/cocoa_pods.rb
+5
-1
specification.rb
lib/cocoa_pods/specification.rb
+13
-25
config.rb
lib/cocoa_pods/xcode/config.rb
+29
-0
project.rb
lib/cocoa_pods/xcode/project.rb
+120
-0
xcode_project.rb
lib/cocoa_pods/xcode_project.rb
+0
-118
No files found.
lib/cocoa_pods.rb
View file @
c14cdd66
...
...
@@ -8,5 +8,9 @@ module Pod
autoload
:Spec
,
'cocoa_pods/specification'
autoload
:Specification
,
'cocoa_pods/specification'
autoload
:Version
,
'cocoa_pods/version'
autoload
:XcodeProject
,
'cocoa_pods/xcode_project'
module
Xcode
autoload
:Config
,
'cocoa_pods/xcode/config'
autoload
:Project
,
'cocoa_pods/xcode/project'
end
end
lib/cocoa_pods/specification.rb
View file @
c14cdd66
...
...
@@ -120,8 +120,16 @@ module Pod
def
create_static_library_project!
puts
"==> Creating static library project"
xcconfigs
=
[]
project
=
XcodeProject
.
static_library
xcconfig
=
Xcode
::
Config
.
new
({
# in a workspace this is where the static library headers should be found
'USER_HEADER_SEARCH_PATHS'
=>
'$(BUILT_PRODUCTS_DIR)'
,
# search the user headers
'ALWAYS_SEARCH_USER_PATHS'
=>
'YES'
,
})
project
=
Xcode
::
Project
.
static_library
resolved_dependent_specification_sets
.
each
do
|
set
|
# In case the set is only part of other pods we don't need to build
# the pod itself.
...
...
@@ -138,35 +146,15 @@ module Pod
end
end
if
xcconfig
=
spec
.
read
(
:xcconfig
)
xcconfig
s
<<
xcconfig
if
xcconfig
_hash
=
spec
.
read
(
:xcconfig
)
xcconfig
<<
xcconfig_hash
end
end
project
.
create_in
(
config
.
project_pods_root
)
# TODO the static library needs an extra xcconfig which sets the values from issue #1.
# Or we could edit the project.pbxproj file, but that seems like more work...
merged_xcconfig
=
{
# in a workspace this is where the static library headers should be found
'USER_HEADER_SEARCH_PATHS'
=>
'$(BUILT_PRODUCTS_DIR)'
,
# search the user headers
'ALWAYS_SEARCH_USER_PATHS'
=>
'YES'
,
}
xcconfigs
.
each
do
|
xcconfig
|
xcconfig
.
each
do
|
key
,
value
|
if
existing_value
=
merged_xcconfig
[
key
]
merged_xcconfig
[
key
]
=
"
#{
existing_value
}
#{
value
}
"
else
merged_xcconfig
[
key
]
=
value
end
end
end
(
config
.
project_pods_root
+
'Pods.xcconfig'
).
open
(
'w'
)
do
|
file
|
merged_xcconfig
.
each
do
|
key
,
value
|
file
.
puts
"
#{
key
}
=
#{
value
}
"
end
end
xcconfig
.
create_in
(
config
.
project_pods_root
)
end
include
Config
::
Mixin
...
...
lib/cocoa_pods/xcode/config.rb
0 → 100644
View file @
c14cdd66
module
Pod
module
Xcode
class
Config
def
initialize
(
xcconfig_hash
=
{})
@attributes
=
{}
merge!
(
xcconfig_hash
)
end
def
merge!
(
xcconfig_hash
)
xcconfig_hash
.
each
do
|
key
,
value
|
if
existing_value
=
@attributes
[
key
]
@attributes
[
key
]
=
"
#{
existing_value
}
#{
value
}
"
else
@attributes
[
key
]
=
value
end
end
end
alias_method
:<<
,
:merge!
def
create_in
(
pods_root
)
(
pods_root
+
'Pods.xcconfig'
).
open
(
'w'
)
do
|
file
|
@attributes
.
each
do
|
key
,
value
|
file
.
puts
"
#{
key
}
=
#{
value
}
"
end
end
end
end
end
end
lib/cocoa_pods/xcode/project.rb
0 → 100644
View file @
c14cdd66
framework
'Foundation'
module
Pod
module
Xcode
class
Project
TEMPLATES_DIR
=
Pathname
.
new
(
File
.
expand_path
(
'../../../xcode-project-templates'
,
__FILE__
))
# TODO see if we really need different templates for iOS and OS X
def
self
.
static_library
new
TEMPLATES_DIR
+
'cocoa-touch-static-library'
end
def
initialize
(
template_dir
)
@template_dir
=
template_dir
file
=
template_dir
+
template_file
@template
=
NSMutableDictionary
.
dictionaryWithContentsOfFile
(
file
.
to_s
)
end
def
template_file
'Pods.xcodeproj/project.pbxproj'
end
def
add_source_file
(
file
)
file_ref_uuid
=
add_file_reference
(
file
,
'SOURCE_ROOT'
)
add_file_to_group
(
file_ref_uuid
,
'Pods'
)
if
file
.
extname
==
'.h'
build_file_uuid
=
add_build_file
(
file_ref_uuid
,
"settings"
=>
{
"ATTRIBUTES"
=>
[
"Public"
]
})
add_file_to_list
(
'PBXHeadersBuildPhase'
,
build_file_uuid
)
else
build_file_uuid
=
add_build_file
(
file_ref_uuid
)
add_file_to_list
(
'PBXSourcesBuildPhase'
,
build_file_uuid
)
end
end
def
add_framework
(
path
)
file_ref_uuid
=
add_file_reference
(
path
,
'SDKROOT'
)
add_file_to_group
(
file_ref_uuid
,
'Frameworks'
)
build_file_uuid
=
add_build_file
(
file_ref_uuid
)
add_file_to_list
(
'PBXFrameworksBuildPhase'
,
build_file_uuid
)
end
def
add_header_search_path
(
path
)
objects_by_isa
(
'XCBuildConfiguration'
).
each
do
|
_
,
object
|
(
object
[
'buildSettings'
][
'HEADER_SEARCH_PATHS'
]
||=
[])
<<
path
end
end
def
to_hash
@template
end
def
create_in
(
pods_root
)
@template_dir
.
children
.
each
do
|
child
|
FileUtils
.
cp_r
(
child
,
pods_root
+
child
.
relative_path_from
(
@template_dir
))
end
pbxproj
=
pods_root
+
template_file
@template
.
writeToFile
(
pbxproj
.
to_s
,
atomically
:true
)
end
private
def
add_object
(
object
)
uuid
=
generate_uuid
objects
[
uuid
]
=
object
uuid
end
def
add_file_reference
(
path
,
source_tree
)
add_object
({
"name"
=>
path
.
basename
.
to_s
,
"isa"
=>
"PBXFileReference"
,
"sourceTree"
=>
source_tree
,
"path"
=>
path
.
to_s
,
})
end
def
add_build_file
(
file_ref_uuid
,
extra
=
{})
add_object
(
extra
.
merge
({
"isa"
=>
"PBXBuildFile"
,
"fileRef"
=>
file_ref_uuid
}))
end
def
add_file_to_list
(
isa
,
build_file_uuid
)
object_uuid
,
object
=
objects_by_isa
(
isa
).
first
object
[
'files'
]
<<
build_file_uuid
end
def
add_file_to_group
(
file_ref_uuid
,
name
)
object_uuid
,
object
=
objects
.
find
do
|
_
,
object
|
object
[
'isa'
]
==
'PBXGroup'
&&
object
[
'name'
]
==
name
end
object
[
'children'
]
<<
file_ref_uuid
end
def
objects
@template
[
'objects'
]
end
def
objects_by_isa
(
isa
)
objects
.
select
{
|
_
,
object
|
object
[
'isa'
]
==
isa
}
end
def
generate_uuid
_uuid
=
CFUUIDCreate
(
nil
)
uuid
=
CFUUIDCreateString
(
nil
,
_uuid
)
CFRelease
(
_uuid
)
CFMakeCollectable
(
uuid
)
# Xcode's version is actually shorter, not worrying about collisions too much right now.
uuid
.
gsub
(
'-'
,
''
)[
0
..
23
]
end
public
def
pretty_print
puts
`ruby -r pp -e 'pp(
#{
@template
.
inspect
}
)'`
end
end
end
end
lib/cocoa_pods/xcode_project.rb
deleted
100644 → 0
View file @
3a8a62fc
framework
'Foundation'
module
Pod
class
XcodeProject
TEMPLATES_DIR
=
Pathname
.
new
(
File
.
expand_path
(
'../../../xcode-project-templates'
,
__FILE__
))
# TODO see if we really need different templates for iOS and OS X
def
self
.
static_library
new
TEMPLATES_DIR
+
'cocoa-touch-static-library'
end
def
initialize
(
template_dir
)
@template_dir
=
template_dir
file
=
template_dir
+
template_file
@template
=
NSMutableDictionary
.
dictionaryWithContentsOfFile
(
file
.
to_s
)
end
def
template_file
'Pods.xcodeproj/project.pbxproj'
end
def
add_source_file
(
file
)
file_ref_uuid
=
add_file_reference
(
file
,
'SOURCE_ROOT'
)
add_file_to_group
(
file_ref_uuid
,
'Pods'
)
if
file
.
extname
==
'.h'
build_file_uuid
=
add_build_file
(
file_ref_uuid
,
"settings"
=>
{
"ATTRIBUTES"
=>
[
"Public"
]
})
add_file_to_list
(
'PBXHeadersBuildPhase'
,
build_file_uuid
)
else
build_file_uuid
=
add_build_file
(
file_ref_uuid
)
add_file_to_list
(
'PBXSourcesBuildPhase'
,
build_file_uuid
)
end
end
def
add_framework
(
path
)
file_ref_uuid
=
add_file_reference
(
path
,
'SDKROOT'
)
add_file_to_group
(
file_ref_uuid
,
'Frameworks'
)
build_file_uuid
=
add_build_file
(
file_ref_uuid
)
add_file_to_list
(
'PBXFrameworksBuildPhase'
,
build_file_uuid
)
end
def
add_header_search_path
(
path
)
objects_by_isa
(
'XCBuildConfiguration'
).
each
do
|
_
,
object
|
(
object
[
'buildSettings'
][
'HEADER_SEARCH_PATHS'
]
||=
[])
<<
path
end
end
def
to_hash
@template
end
def
create_in
(
pods_root
)
@template_dir
.
children
.
each
do
|
child
|
FileUtils
.
cp_r
(
child
,
pods_root
+
child
.
relative_path_from
(
@template_dir
))
end
pbxproj
=
pods_root
+
template_file
@template
.
writeToFile
(
pbxproj
.
to_s
,
atomically
:true
)
end
private
def
add_object
(
object
)
uuid
=
generate_uuid
objects
[
uuid
]
=
object
uuid
end
def
add_file_reference
(
path
,
source_tree
)
add_object
({
"name"
=>
path
.
basename
.
to_s
,
"isa"
=>
"PBXFileReference"
,
"sourceTree"
=>
source_tree
,
"path"
=>
path
.
to_s
,
})
end
def
add_build_file
(
file_ref_uuid
,
extra
=
{})
add_object
(
extra
.
merge
({
"isa"
=>
"PBXBuildFile"
,
"fileRef"
=>
file_ref_uuid
}))
end
def
add_file_to_list
(
isa
,
build_file_uuid
)
object_uuid
,
object
=
objects_by_isa
(
isa
).
first
object
[
'files'
]
<<
build_file_uuid
end
def
add_file_to_group
(
file_ref_uuid
,
name
)
object_uuid
,
object
=
objects
.
find
do
|
_
,
object
|
object
[
'isa'
]
==
'PBXGroup'
&&
object
[
'name'
]
==
name
end
object
[
'children'
]
<<
file_ref_uuid
end
def
objects
@template
[
'objects'
]
end
def
objects_by_isa
(
isa
)
objects
.
select
{
|
_
,
object
|
object
[
'isa'
]
==
isa
}
end
def
generate_uuid
_uuid
=
CFUUIDCreate
(
nil
)
uuid
=
CFUUIDCreateString
(
nil
,
_uuid
)
CFRelease
(
_uuid
)
CFMakeCollectable
(
uuid
)
# Xcode's version is actually shorter, not worrying about collisions too much right now.
uuid
.
gsub
(
'-'
,
''
)[
0
..
23
]
end
public
def
pretty_print
puts
`ruby -r pp -e 'pp(
#{
@template
.
inspect
}
)'`
end
end
end
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