Skip to content
Browse files

[LocalSource] Initial draft.

  • Loading branch information...
1 parent b09ccf1 commit 8a4f5ac08034933e095aa0bddb9300084c9a6978 @fabiopelosin fabiopelosin committed
View
31 lib/cocoapods/dependency.rb
@@ -138,6 +138,8 @@ def self.from_params(name, params)
GitSource.new(name, params)
elsif params.key?(:podspec)
PodspecSource.new(name, params)
+ elsif params.key?(:local)
+ LocalSource.new(name, params)
else
raise Informative, "Unknown external source parameters for #{name}: #{params}"
end
@@ -211,6 +213,35 @@ def description
"from `#{@params[:podspec]}'"
end
end
+
+ class LocalSource < AbstractExternalSource
+ def pod_spec_path
+ root = Pathname.new(@params[:local])
+ path = spec_path = Dir[root + "*.podspec"].first
+ Pathname.new(path)
+ end
+
+ def copy_external_source_into_sandbox(sandbox, _)
+ output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
+ output_path.dirname.mkpath
+ FileUtils.copy(pod_spec_path, output_path)
+ end
+
+ def specification_from_local(sandbox, platform)
+ specification_from_external(sandbox, platform)
+ end
+
+ def specification_from_external(sandbox, platform)
+ copy_external_source_into_sandbox(sandbox, platform)
+ spec = Specification.from_file(pod_spec_path)
+ spec.source = @params
+ spec
+ end
+
+ def description
+ "from `#{@params[:local]}'"
+ end
+ end
end
end
end
View
12 lib/cocoapods/installer.rb
@@ -21,7 +21,11 @@ def project
@project.user_build_configurations = @podfile.user_build_configurations
pods.each do |pod|
# Add all source files to the project grouped by pod
- group = @project.add_pod_group(pod.name)
+ if pod.local?
+ group = @project.add_local_pod_group(pod.name)
+ else
+ group = @project.add_pod_group(pod.name)
+ end
pod.relative_source_files.each do |path|
group.files.new('path' => path.to_s)
end
@@ -192,7 +196,11 @@ def pods_by_target
specs_by_target.each do |target_definition, specs|
@pods_by_spec[target_definition.platform] = {}
result[target_definition] = specs.map do |spec|
- @sandbox.local_pod_for_spec(spec, target_definition.platform)
+ if spec.local?
+ LocalPod::LocalSourcedPod.new(spec, sandbox, target_definition.platform)
+ else
+ @sandbox.local_pod_for_spec(spec, target_definition.platform)
+ end
end.uniq.compact
end
result
View
42 lib/cocoapods/local_pod.rb
@@ -98,9 +98,7 @@ def root
# the pods comes from a local source.
#
def to_s
- result = top_specification.to_s
- result << " [LOCAL]" if top_specification.local?
- result
+ top_specification.to_s
end
# @return [String] The name of the Pod.
@@ -142,6 +140,10 @@ def implode
root.rmtree if exists?
end
+ def local?
+ false
+ end
+
# @!group Cleaning
# Deletes any path that is not used by the pod.
@@ -501,5 +503,39 @@ def expanded_paths(patterns, options = {})
Pathname.glob(pattern, File::FNM_CASEFOLD)
end.flatten
end
+
+ # A {LocalSourcedPod} is a {LocalPod} that interacts with the files of
+ # a folder controlled by the users. As such this class does not alter
+ # in any way the contents of the folder.
+ #
+ class LocalSourcedPod < LocalPod
+ def downloaded?
+ true
+ end
+
+ def create
+ # No ops
+ end
+
+ def root
+ Pathname.new(@top_specification.defined_in_file).dirname
+ end
+
+ def implode
+ # No ops
+ end
+
+ def clean!
+ # No ops
+ end
+
+ def to_s
+ super + " [LOCAL]"
+ end
+
+ def local?
+ true
+ end
+ end
end
end
View
6 lib/cocoapods/project.rb
@@ -39,6 +39,12 @@ def add_pod_group(name)
pods.groups.new('name' => name)
end
+ # Adds a group as child to the `Local Pods' group.
+ def add_local_pod_group(name)
+ local_pods = groups.find { |g| g.name == 'Local Pods' } || groups.new({ 'name' => 'Local Pods' })
+ local_pods.groups.new('name' => name)
+ end
+
def add_pod_target(name, platform)
target = targets.new_static_library(platform.name, name)
View
4 lib/cocoapods/specification.rb
@@ -389,10 +389,6 @@ def local?
!source.nil? && !source[:local].nil?
end
- def local_path
- Pathname.new(File.expand_path(source[:local]))
- end
-
def pod_destroot
if local?
local_path

0 comments on commit 8a4f5ac

Please sign in to comment.
Something went wrong with that request. Please try again.