cocoapods-podfile_patch 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f77646a10d7c52a203f05f40f7aaf01c114bf53
4
- data.tar.gz: 7d0847e74adf0f08706038a25368360755c977cb
3
+ metadata.gz: 458241a69c9825a176500aa680c5f3529c1565f6
4
+ data.tar.gz: 39348fff4a039b73f68ab1edb75be9b9ccfdebf5
5
5
  SHA512:
6
- metadata.gz: 175f1f52932b1da20131980b0304c8a6512813247937ccf281c568f4c69abc143a2db483692cdf2f9fd1e540b8d4979c4240dcd29561b7fb31a99ddaf838eb03
7
- data.tar.gz: c69e2686993aec5f6af4bcf9a860e29f95fec20fe30890a78210d0af0bc1cbf485504e179934ea69f009c81ae6c87af65a7c1c834f0daac57284f2f63ab244a7
6
+ metadata.gz: 572effa83441d770ebe21c0596ae9f778d3f860744f2478addb3ea3480f808784d6c118174bdc5f23fdb6611528c27e72e769d09ed42d239456f34261bef279f
7
+ data.tar.gz: 5b5f96a44cfb9c67affb45c43e4a402ffaa489d2fb5d67b6a24501f2bde8a6dde90e593cf653aa4e19027b4a3fb8814e0ffcaca6e0cf4703e7d69074e2616b62
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPodfile_patch
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,8 +7,12 @@ require 'set'
7
7
 
8
8
  class PodfilePatch
9
9
 
10
- def main(podfile, patchfile_path)
11
-
10
+ ABSTRACT_PATCH_TARGET_NAME = "cocoapods-podfile_patch-fake-target"
11
+
12
+
13
+ def load_patch_target(podfile, patchfile_path)
14
+
15
+ # find patch file
12
16
  patch_file_path = Pathname.new(patchfile_path)
13
17
  if not patch_file_path.expand_path.file?
14
18
  podfile_root_path = Pathname.new(podfile.defined_in_file).dirname
@@ -18,37 +22,42 @@ class PodfilePatch
18
22
  Pod::UI.info "Podfile patch feature is enabled. (No patch file now.)"
19
23
  return
20
24
  end
25
+
26
+ # load patch file content. And add it to a abstract target
27
+ contents = File.read(patch_file_path)
28
+ podfile.target ABSTRACT_PATCH_TARGET_NAME do
29
+ podfile.instance_eval contents
30
+ end
31
+
32
+ # find the patch target and delete it in original podfile
33
+ root_target = podfile.root_target_definitions[0]
34
+ patch_target = root_target.children.find {|t| t.name == ABSTRACT_PATCH_TARGET_NAME }
35
+ root_target.children.delete(patch_target)
36
+
37
+ return patch_target
38
+ end
21
39
 
22
- patchfile = self.patchfile(patch_file_path)
23
- self.patch(podfile: podfile, with_podfile: patchfile)
24
-
40
+
41
+ def merge_patch_and_original_podfile(podfile, patch_target)
42
+
43
+ root_target = podfile.root_target_definitions[0]
44
+
45
+ # merge patch_target and original_target
46
+ patch_target.name = root_target.name
47
+ merge_target_definitions_dependency(root_target, patch_target)
48
+
25
49
  Pod::UI.titled_section "Podfile patch feature is enabled" do
26
50
  next unless Pod::UI.config.verbose?
27
51
  Pod::UI.section "Patchfile Info" do
28
- self.print_podfile_raw_dependencies patchfile
52
+ self.print_podfile_raw_dependencies patch_target
29
53
  end
30
54
  Pod::UI.section "Modified Podfile Info" do
31
- self.print_podfile_raw_dependencies podfile
55
+ self.print_podfile_raw_dependencies root_target
32
56
  end
33
57
  end
34
58
  end
35
59
 
36
60
 
37
-
38
- def patchfile(patch_file_path) # [Podfile]
39
- Pod::Podfile.from_ruby(patch_file_path)
40
- end
41
-
42
- def patch(podfile:, with_podfile: )
43
- original = podfile
44
- patch = with_podfile
45
-
46
- merge_target_definitions_dependency(
47
- podfile.root_target_definitions[0],
48
- patch.root_target_definitions[0]
49
- )
50
- end
51
-
52
61
  def merge_target_definitions_dependency(targetdef, patch_targetdef)
53
62
  # Demo Data
54
63
  # Original Target
@@ -224,7 +233,7 @@ class PodfilePatch
224
233
  end
225
234
  end
226
235
 
227
- def print_podfile_raw_dependencies(podfile)
236
+ def print_podfile_raw_dependencies(target)
228
237
 
229
238
  def print_target_def_and_its_dependencies(target_def, intend = "")
230
239
  puts "|\n"
@@ -235,10 +244,7 @@ class PodfilePatch
235
244
  print_target_def_and_its_dependencies(target_def, intend + " ")
236
245
  end
237
246
  end
238
- puts "#{podfile.defined_in_file}"
239
- podfile.root_target_definitions.each do |target_def|
240
- print_target_def_and_its_dependencies(target_def)
241
- end
247
+ print_target_def_and_its_dependencies(target)
242
248
  end
243
249
  end
244
250
 
@@ -38,13 +38,18 @@ module Pod
38
38
  # you do in podfile, i.e. your custom pod function or other plugins.
39
39
  #
40
40
  def use_patch_file!(patchfile_path = 'Podfile.patch')
41
- @enable_patch = true
42
- @patchfile_path = patchfile_path
43
-
44
- # check not in patchfile
45
- if self.defined_in_file.basename.to_s.downcase == Pathname.new(patchfile_path).basename.to_s.downcase
46
- raise "Cannot call `#{__method__}` in Podfile patchfile"
41
+
42
+ @current_patch_files ||= []
43
+ if @current_patch_files.include? patchfile_path
44
+ # Yes, you could even use it recureively, but don't use the same patch file.
45
+ raise "`use_patch_file!` called recursively. Most case is it's used in Patch file."
46
+ return
47
47
  end
48
+
49
+ @current_patch_files << patchfile_path
50
+ require 'cocoapods-podfile_patch/podfile_patch'
51
+ @patch_target = PodfilePatch.new.load_patch_target self, patchfile_path
52
+ @current_patch_files.delete(patchfile_path)
48
53
  end
49
54
 
50
55
  end
@@ -57,10 +62,8 @@ module Pod
57
62
  define_method(:initialize) do |defined_in_file = nil, internal_hash = {}, &block|
58
63
  old_initialize_function.bind(self).(defined_in_file, internal_hash, &block)
59
64
 
60
- if @enable_patch
61
- require 'cocoapods-podfile_patch/podfile_patch'
62
- patcher = PodfilePatch.new
63
- patcher.main(self, @patchfile_path)
65
+ if not @patch_target.nil?
66
+ PodfilePatch.new.merge_patch_and_original_podfile(self, @patch_target)
64
67
  end
65
68
  end
66
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-podfile_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gao