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
5a647fde
Commit
5a647fde
authored
Feb 02, 2013
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TargetInstaller] Adapt for architectural changes
parent
65dcd5e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
93 deletions
+88
-93
target_installer.rb
lib/cocoapods/installer/target_installer.rb
+69
-79
target_installer_spec.rb
spec/unit/installer/target_installer_spec.rb
+19
-14
No files found.
lib/cocoapods/installer/target_installer.rb
View file @
5a647fde
...
@@ -7,40 +7,6 @@ module Pod
...
@@ -7,40 +7,6 @@ module Pod
#
#
class
TargetInstaller
class
TargetInstaller
# @param [Project] project @see project
# @param [Library] library @see library
#
def
initialize
(
sandbox
,
library
)
@sandbox
=
sandbox
@library
=
library
end
# Creates the target in the Pods project and the relative support files.
#
# @return [void]
#
def
install!
add_target
add_pod_references
create_suport_files_group
create_xcconfig_file
create_target_header
create_prefix_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
create_dummy_source
end
#-----------------------------------------------------------------------#
public
# @!group API
#
# This is the tentative API for the podfile and the specification hooks.
# @return [Sandbox] sandbox the sandbox where the support files should
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
# be generated.
#
#
...
@@ -50,41 +16,32 @@ module Pod
...
@@ -50,41 +16,32 @@ module Pod
#
#
attr_reader
:library
attr_reader
:library
# @return [PBXNativeTarget] the target generated by the installation
# @param [Project] project @see project
# process.
# @param [Library] library @see library
#
# @note Generated by the {#add_target} step.
#
attr_reader
:target
# @return [Project] the Pods project of the sandbox.
#
def
project
sandbox
.
project
end
# @return [Array<LocalPod>] the local pods of this target.
#
#
def
pods
def
initialize
(
sandbox
,
library
)
library
.
local_pods
@sandbox
=
sandbox
@library
=
library
end
end
#
@return [TargetDefinition] the target definition of the library
.
#
Creates the target in the Pods project and the relative support files
.
#
#
def
target_definition
# @return [void]
library
.
target_definition
end
#--------------------------------------#
# @!group Hooks compatiblity
# @todo This has to be removed, but this means the specs have to be
# updated if they need a reference to the prefix header.
#
#
def
prefix_header_filename
def
install!
UI
.
warn
"The usage of the TargetInstaller#prefix_header_filename is deprecated."
UI
.
message
"- Installing target `
#{
library
.
name
}
`
#{
library
.
platform
}
"
do
library
.
prefix_header_path
.
relative_path_from
(
sandbox
.
root
)
add_target
add_files_to_build_phases
create_suport_files_group
create_xcconfig_file
create_target_header
create_prefix_header
create_bridge_support_file
create_copy_resources_script
create_acknowledgements
create_dummy_source
end
end
end
#-----------------------------------------------------------------------#
#-----------------------------------------------------------------------#
...
@@ -131,7 +88,7 @@ module Pod
...
@@ -131,7 +88,7 @@ module Pod
end
end
end
end
library
.
target
=
@target
library
.
target
=
@target
end
end
# Adds the build files of the pods to the target and adds a refence to
# Adds the build files of the pods to the target and adds a refence to
...
@@ -142,12 +99,21 @@ module Pod
...
@@ -142,12 +99,21 @@ module Pod
#
#
# @return [void]
# @return [void]
#
#
def
add_pod_references
def
add_files_to_build_phases
pods
.
each
do
|
pod
|
UI
.
message
"- Adding Build files"
do
pod
.
add_build_files_to_target
(
target
)
library
.
file_accessors
.
each
do
|
file_accessor
|
UI
.
message
"-
#{
file_accessor
.
spec
}
"
pod
.
frameworks
.
each
do
|
framework
|
file_accessor
.
source_files
.
each
do
|
source_file
|
framework_ref
=
project
.
add_system_framework
(
framework
,
target
)
file_reference
=
project
.
file_reference
(
source_file
,
file_accessor
.
spec_consumer
.
spec
.
name
)
consumer
=
file_accessor
.
spec_consumer
flags
=
consumer
.
compiler_flags
.
dup
flags
<<
'-fobjc-arc'
if
consumer
.
requires_arc
flags
=
flags
*
" "
target
.
add_file_references
([
file_reference
],
flags
)
end
file_accessor
.
spec_consumer
.
frameworks
.
each
do
|
framework
|
framework_ref
=
project
.
add_system_framework
(
framework
,
target
)
end
end
end
end
end
end
end
...
@@ -174,7 +140,7 @@ module Pod
...
@@ -174,7 +140,7 @@ module Pod
def
create_xcconfig_file
def
create_xcconfig_file
path
=
library
.
xcconfig_path
path
=
library
.
xcconfig_path
UI
.
message
"- Generating xcconfig file at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"- Generating xcconfig file at
#{
UI
.
path
(
path
)
}
"
do
gen
=
Generator
::
XCConfig
.
new
(
sandbox
,
pod
s
,
library
.
relative_pods_root
)
gen
=
Generator
::
XCConfig
.
new
(
sandbox
,
spec_consumer
s
,
library
.
relative_pods_root
)
gen
.
set_arc_compatibility_flag
=
target_definition
.
podfile
.
set_arc_compatibility_flag?
gen
.
set_arc_compatibility_flag
=
target_definition
.
podfile
.
set_arc_compatibility_flag?
gen
.
save_as
(
path
)
gen
.
save_as
(
path
)
library
.
xcconfig
=
gen
.
xcconfig
library
.
xcconfig
=
gen
.
xcconfig
...
@@ -194,7 +160,7 @@ module Pod
...
@@ -194,7 +160,7 @@ module Pod
#
#
def
create_target_header
def
create_target_header
path
=
library
.
target_header_path
path
=
library
.
target_header_path
UI
.
message
"-
Cre
ating target header at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"-
Gener
ating target header at
#{
UI
.
path
(
path
)
}
"
do
generator
=
Generator
::
TargetHeader
.
new
(
library
.
specs
)
generator
=
Generator
::
TargetHeader
.
new
(
library
.
specs
)
generator
.
save_as
(
path
)
generator
.
save_as
(
path
)
add_file_to_support_group
(
path
)
add_file_to_support_group
(
path
)
...
@@ -210,7 +176,7 @@ module Pod
...
@@ -210,7 +176,7 @@ module Pod
def
create_prefix_header
def
create_prefix_header
path
=
library
.
prefix_header_path
path
=
library
.
prefix_header_path
UI
.
message
"- Generating prefix header at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"- Generating prefix header at
#{
UI
.
path
(
path
)
}
"
do
generator
=
Generator
::
PrefixHeader
.
new
(
target_definition
.
platform
,
pods
)
generator
=
Generator
::
PrefixHeader
.
new
(
library
.
file_accessors
,
library
.
platform
)
generator
.
imports
<<
library
.
target_header_path
.
basename
generator
.
imports
<<
library
.
target_header_path
.
basename
generator
.
save_as
(
path
)
generator
.
save_as
(
path
)
add_file_to_support_group
(
path
)
add_file_to_support_group
(
path
)
...
@@ -234,8 +200,7 @@ module Pod
...
@@ -234,8 +200,7 @@ module Pod
if
target_definition
.
podfile
.
generate_bridge_support?
if
target_definition
.
podfile
.
generate_bridge_support?
path
=
library
.
bridge_support_path
path
=
library
.
bridge_support_path
UI
.
message
"- Generating BridgeSupport metadata at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"- Generating BridgeSupport metadata at
#{
UI
.
path
(
path
)
}
"
do
relative_headers
=
pods
.
map
{
|
pod
|
pod
.
header_files
.
map
{
|
head
|
sandbox
.
relativize
(
head
)}
}.
flatten
headers
=
target
.
headers_build_phase
.
files
.
map
{
|
bf
|
sandbox
.
root
+
bf
.
file_ref
.
path
}
headers
=
relative_headers
.
map
{
|
header
|
sandbox
.
root
+
header
}
generator
=
Generator
::
BridgeSupport
.
new
(
headers
)
generator
=
Generator
::
BridgeSupport
.
new
(
headers
)
generator
.
save_as
(
path
)
generator
.
save_as
(
path
)
add_file_to_support_group
(
path
)
add_file_to_support_group
(
path
)
...
@@ -255,7 +220,7 @@ module Pod
...
@@ -255,7 +220,7 @@ module Pod
def
create_copy_resources_script
def
create_copy_resources_script
path
=
library
.
copy_resources_script_path
path
=
library
.
copy_resources_script_path
UI
.
message
"- Generating copy resources script at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"- Generating copy resources script at
#{
UI
.
path
(
path
)
}
"
do
resources
=
pods
.
map
{
|
p
|
p
.
resource_files
.
map
{
|
res
|
sandbox
.
relativize
(
res
)}
}.
flatten
resources
=
library
.
file_accessors
.
map
{
|
accessor
|
accessor
.
resources
.
values
.
flatten
.
map
{
|
res
|
sandbox
.
relativize
(
res
)}
}.
flatten
resources
<<
bridge_support_file
if
bridge_support_file
resources
<<
bridge_support_file
if
bridge_support_file
generator
=
Generator
::
CopyResourcesScript
.
new
(
resources
)
generator
=
Generator
::
CopyResourcesScript
.
new
(
resources
)
generator
.
save_as
(
path
)
generator
.
save_as
(
path
)
...
@@ -272,7 +237,7 @@ module Pod
...
@@ -272,7 +237,7 @@ module Pod
Generator
::
Acknowledgements
.
generators
.
each
do
|
generator_class
|
Generator
::
Acknowledgements
.
generators
.
each
do
|
generator_class
|
path
=
generator_class
.
path_from_basepath
(
basepath
)
path
=
generator_class
.
path_from_basepath
(
basepath
)
UI
.
message
"- Generating acknowledgements at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"- Generating acknowledgements at
#{
UI
.
path
(
path
)
}
"
do
generator
=
generator_class
.
new
(
target_definition
,
pod
s
)
generator
=
generator_class
.
new
(
library
.
file_accessor
s
)
generator
.
save_as
(
path
)
generator
.
save_as
(
path
)
add_file_to_support_group
(
path
)
add_file_to_support_group
(
path
)
end
end
...
@@ -286,7 +251,7 @@ module Pod
...
@@ -286,7 +251,7 @@ module Pod
#
#
def
create_dummy_source
def
create_dummy_source
path
=
library
.
dummy_source_path
path
=
library
.
dummy_source_path
UI
.
message
"- Generating
acknowledgements
at
#{
UI
.
path
(
path
)
}
"
do
UI
.
message
"- Generating
dummy source file
at
#{
UI
.
path
(
path
)
}
"
do
generator
=
Generator
::
DummySource
.
new
(
library
.
label
)
generator
=
Generator
::
DummySource
.
new
(
library
.
label
)
generator
.
save_as
(
path
)
generator
.
save_as
(
path
)
file_reference
=
add_file_to_support_group
(
path
)
file_reference
=
add_file_to_support_group
(
path
)
...
@@ -298,8 +263,33 @@ module Pod
...
@@ -298,8 +263,33 @@ module Pod
private
private
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader
:target
# @!group Private helpers.
# @!group Private helpers.
# @return [Project] the Pods project of the sandbox.
#
def
project
sandbox
.
project
end
# @return [TargetDefinition] the target definition of the library.
#
def
target_definition
library
.
target_definition
end
# @return [Specification::Consumer] the consumer for the specifications.
#
def
spec_consumers
@spec_consumers
||=
library
.
file_accessors
.
map
(
&
:spec_consumer
)
end
# @return [PBXGroup] the group where the file references to the support
# @return [PBXGroup] the group where the file references to the support
# files should be stored.
# files should be stored.
#
#
...
...
spec/unit/installer/target_installer_spec.rb
View file @
5a647fde
...
@@ -12,23 +12,25 @@ module Pod
...
@@ -12,23 +12,25 @@ module Pod
end
end
@target_definition
=
@podfile
.
target_definitions
[
:default
]
@target_definition
=
@podfile
.
target_definitions
[
:default
]
@project
=
Project
.
new
@project
=
Project
.
new
config
.
sandbox
.
project
=
@project
config
.
sandbox
.
project
=
@project
path_list
=
Sandbox
::
PathList
.
new
(
fixture
(
'banana-lib'
))
@spec
=
fixture_spec
(
'banana-lib/BananaLib.podspec'
)
file_accessor
=
Sandbox
::
FileAccessor
.
new
(
path_list
,
@spec
.
consumer
(
:ios
))
source_files
=
config
.
sandbox
.
relativize_paths
(
file_accessor
.
source_files
)
@project
.
add_source_files
(
source_files
,
'BananaLib'
,
@project
.
pods
)
@library
=
Library
.
new
(
@target_definition
)
@library
=
Library
.
new
(
@target_definition
)
@library
.
platform
=
Platform
.
new
(
:ios
,
'6.0'
)
@library
.
platform
=
Platform
.
new
(
:ios
,
'6.0'
)
@library
.
support_files_root
=
config
.
sandbox
.
root
@library
.
support_files_root
=
config
.
sandbox
.
root
@library
.
user_project_path
=
config
.
sandbox
.
root
+
'../user_project.xcodeproj'
@library
.
user_project_path
=
config
.
sandbox
.
root
+
'../user_project.xcodeproj'
@library
.
user_build_configurations
=
{
'Debug'
=>
:debug
,
'Release'
=>
:release
,
'AppStore'
=>
:release
,
'Test'
=>
:debug
}
@library
.
user_build_configurations
=
{
'Debug'
=>
:debug
,
'Release'
=>
:release
,
'AppStore'
=>
:release
,
'Test'
=>
:debug
}
specification
=
fixture_spec
(
'banana-lib/BananaLib.podspec'
)
@library
.
specs
=
[
@spec
]
@library
.
specs
=
[
specification
]
@library
.
file_accessors
=
[
file_accessor
]
@pod
=
LocalPod
.
new
(
specification
,
config
.
sandbox
,
@library
.
platform
)
@library
.
local_pods
=
[
@pod
]
@installer
=
TargetInstaller
.
new
(
config
.
sandbox
,
@library
)
@installer
=
TargetInstaller
.
new
(
config
.
sandbox
,
@library
)
specification
.
prefix_header_contents
=
'#import "BlocksKit.h"'
@spec
.
prefix_header_contents
=
'#import "BlocksKit.h"'
@pod
.
stubs
(
:root
).
returns
(
Pathname
.
new
(
fixture
(
'banana-lib'
)))
@pod
.
add_file_references_to_project
(
@project
)
end
end
it
"adds file references for the support files of the target"
do
it
"adds file references for the support files of the target"
do
...
@@ -112,7 +114,7 @@ module Pod
...
@@ -112,7 +114,7 @@ module Pod
it
"does not enable the GCC_WARN_INHIBIT_ALL_WARNINGS flag by default"
do
it
"does not enable the GCC_WARN_INHIBIT_ALL_WARNINGS flag by default"
do
@installer
.
install!
@installer
.
install!
@installer
.
target
.
build_configurations
.
each
do
|
config
|
@installer
.
library
.
target
.
build_configurations
.
each
do
|
config
|
config
.
build_settings
[
'GCC_WARN_INHIBIT_ALL_WARNINGS'
].
should
.
be
.
nil
config
.
build_settings
[
'GCC_WARN_INHIBIT_ALL_WARNINGS'
].
should
.
be
.
nil
end
end
end
end
...
@@ -120,7 +122,7 @@ module Pod
...
@@ -120,7 +122,7 @@ module Pod
it
"enables the GCC_WARN_INHIBIT_ALL_WARNINGS flag"
do
it
"enables the GCC_WARN_INHIBIT_ALL_WARNINGS flag"
do
@podfile
.
inhibit_all_warnings!
@podfile
.
inhibit_all_warnings!
@installer
.
install!
@installer
.
install!
@installer
.
target
.
build_configurations
.
each
do
|
config
|
@installer
.
library
.
target
.
build_configurations
.
each
do
|
config
|
config
.
build_settings
[
'GCC_WARN_INHIBIT_ALL_WARNINGS'
].
should
==
'YES'
config
.
build_settings
[
'GCC_WARN_INHIBIT_ALL_WARNINGS'
].
should
==
'YES'
end
end
end
end
...
@@ -129,14 +131,14 @@ module Pod
...
@@ -129,14 +131,14 @@ module Pod
it
'adds the source files of each pod to the target of the Pod library'
do
it
'adds the source files of each pod to the target of the Pod library'
do
@installer
.
install!
@installer
.
install!
names
=
@installer
.
target
.
source_build_phase
.
files
.
map
{
|
bf
|
bf
.
file_ref
.
name
}
names
=
@installer
.
library
.
target
.
source_build_phase
.
files
.
map
{
|
bf
|
bf
.
file_ref
.
name
}
names
.
should
.
include
(
"Banana.m"
)
names
.
should
.
include
(
"Banana.m"
)
end
end
it
'adds the frameworks required by to the pod to the project for informative purposes'
do
it
'adds the frameworks required by to the pod to the project for informative purposes'
do
Specification
::
Consumer
.
any_instance
.
stubs
(
:frameworks
).
returns
([
'QuartzCore'
])
Specification
::
Consumer
.
any_instance
.
stubs
(
:frameworks
).
returns
([
'QuartzCore'
])
@installer
.
install!
@installer
.
install!
names
=
@installer
.
project
[
'Frameworks'
].
children
.
map
(
&
:name
)
names
=
@installer
.
sandbox
.
project
[
'Frameworks'
].
children
.
map
(
&
:name
)
names
.
sort
.
should
==
[
"Foundation.framework"
,
"QuartzCore.framework"
]
names
.
sort
.
should
==
[
"Foundation.framework"
,
"QuartzCore.framework"
]
end
end
...
@@ -158,17 +160,20 @@ module Pod
...
@@ -158,17 +160,20 @@ module Pod
end
end
it
"creates a prefix header, including the contents of the specification's prefix header"
do
it
"creates a prefix header, including the contents of the specification's prefix header"
do
@
pod
.
top_specification
.
prefix_header_contents
=
'#import "BlocksKit.h"'
@
spec
.
prefix_header_contents
=
'#import "BlocksKit.h"'
@installer
.
install!
@installer
.
install!
prefix_header
=
config
.
sandbox
.
root
+
'Pods-prefix.pch'
prefix_header
=
config
.
sandbox
.
root
+
'Pods-prefix.pch'
prefix_header
.
read
.
should
==
<<-
EOS
.
strip_heredoc
generated
=
prefix_header
.
read
expected
=
<<-
EOS
.
strip_heredoc
#ifdef __OBJC__
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <UIKit/UIKit.h>
#endif
#endif
#import "Pods-header.h"
#import "Pods-header.h"
#import "BlocksKit.h"
#import "BlocksKit.h"
#import <BananaTree/BananaTree.h>
EOS
EOS
generated
.
should
==
expected
end
end
it
"creates a bridge support file"
do
it
"creates a bridge support file"
do
...
@@ -193,7 +198,7 @@ module Pod
...
@@ -193,7 +198,7 @@ module Pod
it
"creates a dummy source to ensure the compilation of libraries with only categories"
do
it
"creates a dummy source to ensure the compilation of libraries with only categories"
do
@installer
.
install!
@installer
.
install!
build_files
=
@installer
.
target
.
source_build_phase
.
files
build_files
=
@installer
.
library
.
target
.
source_build_phase
.
files
build_file
=
build_files
.
find
{
|
bf
|
bf
.
file_ref
.
name
==
'Pods-dummy.m'
}
build_file
=
build_files
.
find
{
|
bf
|
bf
.
file_ref
.
name
==
'Pods-dummy.m'
}
build_file
.
should
.
be
.
not
.
nil
build_file
.
should
.
be
.
not
.
nil
build_file
.
file_ref
.
path
.
should
==
'Pods-dummy.m'
build_file
.
file_ref
.
path
.
should
==
'Pods-dummy.m'
...
...
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