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

Fixed Issue when Caching of SwiftTemplate Binary Fails #1323

Merged
merged 2 commits into from
Apr 14, 2024

Conversation

art-divin
Copy link
Collaborator

Context

Currently, whenever Sourcery is done with compiling SwiftTemplate executable binary, it tries to move this binary into a shared cache folder.

However, if Sourcery is executed concurrently, i.e. sourcery binary is launched multiple times with a same .swifttemplate, an error is thrown because one of the sourcery executions was able to move the same file from within a guarding if statement:

Error Domain=NSCocoaErrorDomain Code=516 "“SwiftTemplate” couldn’t be moved to “Equality.swifttemplate” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/var/folders/90/8tcwdk19055d0rrgfp00h25h0000gn/T/SwiftTemplate/4F2C1EC9-D4B9-44BE-A854-1F6BAAFD5113/Major.Minor.Patch/.build/release/SwiftTemplate, NSUserStringVariant=(
    Move
), NSDestinationFilePath=/Users/art-divin/Library/Caches/Sourcery/Equality.swifttemplate/oSLR1bsrLapzaddnJtSrw7XLwIcd94jZorJD%2BX3XSxA%3D, NSFilePath=/var/folders/90/8tcwdk19055d0rrgfp00h25h0000gn/T/SwiftTemplate/4F2C1EC9-D4B9-44BE-A854-1F6BAAFD5113/Major.Minor.Patch/.build/release/SwiftTemplate, NSUnderlyingError=0x600001928030 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}

Details

To resolve this, the move of the compiled SwiftTemplate binary is now optional, i.e. thrown error is ignored. Essentially, it is irrelevant if the binary was cached or not, since Sourcery's task is to execute SwiftTemplate and not cache SwiftTemplate.

Verification is done using a new unit test.

@art-divin art-divin self-assigned this Apr 14, 2024
@art-divin art-divin changed the title Fixed issue when caching compiled binary Fixed Issue when Caching of SwiftTemplate Binary Failes Apr 14, 2024
@art-divin art-divin merged commit f795e49 into master Apr 14, 2024
2 checks passed
@art-divin art-divin deleted the fix-binary-caching-concurrency branch April 14, 2024 18:14
@art-divin art-divin changed the title Fixed Issue when Caching of SwiftTemplate Binary Failes Fixed Issue when Caching of SwiftTemplate Binary Fails Apr 14, 2024
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

Successfully merging this pull request may close these issues.

1 participant