Bugfix/empty resources (#1829)
* Skip synthesizing accessors for empty resource. * Add documentation for disableSynthesizedResourceAccessors. * Change .notice to .warning. * Edit changelog. * Fix reading text file.
This commit is contained in:
parent
41c3c422c7
commit
493cf13d3f
|
@ -4,6 +4,10 @@ Please, check out guidelines: https://keepachangelog.com/en/1.0.0/
|
|||
|
||||
## Next
|
||||
|
||||
### Fixed
|
||||
|
||||
- Skip synthesizing resource accessors when the file/folder is empty [#1829](https://github.com/tuist/tuist/pull/1829) by [@fortmarek](https://github.com/fortmarek)
|
||||
|
||||
## 1.19.0 - Milano
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -90,7 +90,8 @@ public final class SynthesizedResourceInterfaceProjectMapper: ProjectMapping {
|
|||
.appending(component: Constants.DerivedDirectory.name)
|
||||
.appending(component: Constants.DerivedDirectory.sources)
|
||||
|
||||
let paths = self.paths(for: synthesizedResourceInterfaceType, target: target)
|
||||
let paths = try self.paths(for: synthesizedResourceInterfaceType, target: target)
|
||||
.filter(isResourceEmpty)
|
||||
|
||||
let renderedInterfaces: [(String, String)]
|
||||
|
||||
|
@ -195,4 +196,17 @@ public final class SynthesizedResourceInterfaceProjectMapper: ProjectMapping {
|
|||
.filter { $0.extension.map(fontExtensions.contains) ?? false }
|
||||
}
|
||||
}
|
||||
|
||||
private func isResourceEmpty(_ path: AbsolutePath) throws -> Bool {
|
||||
if FileHandler.shared.isFolder(path) {
|
||||
if try !FileHandler.shared.contentsOfDirectory(path).isEmpty { return true }
|
||||
} else {
|
||||
if try !FileHandler.shared.readFile(path).isEmpty { return true }
|
||||
}
|
||||
logger.log(
|
||||
level: .warning,
|
||||
"Skipping synthesizing accessors for \(path.pathString) because it's contents are empty."
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,20 +36,26 @@ final class SynthesizedResourceInterfaceProjectMapperTests: TuistUnitTestCase {
|
|||
let projectPath = try temporaryPath()
|
||||
let targetAPath = projectPath.appending(component: "TargetA")
|
||||
let aAssets = targetAPath.appending(component: "a.xcassets")
|
||||
let aAsset = aAssets.appending(component: "asset")
|
||||
let frenchStrings = targetAPath.appending(components: "fr.lproj", "aStrings.strings")
|
||||
let englishStrings = targetAPath.appending(components: "en.lproj", "aStrings.strings")
|
||||
let environmentPlist = targetAPath.appending(component: "Environment.plist")
|
||||
let emptyPlist = targetAPath.appending(component: "Empty.plist")
|
||||
let ttfFont = targetAPath.appending(component: "ttfFont.ttf")
|
||||
let otfFont = targetAPath.appending(component: "otfFont.otf")
|
||||
let ttcFont = targetAPath.appending(component: "ttcFont.ttc")
|
||||
|
||||
try fileHandler.createFolder(aAssets)
|
||||
try fileHandler.touch(aAsset)
|
||||
try fileHandler.touch(frenchStrings)
|
||||
try fileHandler.touch(englishStrings)
|
||||
try fileHandler.touch(environmentPlist)
|
||||
try fileHandler.touch(ttfFont)
|
||||
try fileHandler.touch(otfFont)
|
||||
try fileHandler.touch(ttcFont)
|
||||
try fileHandler.write("a", path: frenchStrings, atomically: true)
|
||||
try fileHandler.write("a", path: englishStrings, atomically: true)
|
||||
try fileHandler.touch(emptyPlist)
|
||||
try fileHandler.write("a", path: environmentPlist, atomically: true)
|
||||
try fileHandler.write("a", path: ttfFont, atomically: true)
|
||||
try fileHandler.write("a", path: otfFont, atomically: true)
|
||||
try fileHandler.write("a", path: ttcFont, atomically: true)
|
||||
|
||||
let targetA = Target.test(
|
||||
name: "TargetA",
|
||||
|
@ -57,6 +63,7 @@ final class SynthesizedResourceInterfaceProjectMapperTests: TuistUnitTestCase {
|
|||
.folderReference(path: aAssets),
|
||||
.file(path: frenchStrings),
|
||||
.file(path: englishStrings),
|
||||
.file(path: emptyPlist),
|
||||
.file(path: environmentPlist),
|
||||
.file(path: ttfFont),
|
||||
.file(path: otfFont),
|
||||
|
@ -135,5 +142,11 @@ final class SynthesizedResourceInterfaceProjectMapperTests: TuistUnitTestCase {
|
|||
]
|
||||
)
|
||||
)
|
||||
|
||||
XCTAssertPrinterContains(
|
||||
"Skipping synthesizing accessors for \(emptyPlist.pathString) because it's contents are empty.",
|
||||
at: .warning,
|
||||
==
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,11 @@ Generation options allow customizing the generation of Xcode projects.
|
|||
description:
|
||||
'Suppress logging of environment in Run Script build phases',
|
||||
},
|
||||
{
|
||||
case: '.disableSynthesizedResourceAccessors',
|
||||
description:
|
||||
'Do not automatically synthesize resource accessors (assets, localized strings, etc.)',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
|
|
Loading…
Reference in New Issue