For context, I have been trying to write a swift package manager build tool plugin that generates mocks using the sourcery binary.
This plugin is working fine when used on a single target, but if I add it to several target in the same package, then I get errors.
These look like either:
error: unable to attach DB: error: accessing build database "/private/var/folders/bl/dpyystbj1szdr_rzp6p1fwq40000gn/T/SwiftTemplate/2.0.1/.build/arm64-apple-macosx/build.db": database is locked Possibly there are two concurrent builds running in the same filesystem location.
or:
input file '/private/var/folders/bl/dpyystbj1szdr_rzp6p1fwq40000gn/T/SwiftTemplate/2.0.1/Sources/SourceryRuntime/Struct.swift' was modified during the builderror: input file '/private/var/folders/bl/dpyystbj1szdr_rzp6p1fwq40000gn/T/SwiftTemplate/2.0.1/Sources/SourceryRuntime/Struct.swift' was modified during the build
I worked out that the sourcery binary as well as creating the mocks that end up being used in the project, also creates some other files that it is writing to the temp directory. These 'temp' files are seem to be being interpreted as part of the build process by the compiler and causing issues with the build when there are multiple targets being built concurrently.
My attempted solution to this is to try and get the compiler to ignore these files using the swiftSettings argument
I've tried this:
swiftSettings: [.define("EXCLUDED_SOURCE_FILE_NAMES=${TMPDIR}/SwiftTemplate/2.0.1")]
added to the targets in the package that use the plugin.
But I'm unsure if this is the correct way to write this? In any case it doesn't seem to be helping..
Thoughts appreciated!