fix-carthage-paths.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'xcodeproj'
  2. require 'json'
  3. project_path = ARGV[0]
  4. project = Xcodeproj::Project.open(project_path)
  5. dependenciesGroup = project["Dependencies"]
  6. #Open dependencies-state.json file
  7. file = File.read(".build/dependencies-state.json")
  8. json = JSON.parse(file)
  9. dependenciesGroup.recursive_children_groups.each do |child|
  10. if !Dir.exists?(child.real_path)
  11. path = child.path
  12. stringArray = path.split(".build/checkouts/").last.split("/")
  13. repoNameInXcodeproj = stringArray[0]
  14. if !repoNameInXcodeproj.nil? and repoNameInXcodeproj.include? ".git-"
  15. repoName = repoNameInXcodeproj.split(".git-").first
  16. numberOfDependencies = json["object"]["dependencies"].count
  17. for i in 1..numberOfDependencies
  18. if json["object"]["dependencies"][i-1]["packageRef"]["name"] == repoName
  19. json["object"]["dependencies"][i-1]["subpath"] = repoNameInXcodeproj
  20. end
  21. end
  22. projectDir = ENV["PWD"]
  23. spmDirPath = Dir.glob("#{projectDir}/.build/checkouts/#{repoName}**").first
  24. xcodeprojDirPath = "#{projectDir}/.build/checkouts/#{repoNameInXcodeproj}"
  25. if !spmDirPath.eql? xcodeprojDirPath
  26. # Rename directory created by SPM to the name that Xcodeproj file already had
  27. FileUtils.mv spmDirPath, xcodeprojDirPath
  28. end
  29. end
  30. end
  31. end
  32. File.open(".build/dependencies-state.json","w") do |f|
  33. f.write(json.to_json)
  34. end