fix-carthage-paths.rb 1.5 KB

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