A CocoaPods source that discovers podspecs locally.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Pod | |
class LocalDependenciesSource < Source | |
attr_reader :sandbox | |
attr_reader :local_podspecs_by_name | |
def self.register(plugin_name, sandbox, local_podspec_dependencies) | |
return unless local_podspec_dependencies | |
# Register a source that can be used to provide local podspecs | |
HooksManager.register(plugin_name, :source_provider) do |context| | |
context.add_source(LocalDependenciesSource.new(sandbox, local_podspec_dependencies)) | |
end | |
end | |
def initialize(sandbox, podspec_paths) | |
@repo = Pathname(Dir.pwd).expand_path | |
@sandbox = sandbox | |
@local_podspecs_by_name = parse_local_podspec_dependencies(podspec_paths) | |
end | |
# Methods overrides for Pod::Source (Based on CocoaPods 1.3.1) | |
def name | |
'LocalDependenciesSource' | |
end | |
def versions(name) | |
return local_podspecs_by_name[name][:versions] | |
end | |
def specification_path(name, version) | |
Pathname(File.join(Dir.pwd, local_podspecs_by_name[name][:path])) | |
end | |
def search(query) | |
podspec_name = query.name | |
# Check if we have been told where to find this dependency | |
return unless local_podspecs_by_name.keys.include?(podspec_name) | |
# Add the podspec to the sandbox so it will be treated as a local dependency | |
podspec_path = local_podspecs_by_name[podspec_name][:path] | |
# Use the version from the Podspec as the source of truth | |
spec = Specification.from_file(podspec_path) | |
local_podspecs_by_name[podspec_name][:versions] = [spec.version] | |
# Load the local path podspec into the sandbox for dependency resolver to know these as "local dependecies" | |
local_podspec = Pod::ExternalSources::PathSource.new(podspec_name, { path: File.expand_path(podspec_path, Dir.pwd) }, Dir.pwd) | |
local_podspec.fetch(sandbox) | |
# return the podspec | |
Specification::Set.new(query.name, self) | |
end | |
# Block any unnecessary Pod::Source methods to make failure point obvious on a CocoaPods upgrades | |
def specs_dir | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
def url | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
def pod_path(name) | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
def pods_for_specification_paths(spec_paths) | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
def pods | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
def update(show_output) | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
def git? | |
raise Informative, 'Unused for the purposes of the LocalDependenciesSource' | |
end | |
private | |
def parse_local_podspec_dependencies(local_podspec_paths) | |
parsed_podspecs = {} | |
local_podspec_paths.each do |podspec_path| | |
spec = Specification.from_file(podspec_path) | |
parsed_podspecs[spec.name] = { path: podspec_path } | |
end | |
parsed_podspecs | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment