Remove Shell invocation as many as possible (high cost in term of speed of execution)
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit

This commit is contained in:
2022-09-02 15:57:20 +02:00
parent 8723019732
commit e3258453bb
15 changed files with 95 additions and 119 deletions

View File

@ -15,26 +15,29 @@ public class GeneratorChecker {
return true
}
// If inputFile is newer that generated extension -> Regenerate
let extensionFileURL = URL(fileURLWithPath: extensionFilePath)
let inputFileURL = URL(fileURLWithPath: inputFilePath)
let extensionRessourceValues = try? extensionFileURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey])
let inputFileRessourceValues = try? inputFileURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey])
if let extensionModificationDate = extensionRessourceValues?.contentModificationDate,
let inputFileModificationDate = inputFileRessourceValues?.contentModificationDate {
if inputFileModificationDate >= extensionModificationDate {
print("Input file is newer that generated extension.")
return true
} else {
return false
}
}
return Self.isFile(inputFilePath, moreRecenThan: extensionFilePath)
}
// ModificationDate not available for both file
print("⚠️ Could not compare file modication date. ⚠️")
return true
public static func isFile(_ fileOne: String, moreRecenThan fileTwo: String) -> Bool {
let fileOneURL = URL(fileURLWithPath: fileOne)
let fileTwoURL = URL(fileURLWithPath: fileTwo)
let fileOneRessourceValues = try? fileOneURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey])
let fileTwoRessourceValues = try? fileTwoURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey])
guard let fileOneModificationDate = fileOneRessourceValues?.contentModificationDate,
let fileTwoModificationDate = fileTwoRessourceValues?.contentModificationDate else {
print("⚠️ Could not compare file modication date. ⚠️ (assume than file is newer)")
// Date not available -> assume than fileOne is newer than fileTwo
return true
}
if fileOneModificationDate >= fileTwoModificationDate {
debugPrint("File one is more recent than file two.")
return true
}
return false
}
}