thw
(Thorbjørn Weidemann)
September 12, 2024, 9:02am
1
Even with a simple new project created with
swiftpm init --name app --type executable
and adding
dependencies: [
.package(url: "GitHub - swiftlang/swift-docc-plugin: Swift Package Manager command plugin for Swift-DocC ", from: "1.0.0"),
],
to Package swift, I get the following error when running
swift package plugin generate-documentation
...
Building documentation for 'app'...
Error: Error Domain=NSCocoaErrorDomain Code=513 "You don't have permission."
error: 'docc convert' invocation failed with a nonzero exit code: '1'
error: Error Domain=NSCocoaErrorDomain Code=4 "The file doesn't exist."
The error does not occur using swift 5.10.1.
But using
swift-6.0-DEVELOPMENT-SNAPSHOT-2024-08-22-a-ubi9 on AlmaLinux 9
swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-19-a-centos7.tar.gz on Almalinux 8
swift-6.0-DEVELOPMENT-SNAPSHOT-2024-08-22-a-ubuntu20.04 on Ubuntu 20.04 (tried 2 different installations)
I get this error.
Would be grateful if anyone could offer a workaround. Unfortunately the error message does not say which permission or which file is missing.
1 Like
I'm still seeing this with Swift 6.0.2. Running with swift package plugin generate-documentation --verbose
shows that the command that actually fails looks like this /opt/usr/lib/bin/docc convert --emit-lmdb-index --fallback-display-name [lib name] --fallback-bundle-identifier [lib name] --additional-symbol-graph-dir [cwd]/.build/x86_64-unknown-linux-gnu/extracted-symbols/swift/[lib name] --output-path [cwd]/.build/plugins/Swift-DocC/outputs/intermediates/[lib name].doccarchive
Running the same command with strace
shows the stack trace for the failing syscall and the one before it:
chmod("/tmp/55E11227-4BE3-4BB4-931A-E746CD588B3F-2248221-0000D204964632AD/css", 0755) = 0
> /usr/lib/x86_64-linux-gnu/libc.so.6(chmod+0x7) [0xfeb27]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV13setAttributes_12ofItemAtPathySDyAA0C12AttributeKeyVypG_SStKFySPys4Int8VGSgKXEfU_TA+0x163) [0x2d3b43]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($sSS20FoundationEssentialsE28withFileSystemRepresentationyxxSPys4Int8VGSgKXEKlFxAEKXEfU_TA+0xc) [0x29534c]
> /opt/usr/lib/swift/linux/libswiftCore.so($ss11_StringGutsV11withCStringyxxSPys4Int8VGKXEKlFxSRyAEGKXEfU_TA+0x11) [0x299f31]
> /opt/usr/lib/swift/linux/libswiftCore.so($sSS11withCStringyxxSPys4Int8VGKXEKlF+0x82) [0x317182]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC04withC20SystemRepresentation3for_xSS_xSPys4Int8VGSgKXEtKlF+0x2e) [0x32044e]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV13setAttributes_12ofItemAtPathySDyAA0C12AttributeKeyVypG_SStKF+0x1dc) [0x19c7fc]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC13setAttributes_12ofItemAtPathySDyAA0C12AttributeKeyVypG_SStKF+0x41) [0x31f3b1]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO011_linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL__4with8delegateySPys4Int8VG_AjA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySryAIGKXEfU_AC04copyC0_2toAF7optionsySS_SSAlA06NSFilepG7OptionsVtKFZ0gcR0L_V_Tg5+0x576) [0x1a0f56]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO011_linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL__4with8delegateySPys4Int8VG_AjA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZAC04copyC0_2toAF7optionsySS_SSAlA06NSFilepG7OptionsVtKFZ0gcR0L_V_Tgm5+0xcc) [0x1a089c]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_yAOKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5+0x33) [0x25d663]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_yAOKXEfU_AC0eC0_2toAGySS_SSAJtKFZ0qcR0L_V_TG5TATm+0x1b) [0x2d355b]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_yAOKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5TA+0xd) [0x2d353d]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($sSS11withCStringyxxSPys4Int8VGKXEKlFyt_Tg5065$sSS20FoundationEssentialsE28withFileSystemRepresentationyxxSPys4C25VGSgKXEKlFxAEKXEfU_yt_Tg5ADSgxs5Error_pRi_zRi0_zlyytIsgyrzo_Tf1ncn_n+0x7a) [0x1866fa]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_Tg5+0x69) [0x1a47a9]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5TATm+0x32) [0x2d35a2]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5TA.300+0x6) [0x2d3566]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($sSS11withCStringyxxSPys4Int8VGKXEKlFyt_Tg5065$sSS20FoundationEssentialsE28withFileSystemRepresentationyxxSPys4C25VGSgKXEKlFxAEKXEfU_yt_Tg5ADSgxs5Error_pRi_zRi0_zlyytIsgyrzo_Tf1ncn_n+0x7a) [0x1866fa]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV8copyItem6atPath02toI07optionsySS_SSAA06NSFileD11CopyOptionsVtKFTf4nndn_n+0x9a) [0x29e0da]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV8copyItem2at2to7optionsyAA3URLV_AiA06NSFileD11CopyOptionsVtKFTf4nndn_nTm+0x13b) [0x29e51b]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC8moveItem2at2toyAA3URLV_AHtKFTm+0x55) [0x1a50b5]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC8copyItem2at2toyAA3URLV_AHtKF+0xd) [0x31fcbd]
> /opt/usr/bin/docc($s20FoundationEssentials11FileManagerC9SwiftDocC0cD8ProtocolA2dEP8copyItem2at2toyAA3URLV_AKtKFTW+0x15) [0x5e7d35]
> /opt/usr/bin/docc($s18SwiftDocCUtilities13ConvertActionV7perform9logHandleAA0E6ResultV0aB1C03LogH0O_tKF+0x4cb) [0x9c7b1b]
> /opt/usr/bin/docc($s18SwiftDocCUtilities4DoccV7ConvertV3runyyKF+0x6e) [0x9bb05e]
> /opt/usr/bin/docc($s18SwiftDocCUtilities4DoccV7ConvertV14ArgumentParser15ParsableCommandAafGP3runyyKFTW+0x9) [0x99d209]
> /opt/usr/bin/docc(docc_main+0x5a) [0xadf12a]
> /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x88) [0x29d68]
> /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x29e25]
> /opt/usr/bin/docc(_start+0x21) [0x11b191]
chown("/tmp/55E11227-4BE3-4BB4-931A-E746CD588B3F-2248221-0000D204964632AD/css", 0, 0) = -1 EPERM (Operation not permitted)
> /usr/lib/x86_64-linux-gnu/libc.so.6(chown+0x7) [0xfeb57]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV13setAttributes_12ofItemAtPathySDyAA0C12AttributeKeyVypG_SStKFySPys4Int8VGSgKXEfU_TA+0x74b) [0x2d412b]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($sSS20FoundationEssentialsE28withFileSystemRepresentationyxxSPys4Int8VGSgKXEKlFxAEKXEfU_TA+0xc) [0x29534c]
> /opt/usr/lib/swift/linux/libswiftCore.so($ss11_StringGutsV11withCStringyxxSPys4Int8VGKXEKlFxSRyAEGKXEfU_TA+0x11) [0x299f31]
> /opt/usr/lib/swift/linux/libswiftCore.so($sSS11withCStringyxxSPys4Int8VGKXEKlF+0x82) [0x317182]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC04withC20SystemRepresentation3for_xSS_xSPys4Int8VGSgKXEtKlF+0x2e) [0x32044e]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV13setAttributes_12ofItemAtPathySDyAA0C12AttributeKeyVypG_SStKF+0x1dc) [0x19c7fc]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC13setAttributes_12ofItemAtPathySDyAA0C12AttributeKeyVypG_SStKF+0x41) [0x31f3b1]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO011_linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL__4with8delegateySPys4Int8VG_AjA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySryAIGKXEfU_AC04copyC0_2toAF7optionsySS_SSAlA06NSFilepG7OptionsVtKFZ0gcR0L_V_Tg5+0x576) [0x1a0f56]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO011_linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL__4with8delegateySPys4Int8VG_AjA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZAC04copyC0_2toAF7optionsySS_SSAlA06NSFilepG7OptionsVtKFZ0gcR0L_V_Tgm5+0xcc) [0x1a089c]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_yAOKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5+0x33) [0x25d663]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_yAOKXEfU_AC0eC0_2toAGySS_SSAJtKFZ0qcR0L_V_TG5TATm+0x1b) [0x2d355b]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_yAOKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5TA+0xd) [0x2d353d]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($sSS11withCStringyxxSPys4Int8VGKXEKlFyt_Tg5065$sSS20FoundationEssentialsE28withFileSystemRepresentationyxxSPys4C25VGSgKXEKlFxAEKXEfU_yt_Tg5ADSgxs5Error_pRi_zRi0_zlyytIsgyrzo_Tf1ncn_n+0x7a) [0x1866fa]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_Tg5+0x69) [0x1a47a9]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5TATm+0x32) [0x2d35a2]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials15_FileOperationsO010linkOrCopyC033_54538455693C81BE2FDBED43BE08DD07LL_3dst4with8delegateySS_SSAA0C7ManagerCxtKAA04LinkfG8DelegateAELLRzlFZySPys4Int8VGSgKXEfU_AC04copyC0_2toAG7optionsySS_SSAjA06NSFilepG7OptionsVtKFZ0gcR0L_V_TG5TA.300+0x6) [0x2d3566]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($sSS11withCStringyxxSPys4Int8VGKXEKlFyt_Tg5065$sSS20FoundationEssentialsE28withFileSystemRepresentationyxxSPys4C25VGSgKXEKlFxAEKXEfU_yt_Tg5ADSgxs5Error_pRi_zRi0_zlyytIsgyrzo_Tf1ncn_n+0x7a) [0x1866fa]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV8copyItem6atPath02toI07optionsySS_SSAA06NSFileD11CopyOptionsVtKFTf4nndn_n+0x9a) [0x29e0da]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials16_FileManagerImplV8copyItem2at2to7optionsyAA3URLV_AiA06NSFileD11CopyOptionsVtKFTf4nndn_nTm+0x13b) [0x29e51b]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC8moveItem2at2toyAA3URLV_AHtKFTm+0x55) [0x1a50b5]
> /opt/usr/lib/swift/linux/libFoundationEssentials.so($s20FoundationEssentials11FileManagerC8copyItem2at2toyAA3URLV_AHtKF+0xd) [0x31fcbd]
> /opt/usr/bin/docc($s20FoundationEssentials11FileManagerC9SwiftDocC0cD8ProtocolA2dEP8copyItem2at2toyAA3URLV_AKtKFTW+0x15) [0x5e7d35]
> /opt/usr/bin/docc($s18SwiftDocCUtilities13ConvertActionV7perform9logHandleAA0E6ResultV0aB1C03LogH0O_tKF+0x4cb) [0x9c7b1b]
> /opt/usr/bin/docc($s18SwiftDocCUtilities4DoccV7ConvertV3runyyKF+0x6e) [0x9bb05e]
> /opt/usr/bin/docc($s18SwiftDocCUtilities4DoccV7ConvertV14ArgumentParser15ParsableCommandAafGP3runyyKFTW+0x9) [0x99d209]
> /opt/usr/bin/docc(docc_main+0x5a) [0xadf12a]
> /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x88) [0x29d68]
> /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x29e25]
> /opt/usr/bin/docc(_start+0x21) [0x11b191]
AFAICT it looks like there was an attempt to chown
a temporary directory to be owned by the root user, which the OS rejected.
powwow
January 10, 2025, 1:43pm
4
Does anyone know the latest status of this issue.
I have recently fallen over the same problem on Ubuntu 24.04 using Swift --version 6.0.3.
The concern for me is that if you already have documentation from a previous version of Swift and your using the "swift package --allow-writing-to-directory ./docs generate-documentation --target --output-path ./docs" command it deletes your ./docs directory completely and anything in it is lost.
powwow
January 24, 2025, 12:16pm
5
Please see the below bug in SwiftLang/swift-docc
https://github.com/swiftlang/swift-docc/issues/1136
I think this is the same issue that we have observed here, the only difference I can see is the platform, as I'm on Ubuntu where the toolchain installation location is "/opt/swift"
anyone have any thoughts ??
1 Like
powwow
April 14, 2025, 10:37am
6
I have just managed to re-test this issue with Swift --version 6.1 on Ubuntu 24.04
I get the same error, so I think we are awaiting the bug fix for issue [quote="powwow, post:5, topic:74534"]
opened 02:00AM - 12 Jan 25 UTC
closed 10:32AM - 14 Mar 25 UTC
bug
### Description
When the Swift toolchain is installed to `/` or `/usr/libexec` … (as is done with Debian and Fedora distributions), the `docc` binary throws a permissions issue when attempting to preview or generate documentation:
```bash
xtremek@Winter ~/t/swift-async-algorithms (main) [1]> ls -la /usr/libexec/swift/6.0.3/bin/docc
-rwxr-xr-x 1 root root 23984936 Dec 15 19:00 /usr/libexec/swift/6.0.3/bin/docc*
xtremek@Winter ~/t/swift-async-algorithms (main)> /usr/libexec/swift/6.0.3/bin/docc preview
Input: ~/tmp/swift-async-algorithms
Template: /usr/libexec/swift/6.0.3/share/docc/render
Error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission."
```
However, if the Swift toolchain and `docc` are installed to a directory under the user, like in the user's home directory or via Swiftly, then it works perfectly fine:
```
xtremek@Winter ~/t/swift-async-algorithms (main)> ls -la $(which docc)
lrwxrwxrwx 1 xtremek xtremek 32 Jan 4 15:36 ~/.local/bin/docc -> ~/.local/bin/swiftly*
xtremek@Winter ~/t/swift-async-algorithms (main)> ~/.local/bin/docc preview
Input: ~/tmp/swift-async-algorithms
Template: ~/.local/share/swiftly/toolchains/6.0.3/usr/share/docc/render
========================================
Starting Local Preview Server
Address: http://localhost:8080/documentation/validation
========================================
```
Any ideas why this happens? It makes it impossible to have Swift installed to the system and then use docc to preview and generate documentation, for example in a CI environment...
### Checklist
- [X] If possible, I've reproduced the issue using the `main` branch of this package.
- [X] This issue hasn't been addressed in an [existing GitHub issue](https://github.com/apple/swift-docc/issues).
### Expected Behavior
Running `docc convert` or `docc preview` when the Swift toolchain is installed to a system directory with `root` permissions works.
### Actual behavior
Running `docc convert` or `docc preview` when the Swift toolchain is installed to a system directory with `root` permissions throws a permissions error:
`Error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission."`
### Steps To Reproduce
1. Install Swift to a system directory such as / or /usr/libexec/swift.
2. Run `docc preview` from the system directory.
3. Observe that it does not work, but throws a permissions issue.
### Swift-DocC Version Information
Swift 6.0.3 Release
### Swift Compiler Version Information
```shell
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: aarch64-unknown-linux-gnu
```
[/quote]
=======
Additional info, looks like the below pull request resolves this issue in Swift --version 6.1.1
release/6.1.1
← xtremekforever:bugfix/docc-permissions-in-6.1.1
opened 08:55PM - 10 Apr 25 UTC
- **Explanation**: When Swift was installed as root to a location such as `/` or… `/usr/libexec`, attempting to generate or preview documentation with `docc` would result in the error: `Error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission."`. This was cherry-picked from `swiftlang/swift-docc:main`.
- **Scope**: This is a small fix/workaround that is originally caused by a bug in Foundation that has not been fixed yet.
- **GitHub Issue**: https://github.com/swiftlang/swift-docc/issues/1136
- **Risk**: I forsee no risks with this fix.
- **Testing**: Manual testing was performed (https://github.com/swiftlang/swift-docc/pull/1169) along with some test cases added for this scenario.
- **Reviewer**: @d-ronnqvist @patshaughnessy