forked from grpc/grpc-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-carthage-paths.rb
45 lines (35 loc) · 1.53 KB
/
fix-carthage-paths.rb
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
require 'bundler/setup'
require 'xcodeproj'
require 'json'
project_path = ARGV[0]
project = Xcodeproj::Project.open(project_path)
dependenciesGroup = project["Dependencies"]
#Open dependencies-state.json file
file = File.read(".build/dependencies-state.json")
json = JSON.parse(file)
dependenciesGroup.recursive_children_groups.each do |child|
if !Dir.exists?(child.real_path)
path = child.path
stringArray = path.split(".build/checkouts/").last.split("/")
repoNameInXcodeproj = stringArray[0]
if !repoNameInXcodeproj.nil? and repoNameInXcodeproj.include? ".git-"
repoName = repoNameInXcodeproj.split(".git-").first
numberOfDependencies = json["object"]["dependencies"].count
for i in 1..numberOfDependencies
if json["object"]["dependencies"][i-1]["packageRef"]["name"] == repoName
json["object"]["dependencies"][i-1]["subpath"] = repoNameInXcodeproj
end
end
projectDir = ENV["PWD"]
spmDirPath = Dir.glob("#{projectDir}/.build/checkouts/#{repoName}**").first
xcodeprojDirPath = "#{projectDir}/.build/checkouts/#{repoNameInXcodeproj}"
if !spmDirPath.eql? xcodeprojDirPath
# Rename directory created by SPM to the name that Xcodeproj file already had
FileUtils.mv spmDirPath, xcodeprojDirPath
end
end
end
end
File.open(".build/dependencies-state.json","w") do |f|
f.write(json.to_json)
end