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
d691d0bb
Commit
d691d0bb
authored
Sep 06, 2013
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean-up
parent
602d23f6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
230 additions
and
236 deletions
+230
-236
file_references_installer.rb
...aller/pods_project_generator/file_references_installer.rb
+115
-121
target_installer.rb
...pods/installer/pods_project_generator/target_installer.rb
+104
-104
file_references_installer_spec.rb
.../pods_project_generator/file_references_installer_spec.rb
+11
-11
No files found.
lib/cocoapods/installer/pods_project_generator/file_references_installer.rb
View file @
d691d0bb
...
...
@@ -2,151 +2,145 @@ module Pod
class
Installer
class
PodsProjectGenerator
# Controller class responsible of installing the file references of the
# specifications in the Pods project.
#
class
FileReferencesInstaller
# @return [Sandbox] The sandbox of the installation.
#
attr_reader
:sandbox
# @return [Array<Library>] The libraries of the installation.
#
attr_reader
:pod_targets
# @param [Sandbox] sandbox @see sandbox
# @param [Array<Library>] libraries @see libraries
# @param [Project] libraries @see libraries
#
def
initialize
(
sandbox
,
pod_targets
)
@sandbox
=
sandbox
@pod_targets
=
pod_targets
end
# Controller class responsible of installing the file references of the
# specifications in the Pods project.
#
class
FileReferencesInstaller
# @return [Sandbox] The sandbox of the installation.
#
attr_reader
:sandbox
# @return [Array<Library>] The libraries of the installation.
#
attr_reader
:pod_targets
# @param [Sandbox] sandbox @see sandbox
# @param [Array<Library>] libraries @see libraries
# @param [Project] libraries @see libraries
#
def
initialize
(
sandbox
,
pod_targets
)
@sandbox
=
sandbox
@pod_targets
=
pod_targets
end
# Installs the file references.
#
# @return [void]
#
def
install!
refresh_file_accessors
add_source_files_references
add_frameworks_bundles
add_vendored_libraries
add_resources
end
# Installs the file references.
#
# @return [void]
#
def
install!
refresh_file_accessors
add_source_files_references
add_frameworks_bundles
add_vendored_libraries
add_resources
end
#-----------------------------------------------------------------------#
private
private
# @!group Installation Steps
# @!group Installation Steps
#---------------------------------------------------------------------#
# Reads the file accessors contents from the file system.
#
# @note The contents of the file accessors are modified by the clean
# step of the #{PodSourceInstaller} and by the pre install hooks.
#
# @return [void]
#
def
refresh_file_accessors
file_accessors
.
each
do
|
fa
|
fa
.
path_list
.
read_file_system
# Reads the file accessors contents from the file system.
#
# @note The contents of the file accessors are modified by the clean
# step of the #{PodSourceInstaller} and by the pre install hooks.
#
# @return [void]
#
def
refresh_file_accessors
file_accessors
.
each
do
|
fa
|
fa
.
path_list
.
read_file_system
end
end
end
# Adds the source files of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively).
#
# @return [void]
#
def
add_source_files_references
UI
.
message
"- Adding source files"
do
add_file_accessors_paths_to_pods_group
(
:source_files
,
:source_files
)
# Adds the source files of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively).
#
# @return [void]
#
def
add_source_files_references
UI
.
message
"- Adding source files"
do
add_file_accessors_paths_to_pods_group
(
:source_files
,
:source_files
)
end
end
end
# Adds the bundled frameworks to the Pods project
#
# @return [void]
#
def
add_frameworks_bundles
UI
.
message
"- Adding frameworks"
do
add_file_accessors_paths_to_pods_group
(
:vendored_frameworks
,
:frameworks_and_libraries
)
# Adds the bundled frameworks to the Pods project
#
# @return [void]
#
def
add_frameworks_bundles
UI
.
message
"- Adding frameworks"
do
add_file_accessors_paths_to_pods_group
(
:vendored_frameworks
,
:frameworks_and_libraries
)
end
end
end
# Adds the bundled libraries to the Pods project
#
# @return [void]
#
def
add_vendored_libraries
UI
.
message
"- Adding libraries"
do
add_file_accessors_paths_to_pods_group
(
:vendored_libraries
,
:frameworks_and_libraries
)
# Adds the bundled libraries to the Pods project
#
# @return [void]
#
def
add_vendored_libraries
UI
.
message
"- Adding libraries"
do
add_file_accessors_paths_to_pods_group
(
:vendored_libraries
,
:frameworks_and_libraries
)
end
end
end
# Adds the resources of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively) in the resources group.
#
# @return [void]
#
def
add_resources
UI
.
message
"- Adding resources"
do
add_file_accessors_paths_to_pods_group
(
:resources
,
:resources
)
add_file_accessors_paths_to_pods_group
(
:resource_bundle_files
,
:resources
)
# Adds the resources of the Pods to the Pods project.
#
# @note The source files are grouped by Pod and in turn by subspec
# (recursively) in the resources group.
#
# @return [void]
#
def
add_resources
UI
.
message
"- Adding resources"
do
add_file_accessors_paths_to_pods_group
(
:resources
,
:resources
)
add_file_accessors_paths_to_pods_group
(
:resource_bundle_files
,
:resources
)
end
end
end
#-----------------------------------------------------------------------#
private
private
# @!group Private Helpers
# @!group Private Helpers
#---------------------------------------------------------------------#
# TODO
#
def
pods_project
sandbox
.
project
end
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations.
#
def
file_accessors
@file_accessors
||=
pod_targets
.
map
(
&
:file_accessors
).
flatten
.
compact
end
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations.
#
def
file_accessors
@file_accessors
||=
pod_targets
.
map
(
&
:file_accessors
).
flatten
.
compact
end
# Adds file references to the list of the paths returned by the file
# accessor with the given key to the given group of the Pods project.
#
# @param [Symbol] file_accessor_key
# The method of the file accessor which would return the list of
# the paths.
#
# @param [Symbol] group_key
# The key of the group of the Pods project.
#
# @return [void]
#
def
add_file_accessors_paths_to_pods_group
(
file_accessor_key
,
group_key
)
file_accessors
.
each
do
|
file_accessor
|
paths
=
file_accessor
.
send
(
file_accessor_key
)
paths
.
each
do
|
path
|
group
=
pods_project
.
group_for_spec
(
file_accessor
.
spec
.
name
,
group_key
)
pods_project
.
add_file_reference
(
path
,
group
)
# Adds file references to the list of the paths returned by the file
# accessor with the given key to the given group of the Pods project.
#
# @param [Symbol] file_accessor_key
# The method of the file accessor which would return the list of
# the paths.
#
# @param [Symbol] group_key
# The key of the group of the Pods project.
#
# @return [void]
#
def
add_file_accessors_paths_to_pods_group
(
file_accessor_key
,
group_key
)
file_accessors
.
each
do
|
file_accessor
|
paths
=
file_accessor
.
send
(
file_accessor_key
)
paths
.
each
do
|
path
|
group
=
sandbox
.
project
.
group_for_spec
(
file_accessor
.
spec
.
name
,
group_key
)
sandbox
.
project
.
add_file_reference
(
path
,
group
)
end
end
end
end
#--
---------------------------------------------------------------------#
#
---------------------------------------------------------------------#
end
end
end
end
end
lib/cocoapods/installer/pods_project_generator/target_installer.rb
View file @
d691d0bb
...
...
@@ -2,132 +2,132 @@ module Pod
class
Installer
class
PodsProjectGenerator
# Controller class responsible of creating and configuring the static
# library target in Pods project. It also creates the support file needed
# by the target.
#
class
TargetInstaller
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
#
attr_reader
:sandbox
# Controller class responsible of creating and configuring the static
# library target in Pods project. It also creates the support file needed
# by the target.
#
class
TargetInstaller
# @return [Sandbox] sandbox the sandbox where the support files should
# be generated.
#
attr_reader
:sandbox
# @return [Library] The library whose target needs to be generated.
#
attr_reader
:library
# @param [Project] project @see project
# @param [Library] library @see library
#
def
initialize
(
sandbox
,
library
)
@sandbox
=
sandbox
@library
=
library
end
# @return [Library] The library whose target needs to be generated.
#
attr_reader
:library
# @param [Project] project @see project
# @param [Library] library @see library
#
def
initialize
(
sandbox
,
library
)
@sandbox
=
sandbox
@library
=
library
end
private
private
# @!group Installation steps
#---------------------------------------------------------------------#
#-----------------------------------------------------------------------#
# Adds the target for the library to the Pods project with the
# appropriate build configurations.
#
# @note The `PODS_HEADERS_SEARCH_PATHS` overrides the xcconfig.
#
# @return [void]
#
def
add_target
name
=
library
.
label
platform
=
library
.
platform
.
name
deployment_target
=
library
.
platform
.
deployment_target
.
to_s
@target
=
project
.
new_target
(
:static_library
,
name
,
platform
,
deployment_target
)
# @!group Installation steps
settings
=
{}
if
library
.
platform
.
requires_legacy_ios_archs?
settings
[
'ARCHS'
]
=
"armv6 armv7"
end
# Adds the target for the library to the Pods project with the
# appropriate build configurations.
#
# @note The `PODS_HEADERS_SEARCH_PATHS` overrides the xcconfig.
#
# @return [void]
#
def
add_target
name
=
library
.
label
platform
=
library
.
platform
.
name
deployment_target
=
library
.
platform
.
deployment_target
.
to_s
@target
=
project
.
new_target
(
:static_library
,
name
,
platform
,
deployment_target
)
settings
=
{}
if
library
.
platform
.
requires_legacy_ios_archs?
settings
[
'ARCHS'
]
=
"armv6 armv7"
end
@target
.
build_settings
(
'Debug'
).
merge!
(
settings
)
@target
.
build_settings
(
'Release'
).
merge!
(
settings
)
@target
.
build_settings
(
'Debug'
).
merge!
(
settings
)
@target
.
build_settings
(
'Release'
).
merge!
(
settings
)
library
.
user_build_configurations
.
each
do
|
bc_name
,
type
|
@target
.
add_build_configuration
(
bc_name
,
type
)
end
library
.
user_build_configurations
.
each
do
|
bc_name
,
type
|
@target
.
add_build_configuration
(
bc_name
,
type
)
library
.
target
=
@target
end
library
.
target
=
@target
end
# Creates the group that holds the references to the support files
# generated by this installer.
#
# @return [void]
#
def
create_suport_files_group
@support_files_group
=
project
.
support_files_group
.
new_group
(
library
.
name
)
end
# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @return [void]
#
def
create_dummy_source
path
=
library
.
dummy_source_path
UI
.
message
"- Generating dummy source file at
#{
UI
.
path
(
path
)
}
"
do
generator
=
Generator
::
DummySource
.
new
(
library
.
label
)
generator
.
save_as
(
path
)
file_reference
=
add_file_to_support_group
(
path
)
target
.
source_build_phase
.
add_file_reference
(
file_reference
)
# Creates the group that holds the references to the support files
# generated by this installer.
#
# @return [void]
#
def
create_suport_files_group
@support_files_group
=
project
.
support_files_group
.
new_group
(
library
.
name
)
end
end
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader
:target
# Generates a dummy source file for each target so libraries that contain
# only categories build.
#
# @return [void]
#
def
create_dummy_source
path
=
library
.
dummy_source_path
UI
.
message
"- Generating dummy source file at
#{
UI
.
path
(
path
)
}
"
do
generator
=
Generator
::
DummySource
.
new
(
library
.
label
)
generator
.
save_as
(
path
)
file_reference
=
add_file_to_support_group
(
path
)
target
.
source_build_phase
.
add_file_reference
(
file_reference
)
end
end
private
# @return [PBXNativeTarget] the target generated by the installation
# process.
#
# @note Generated by the {#add_target} step.
#
attr_reader
:target
#-----------------------------------------------------------------------#
# @!group Private helpers.
private
# @return [Project] the Pods project of the sandbox.
#
def
project
sandbox
.
project
end
# @!group Private helpers.
#---------------------------------------------------------------------#
# @return [TargetDefinition] the target definition of the library
.
#
def
target_definition
library
.
target_definition
end
# @return [Project] the Pods project of the sandbox
.
#
def
project
sandbox
.
project
end
# @return [PBXGroup] the group where the file references to the support
# files should be stored.
#
attr_reader
:support_files_group
# @return [TargetDefinition] the target definition of the library.
#
def
target_definition
library
.
target_definition
end
# Adds a reference to the given file in the support group of this target.
#
# @param [Pathname] path
# The path of the file to which the reference should be added.
#
# @return [PBXFileReference] the file reference of the added file.
#
def
add_file_to_support_group
(
path
)
support_files_group
.
new_file
(
path
)
end
# @return [PBXGroup] the group where the file references to the support
# files should be stored.
#
attr_reader
:support_files_group
# Adds a reference to the given file in the support group of this target.
#
# @param [Pathname] path
# The path of the file to which the reference should be added.
#
# @return [PBXFileReference] the file reference of the added file.
#
def
add_file_to_support_group
(
path
)
support_files_group
.
new_file
(
path
)
end
#-----------------------------------------------------------------------#
#-----------------------------------------------------------------------#
end
end
end
end
end
spec/unit/installer/pods_project_generator/file_references_installer_spec.rb
View file @
d691d0bb
...
...
@@ -9,7 +9,7 @@ module Pod
@pod_target
.
file_accessors
=
[
@file_accessor
]
config
.
sandbox
.
project
=
Project
.
new
(
config
.
sandbox
.
project_path
)
config
.
sandbox
.
project
.
add_pod_group
(
'BananaLib'
,
fixture
(
'banana-lib'
))
@
installer
=
Installer
::
PodsProjectGenerator
::
FileReferencesInstaller
.
new
(
config
.
sandbox
,
[
@pod_target
])
@
sut
=
Installer
::
PodsProjectGenerator
::
FileReferencesInstaller
.
new
(
config
.
sandbox
,
[
@pod_target
])
end
#-------------------------------------------------------------------------#
...
...
@@ -19,18 +19,18 @@ module Pod
it
"adds the files references of the source files the Pods project"
do
@file_accessor
.
path_list
.
read_file_system
@file_accessor
.
path_list
.
expects
(
:read_file_system
)
@
installer
.
install!
@
sut
.
install!
end
it
"adds the files references of the source files the Pods project"
do
@
installer
.
install!
@
sut
.
install!
file_ref
=
config
.
sandbox
.
project
[
'Pods/BananaLib/Source Files/Banana.m'
]
file_ref
.
should
.
be
.
not
.
nil
file_ref
.
path
.
should
==
"Classes/Banana.m"
end
it
"adds the file references of the frameworks of the project"
do
@
installer
.
install!
@
sut
.
install!
group
=
config
.
sandbox
.
project
.
group_for_spec
(
'BananaLib'
,
:frameworks_and_libraries
)
file_ref
=
group
[
'Bananalib.framework'
]
file_ref
.
should
.
be
.
not
.
nil
...
...
@@ -38,7 +38,7 @@ module Pod
end
it
"adds the file references of the libraries of the project"
do
@
installer
.
install!
@
sut
.
install!
group
=
config
.
sandbox
.
project
.
group_for_spec
(
'BananaLib'
,
:frameworks_and_libraries
)
file_ref
=
group
[
'libBananalib.a'
]
file_ref
.
should
.
be
.
not
.
nil
...
...
@@ -46,7 +46,7 @@ module Pod
end
it
"adds the files references of the resources the Pods project"
do
@
installer
.
install!
@
sut
.
install!
file_ref
=
config
.
sandbox
.
project
[
'Pods/BananaLib/Resources/logo-sidebar.png'
]
file_ref
.
should
.
be
.
not
.
nil
file_ref
.
path
.
should
==
"Resources/logo-sidebar.png"
...
...
@@ -64,23 +64,23 @@ module Pod
pod_target_1
.
file_accessors
=
[
fixture_file_accessor
(
'banana-lib/BananaLib.podspec'
)]
pod_target_2
=
PodTarget
.
new
([],
nil
,
config
.
sandbox
)
pod_target_2
.
file_accessors
=
[
fixture_file_accessor
(
'banana-lib/BananaLib.podspec'
)]
installer
=
Installer
::
PodsProjectGenerator
::
FileReferencesInstaller
.
new
(
config
.
sandbox
,
[
pod_target_1
,
pod_target_2
])
roots
=
installer
.
send
(
:file_accessors
).
map
{
|
fa
|
fa
.
path_list
.
root
}
@sut
=
Installer
::
PodsProjectGenerator
::
FileReferencesInstaller
.
new
(
config
.
sandbox
,
[
pod_target_1
,
pod_target_2
])
roots
=
@sut
.
send
(
:file_accessors
).
map
{
|
fa
|
fa
.
path_list
.
root
}
roots
.
should
==
[
fixture
(
'banana-lib'
),
fixture
(
'banana-lib'
)]
end
it
"handles libraries empty libraries without file accessors"
do
pod_target_1
=
PodTarget
.
new
([],
nil
,
config
.
sandbox
)
pod_target_1
.
file_accessors
=
[]
installer
=
Installer
::
PodsProjectGenerator
::
FileReferencesInstaller
.
new
(
config
.
sandbox
,
[
pod_target_1
])
roots
=
installer
.
send
(
:file_accessors
).
should
==
[]
@sut
=
Installer
::
PodsProjectGenerator
::
FileReferencesInstaller
.
new
(
config
.
sandbox
,
[
pod_target_1
])
roots
=
@sut
.
send
(
:file_accessors
).
should
==
[]
end
end
describe
"#add_file_accessors_paths_to_pods_group"
do
it
"adds the paths of the paths of the file accessor corresponding to the given key to the Pods project"
do
@
installer
.
send
(
:add_file_accessors_paths_to_pods_group
,
:source_files
,
:source_files
)
@
sut
.
send
(
:add_file_accessors_paths_to_pods_group
,
:source_files
,
:source_files
)
group
=
config
.
sandbox
.
project
.
group_for_spec
(
'BananaLib'
,
:source_files
)
group
.
children
.
map
(
&
:name
).
sort
.
should
==
[
"Banana.h"
,
"Banana.m"
,
"BananaPrivate.h"
]
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