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

Failed to generate code with SwiftTemplate with (at least) custom build path / custom cache path #1349

Closed
pavel-trafimuk opened this issue Jul 17, 2024 · 3 comments

Comments

@pavel-trafimuk
Copy link
Contributor

pavel-trafimuk commented Jul 17, 2024

After updating up to 2.2.5 my ymls with swifttemplate start failing.
Sourcery argument:
--config tools/sourcery/generated/phase_02/Settings/SettingsContainer.yml -v -p --cacheBasePath tools/sourcery/customCache --buildPath tools/sourcery/customSwiftTemplateBuilds/5811391726280627442

Error:

Generating code...
Rendering template /Users/pavel.trafimuk/Developer/_censored_/tools/sourcery/templates/settings-gen/SettingsContainer.swifttemplate
Reusing built SwiftTemplate binary for SwiftTemplate with cache key: MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK/KJLgPAPLY=...
Binary file location: /Users/pavel.trafimuk/Developer/_censored_/tools/sourcery/customSwiftTemplateBuilds/5811391726280627442/SwiftTemplate/F5970073-49DA-483D-A452-98C9960123B9/2.2.5/MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%2FKJLgPAPLY%3D
Reusing built SwiftTemplate binary for SwiftTemplate with cache key: MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK/KJLgPAPLY=...
error: Error Domain=NSCocoaErrorDomain Code=516 "The file “MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%2FKJLgPAPLY%3D” couldn’t be saved in the folder “2.2.5” because a file with the same name already exists." UserInfo={NSURL=file:///Users/pavel.trafimuk/Developer/_censored_/tools/sourcery/customSwiftTemplateBuilds/5811391726280627442/SwiftTemplate/F5970073-49DA-483D-A452-98C9960123B9/2.2.5/MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%252FKJLgPAPLY%253D, NSUnderlyingError=0x600000c642a0 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}, NSFilePath=/Users/pavel.trafimuk/Developer/_censored_/tools/sourcery/customSwiftTemplateBuilds/5811391726280627442/SwiftTemplate/F5970073-49DA-483D-A452-98C9960123B9/2.2.5/MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%2FKJLgPAPLY%3D}
Error Domain=NSCocoaErrorDomain Code=516 "The file “MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%2FKJLgPAPLY%3D” couldn’t be saved in the folder “2.2.5” because a file with the same name already exists." UserInfo={NSURL=file:///Users/pavel.trafimuk/Developer/_censored_/tools/sourcery/customSwiftTemplateBuilds/5811391726280627442/SwiftTemplate/F5970073-49DA-483D-A452-98C9960123B9/2.2.5/MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%252FKJLgPAPLY%253D, NSUnderlyingError=0x600000c642a0 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}, NSFilePath=/Users/pavel.trafimuk/Developer/_censored_/tools/sourcery/customSwiftTemplateBuilds/5811391726280627442/SwiftTemplate/F5970073-49DA-483D-A452-98C9960123B9/2.2.5/MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%2FKJLgPAPLY%3D}%            

After quick investigation,
code if FileManager.default.fileExists(atPath: originalBinaryPath.string) { doesn't work correctly,

(lldb) po originalBinaryPath.string
"/Users/pavel.trafimuk/Developer/Viber_iOS_2/tools/sourcery/customSwiftTemplateBuilds/5811391726280627442/SwiftTemplate/71EA0DA5-E3EF-4AAC-998C-3EC9A3B9B5BF/2.2.5/MI6b0Z6LKDJ0eIbHkx7BmAltVogLlLDJK%2FKJLgPAPLY%3D"

But symlink exists
Zrzut ekranu 2024-07-17 o 13 16 08

@pavel-trafimuk
Copy link
Contributor Author

Updated, got it, FileManager resolves symlink before checking of file existing, so symlink is broken, after checking it I found that yes, seems like I reproduce issue #1321 cause destinationBinaryPath = cachePath + hashPath based on cachedPath which is relative

@pavel-trafimuk
Copy link
Contributor Author

Zrzut ekranu 2024-07-17 o 13 26 31 probable quick fix, wdyt @art-divin

@art-divin
Copy link
Collaborator

If it works in your case, it shouldn also in others'!

So much thanks, very appreciated 🙌🏻👏 - you contribution.

If you can commit this, it'd be just 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants