Skip to content
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

Support On-Demand Resource #622

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
## Master

##### Enhancements

* Support On-Demand Resource
[JunyiXie](https://github.com/JunyiXie)
[#issue_number](https://github.com/CocoaPods/Core/pull/622)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make this 622 instead of #issue_number


* Add a post_integrate_hook API
[lucasmpaim](https://github.com/lucasmpaim)
[#7432](https://github.com/CocoaPods/CocoaPods/issues/7432)
Expand Down
24 changes: 24 additions & 0 deletions lib/cocoapods-core/specification/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def user_target_xcconfig
merge_values(attr, value_for_attribute(:xcconfig), value_for_attribute(:user_target_xcconfig))
end

# @return [Hash{String=>String}]] hash where the keys are the names of
# the on demand resource and the values are their relative file
# patterns.
#
spec_attr_accessor :on_demand_resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want this to be a Hash that allows Pod authors to specify the tag (see my comment here)

example:

s.on_demand_resources = {
    'Tag1' => ['file1.png', 'file2.png']
}

we also may need to provide a way for Pod authors to specify the category of the tag. The category determines how the resource gets fetched. To quote the docs:

Initial install tags. The resources are downloaded at the same time as the app. The size of the resources is included in the total size for the app in the App Store. The tags can be purged when they are not being accessed by at least one NSBundleResourceRequest object.

Prefetch tag order. The resources start downloading after the app is installed. The tags will be downloaded in the order in which they are listed in the Prefetched tag order group.

Dowloaded only on demand. The tags are downloaded when requested by the app.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. I will refer to your design for implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation f240511


# @return [Hash{String => String}] the Info.plist values for the current specification
#
spec_attr_accessor :info_plist
Expand Down Expand Up @@ -473,6 +479,24 @@ def _prepare_resource_bundles(value)
result
end

# Ensures that the file patterns of the on demand resources are contained in
# an array.
#
# @param [String, Array, Hash] value.
# The value of the attribute as specified by the user.
#
# @return [Hash] the resources.
#
def _prepare_on_demand_resources(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a test for this logic?

result = {}
if value
value.each do |key, patterns|
result[key] = [*patterns].compact
end
end
result
end

#-----------------------------------------------------------------------#
end
end
Expand Down
21 changes: 21 additions & 0 deletions lib/cocoapods-core/specification/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,26 @@ def dependency=(args)

#------------------#

# @!method on_demand_resources=(on_demand_resources)
#
# A list of on_demand_resource that should be copied into the target bundle.
#
# @example
#
# s.on_demand_resources = {
# 'Tag1' => ['file1.png', 'file2.png']
# }
# @param [String, Array<String>] resources
# The on_demand_resources shipped with the Pod.
#
attribute :on_demand_resources,
:types => [String, Array],
:container => Hash,
:file_patterns => true,
:singularize => true

#------------------#

# @!method resource_bundles=(*resource_bundles)
#
# This attribute allows to define the name and the file of the resource
Expand Down Expand Up @@ -1370,6 +1390,7 @@ def dependency=(args)
:file_patterns => true,
:singularize => true


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unneeded?

#------------------#

# @!method exclude_files=(exclude_files)
Expand Down
5 changes: 5 additions & 0 deletions lib/cocoapods-core/specification/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def _validate_weak_frameworks(frameworks)
' specified by its name')
end
end

# Performs validations related to the `on_demand_resources` attribute.
#
def _validate_on_demand_resources(on_demand_resource)
end

# Performs validations related to the `libraries` attribute.
#
Expand Down