-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_duplicates_xcodeproj.rb
More file actions
69 lines (55 loc) · 1.8 KB
/
fix_duplicates_xcodeproj.rb
File metadata and controls
69 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
require 'xcodeproj'
require 'set'
# Open the project
project_path = '/Users/个人_local/macos-cat-pet/Sources/swift/Pets Therapy.xcodeproj'
project = Xcodeproj::Project.open(project_path)
puts "Opened project: #{project_path}"
puts "=" * 50
# Process each target
project.targets.each do |target|
puts "\nProcessing target: #{target.name}"
# Get the sources build phase
sources_phase = target.source_build_phase
next unless sources_phase
puts " Found #{sources_phase.files.count} files in Compile Sources"
# Track unique files by their file path
seen_files = Set.new
duplicates_removed = []
files_to_keep = []
sources_phase.files.each do |file|
if file.file_ref
file_path = file.file_ref.real_path.to_s rescue file.file_ref.path
file_name = File.basename(file_path)
# Create a unique key based on the file content, not the path
# This will catch iOS/macOS duplicates
unique_key = file_name
if seen_files.include?(unique_key)
duplicates_removed << file_path
puts " Removing duplicate: #{file_path}"
else
seen_files.add(unique_key)
files_to_keep << file
end
else
# Keep files without file_ref (shouldn't happen but be safe)
files_to_keep << file
end
end
if duplicates_removed.any?
puts " Removing #{duplicates_removed.count} duplicate(s)..."
# Clear and rebuild the files list
sources_phase.clear
files_to_keep.each do |file|
sources_phase.files << file
end
puts " Now has #{sources_phase.files.count} unique files"
else
puts " No duplicates found"
end
end
# Save the project
project.save
puts "\n" + "=" * 50
puts "Project saved successfully!"
puts "Please clean and rebuild in Xcode (Cmd+Shift+K, then Cmd+B)"