xcmv 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 456870dbe3e27ce5b5a643e968015b80d9e4db00
4
- data.tar.gz: 3afa9566039e0b74f5bf2781540e6012aedd8963
3
+ metadata.gz: 4b1211a94c5f7daff4383d3aa05a5c20a65c66da
4
+ data.tar.gz: add87d0f05d8d163d14543b75fc131b0f49f9995
5
5
  SHA512:
6
- metadata.gz: 29d8ca18f07edebe74a993404eb291c07cfd0c34d56290f0f0a4b153f11d748fcb072be3a84f3687b235de352d8e6b05d614dc47513f2042d88d8868130178d6
7
- data.tar.gz: 7725808f9f589869d8d262db3d7ec6d17e843a7a98f3819932e71448ba9c1322b7fa1c1d41f2fae1e9c26d773872984222950c2136ca090b9c89867b5b9088bb
6
+ metadata.gz: 786a56f236c0f476ca80987dba5da88ca67a420e22fa614fe03a6599d8edc95f9a1b6b71eb77e1d2a62c82d49ccadd4b8f1e9014b317101fd2dc70dec4972292
7
+ data.tar.gz: 5042a1ac63777486ee675d0f8e1439636c8a0fc255c847e85579638d9c4a4180cf020b32d49302d1121f84a2f22e6150d1373a370c5fb74558b7f56fd468e143
data/lib/xcmv/file.rb CHANGED
@@ -57,11 +57,19 @@ module XcodeMove
57
57
  def add_to_targets(target_names, header_visibility)
58
58
  unless target_names
59
59
  group = GroupMembership.new(pbx_file.parent)
60
- targets = group.sibling_targets
60
+ targets = group.inferred_targets
61
+
62
+ if targets.empty?
63
+ # fallback: if we can't infer any target membership,
64
+ # we just assign the first target of the project and emit a warning
65
+ fallback_target = project.targets.select{ |t| t.respond_to?(:source_build_phase) }[0]
66
+ targets = [fallback_target]
67
+ warn "⚠️ Warning: Unable to infer target membership of #{path} -- assigning to #{fallback_target.name}."
68
+ end
61
69
  else
62
70
  name_set = target_names.to_set
63
71
  targets = project.targets.select{ |t| name_set.include?(t.name) }
64
- abort "No targets found in #{target_names}" if targets.empty?
72
+ abort "🛑 Error: No targets found in #{target_names}." if targets.empty?
65
73
  end
66
74
 
67
75
  targets.each do |target|
@@ -1,18 +1,34 @@
1
+ class Xcodeproj::Project::Object::PBXGroup
2
+ # Returns an array of targets that have build files in `group`.
3
+ def sibling_targets
4
+ siblings = children.to_set
5
+ compiled_targets = project.targets.select{ |t| t.respond_to?(:source_build_phase) }
6
+ compiled_targets.select{ |t| t.source_build_phase.files_references.any?{ |f| siblings.include?(f) } }
7
+ end
8
+ end
1
9
 
2
10
  module XcodeMove
3
11
  class GroupMembership
12
+ attr_reader :group, :project
4
13
  def initialize(group)
5
14
  @group = group
6
15
  @project = group.project
7
16
  @siblings = @group.children.to_set
8
17
  end
9
18
 
10
- # Returns an array of targets that have build files in `group`.
11
- def sibling_targets
12
- compiled_targets = @project.targets.select{ |t| t.respond_to?(:source_build_phase) }
13
- compiled_targets.select{ |t| t.source_build_phase.files_references.any?{ |f| @siblings.include?(f) } }
19
+ # Returns an array of targets that the `group` should reasonably
20
+ # belong to -- either based on `sibling_targets` or the `sibling_targets`
21
+ # of some ancestor group.
22
+ def inferred_targets
23
+ target_group = self.group
24
+ targets = []
25
+ while targets.empty? and target_group.respond_to?(:sibling_targets) do
26
+ targets += target_group.sibling_targets
27
+ target_group = target_group.parent
28
+ end
29
+ targets
14
30
  end
15
-
31
+
16
32
  def max_header_visibility(target)
17
33
  sibling_headers = target.headers_build_phase.files.filter{ |f| @siblings.include?(file_ref) }
18
34
  sibling_headers.map{ |f| HeaderVisibility.from_file_settings(f.settings) }.max
data/lib/xcmv/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module XcodeMove
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
data/lib/xcmv.rb CHANGED
@@ -10,7 +10,7 @@ module XcodeMove
10
10
  # Moves from one `Pathname` to another
11
11
  def self.mv(src, dst, options)
12
12
  src_file = src.directory? ? Group.new(src) : File.new(src)
13
- dst_file = src_file.with_dirname(dst)
13
+ dst_file = src_file.with_dirname(dst.dirname)
14
14
 
15
15
  puts("#{src_file.path} => #{dst_file.path}")
16
16
 
@@ -45,7 +45,7 @@ module XcodeMove
45
45
  if src_file.pbx_file
46
46
  src_file.remove_from_project
47
47
  else
48
- warn("warning: #{src_file.path.realdirpath} not found in #{src_file.project.path.basename}. moving anyway...")
48
+ warn("⚠️ Warning: #{src.path.basename} not found in #{src.project.path.basename}, moving anyway...")
49
49
  end
50
50
  end
51
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcmv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliott Williams