swift-sourcery-templates
swift-sourcery-templates copied to clipboard
"Operation not permitted" while loading Package manifest when invoking Sourcery from an SPM prebuild command plugin
Filing a known issue:
Sourcery allows to use package manifest to specify sources for the code indexation:
# .Sourcery.Mocks.yml
package:
path: ../..
target:
- ExampleProjectSpm
When such Sourcery config file is given to the SourcerySwiftCodegenPlugin, Sourcery fails to read the package manifest:
Loading manifest: [error]: Invalid manifest (.../Package.swift...)
sandbox-exec: sandbox_apply: Operation not permitted
This happens, apparently, because package manifest could not be read from the build tool plugin sandbox.
To replicate the error, check out this commit: https://github.com/ivanmisuno/swift-sourcery-templates/commit/bfbd50f57459ebfd7bce58a198421c93c7a6d033
git clone https://github.com/ivanmisuno/swift-sourcery-templates
cd swift-sourcery-templates
git checkout bfbd50f57459ebfd7bce58a198421c93c7a6d033
cd Examples/ExampleProjectSpm
./build-ios.sh
You'll see sandbox-exec: sandbox_apply: Operation not permitted
error when Sourcery tries to read ExampleProjectSpm/Package.swift
.
When invoking Sourcery with the same config from the command line, it can read the Package manifest just fine:
SOURCERY_OUTPUT_DIR=.generated /path/to/sourcery --config .Sourcery.Mocks.yml
Using configuration file at '.Sourcery.Mocks.yml'
Scanning sources...
Found 55 types in 5 files, 0 changed from last run.
Loading templates...
Loaded 1 templates.
Generating code...
Finished.
Just wondering if anyone else has observed this, and if anyone has ideas/came up with a workaround?
My own workaround:
- the build tool plugin exports paths to all dependencies via environment variables (with predefined names)
- you add source paths to the .yml config using these env vars, eg.:
# .Sourcery.Mocks.yml
sources:
- ${SOURCERY_TARGET_ExampleProjectSpm}
- ...
This works (in the same checkout):
git switch pre_build_command_plugin
./build-ios.sh
...
** BUILD SUCCEEDED **