-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add podspec script_phases
DSL
#413
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,6 +352,14 @@ def prefix_header_file | |
attributes_hash['prefix_header_file'] | ||
end | ||
|
||
# @return [Array<Hash{Symbol=>String}>] The script_phases value. | ||
# | ||
def script_phases | ||
attributes_hash['script_phases'].map do |script_phase| | ||
Specification.convert_keys_to_symbol(script_phase) | ||
end | ||
end | ||
|
||
#-------------------------------------------------------------------------# | ||
|
||
public | ||
|
@@ -376,11 +384,6 @@ def local? | |
# | ||
# @overload supported_on_platform?(symbolic_name, deployment_target) | ||
# | ||
# @param [Symbol] symbolic_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused params, deleted the doc |
||
# the name of the platform which is checked for support. | ||
# | ||
# @param [String] deployment_target | ||
# the deployment target which is checked for support. | ||
# | ||
def supported_on_platform?(*platform) | ||
platform = Platform.new(*platform) | ||
|
@@ -462,7 +465,7 @@ def platform_hash | |
# @param [Object] value | ||
# the value to store. | ||
# | ||
# @param [Symbol] platform. | ||
# @param [Symbol] platform_name | ||
# If provided the attribute is stored only for the given platform. | ||
# | ||
# @note If the provides value is Hash the keys are converted to a string. | ||
|
@@ -471,7 +474,7 @@ def platform_hash | |
# | ||
def store_attribute(name, value, platform_name = nil) | ||
name = name.to_s | ||
value = convert_keys_to_string(value) if value.is_a?(Hash) | ||
value = Specification.convert_keys_to_string(value) if value.is_a?(Hash) | ||
value = value.strip_heredoc.strip if value.respond_to?(:strip_heredoc) | ||
if platform_name | ||
platform_name = platform_name.to_s | ||
|
@@ -495,25 +498,40 @@ def store_attribute(name, value, platform_name = nil) | |
end | ||
end | ||
|
||
private | ||
|
||
# Converts the keys of the given hash to a string. | ||
# | ||
# @param [Object] value | ||
# the value that needs to be stripped from the Symbols. | ||
# | ||
# @return [Hash] the hash with the strings instead of the keys. | ||
# | ||
def convert_keys_to_string(value) | ||
def self.convert_keys_to_string(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for symmetry, decided to make this a class method as well as it maintains no state. |
||
return unless value | ||
result = {} | ||
value.each do |key, subvalue| | ||
subvalue = convert_keys_to_string(subvalue) if subvalue.is_a?(Hash) | ||
subvalue = Specification.convert_keys_to_string(subvalue) if subvalue.is_a?(Hash) | ||
result[key.to_s] = subvalue | ||
end | ||
result | ||
end | ||
|
||
# Converts the keys of the given hash to a string. | ||
# | ||
# @param [Object] value | ||
# the value that needs to be stripped from the Symbols. | ||
# | ||
# @return [Hash] the hash with the strings instead of the keys. | ||
# | ||
def self.convert_keys_to_symbol(value) | ||
return unless value | ||
result = {} | ||
value.each do |key, subvalue| | ||
subvalue = Specification.convert_keys_to_symbol(subvalue) if subvalue.is_a?(Hash) | ||
result[key.to_sym] = subvalue | ||
end | ||
result | ||
end | ||
|
||
#-------------------------------------------------------------------------# | ||
|
||
public | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,11 @@ def user_target_xcconfig | |
# | ||
spec_attr_accessor :resource_bundles | ||
|
||
# @return [Array<Hash{Symbol=>String}>] An array of hashes where each hash | ||
# represents a script phase. | ||
# | ||
spec_attr_accessor :script_phases | ||
|
||
# @return [Array<String>] A hash where the key represents the | ||
# paths of the resources to copy and the values the paths of | ||
# the resources that should be copied. | ||
|
@@ -324,7 +329,11 @@ def merge_values(attr, existing_value, new_value) | |
# | ||
def prepare_value(attr, value) | ||
if attr.container == Array | ||
value = [*value].compact | ||
value = if value.is_a?(Hash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @segiddins this is the primary fix that helps me accomplish this. Basically I want to the container to be an "Array" for this attribute since I want to preserve the order in which the script phases are added. However, without this change the Hash becomes an array and then I lose the ability to recreate the hashes from the arrays. This is the first attribute that requires an array of hashes so this is probably why I hit this. |
||
[value] | ||
else | ||
[*value].compact | ||
end | ||
end | ||
|
||
hook_name = prepare_hook_name(attr) | ||
|
@@ -362,6 +371,21 @@ def _prepare_prefix_header_contents(value) | |
end | ||
end | ||
|
||
# Converts the array of hashes (script phases) where keys are strings into symbols. | ||
# | ||
# @param [Array<Hash{String=>String}>] value. | ||
# The value of the attribute as specified by the user. | ||
# | ||
# @return [Array<Hash{Symbol=>String}>] the script phases array with symbols for each hash instead of strings. | ||
# | ||
def _prepare_script_phases(value) | ||
if value | ||
value.map do |script_phase| | ||
Specification.convert_keys_to_symbol(script_phase) if script_phase.is_a?(Hash) | ||
end.compact | ||
end | ||
end | ||
|
||
# Ensures that the file patterns of the resource bundles are contained in | ||
# an array. | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1134,7 +1134,7 @@ def dependency(*args) | |
|
||
#------------------# | ||
|
||
# @!method resource_bundles=(*frameworks) | ||
# @!method resource_bundles=(*resource_bundles) | ||
# | ||
# This attribute allows to define the name and the file of the resource | ||
# bundles which should be built for the Pod. They are specified as a | ||
|
@@ -1272,6 +1272,46 @@ def dependency(*args) | |
attribute :module_map, | ||
:root_only => true | ||
|
||
#------------------# | ||
|
||
SCRIPT_PHASE_REQUIRED_KEYS = [:name, :script].freeze | ||
|
||
SCRIPT_PHASE_OPTIONAL_KEYS = [:shell_path, :input_files, :output_files, :show_env_vars_in_log].freeze | ||
|
||
ALL_SCRIPT_PHASE_KEYS = (SCRIPT_PHASE_REQUIRED_KEYS + SCRIPT_PHASE_OPTIONAL_KEYS).freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spec linter should validate this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeap working on that as we speak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests added |
||
|
||
# @!method script_phases=(*script_phases) | ||
# | ||
# This attribute allows to define a script phase to execute as part of compilation of the Pod. | ||
# Unlike a prepare command, script phases execute as part of `xcodebuild` they can also utilize all environment | ||
# variables that are set during compilation. | ||
# | ||
# A Pod can provide multiple script phases to execute and they will be added in the order they were | ||
# declared. | ||
# | ||
# @example | ||
# | ||
# spec.script_phase = { :name => 'Hello World', :script => 'echo "Hello World"' } | ||
# | ||
# @example | ||
# | ||
# spec.script_phase = { :name => 'Hello World', :script => 'puts "Hello World"', :shell_path => '/usr/bin/ruby' } } | ||
# | ||
# @example | ||
# | ||
# spec.script_phases = [ | ||
# { :name => 'Hello World', :script => 'echo "Hello World"' }, | ||
# { :name => 'Hello Ruby World', :script => 'puts "Hello World"', :shell_path => '/usr/bin/ruby' } }, | ||
# ] | ||
# | ||
# @param [Array<Hash{Symbol=>String}>] script_phases | ||
# An array of hashes where each hash represents a single script phase. | ||
# | ||
attribute :script_phases, | ||
:types => [Hash], | ||
:container => Array, | ||
:singularize => true | ||
|
||
#-----------------------------------------------------------------------# | ||
|
||
# @!group Subspecs | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thosed moved to
specification.rb
, no logical changes here.