Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Folders To Patch #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/XcodeSurgery-CLI/Transplant/Transplant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ extension XcodeSurgery {

@Option(name: .customLong("filesToRemove"),
parsing: .upToNextOption,
help: "Files to remove (separated by spaces)")
help: "Files to remove (separated by comma)")
var filesToRemove: [String] = []

@Option(name: .customLong("filesToInject"),
parsing: .upToNextOption,
help: "Files to inject (separated by spaces)")
var filesToInject: [String] = []

@Option(name: .customLong("foldersToPatch"),
help: "Folder to patch over with (separated by comma)")
var foldersToPatch: [String] = []


@Option(name: [.customLong("debugInformationFormat"),
.customLong("dif")],
Expand Down
26 changes: 25 additions & 1 deletion Sources/XcodeSurgery-CLI/Transplant/TransplantActionable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extension TransplantActionable {

func removeFiles() throws {
XcodeSurgery.log("----- begin removeFiles")
let filesToRemove = self.transplantCommand.filesToRemove
let filesToRemoveBeforeSplit = self.transplantCommand.filesToRemove.joined(separator: ",")
let filesToRemove = filesToRemoveBeforeSplit.split(separator: ",")
XcodeSurgery.log("filesToRemove: \(filesToRemove)")
let fileManager = FileManager.default
try fileManager.removeItem(atPath: "\(self.pathOfWorkingFolder)/Info.plist")
Expand All @@ -54,6 +55,29 @@ extension TransplantActionable {
try fileManager.copyItem(atPath: fileToInject,
toPath: destination)
}

let foldersToPatch = self.transplantCommand.foldersToPatch
let workingDirectory = self.transplantCommand.workingDirectory
for folderToPatch in foldersToPatch {

guard let folderToPatchURL = URL(string: folderToPatch) else {
throw NSError(domain: "Invalid file url: \(folderToPatch)", code: 0, userInfo: nil)
}
let folderName = folderToPatchURL.lastPathComponent
let destination = "\(pathOfWorkingFolder)/\(folderName)"

XcodeSurgery.log("------- workingDirectory: \(workingDirectory)")
XcodeSurgery.log("------- pathOfWorkingFolder: \(pathOfWorkingFolder)")
XcodeSurgery.log("------- folderToPatch: \(folderToPatch)")
XcodeSurgery.log("------- destination: \(destination)")

guard let destinationURL = URL(string: destination) else {
throw NSError(domain: "Invalid file url: \(destination)", code: 0, userInfo: nil)
}
try _ = fileManager.replaceItemAt(destinationURL, withItemAt: folderToPatchURL, options: [.usingNewMetadataOnly])

XcodeSurgery.log("------- [ok]folderToPatch OK")
}
}

func renameBinary() throws {
Expand Down
Loading