mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.47k stars 759 forks source link

Issue with Xcode Cloud #777

Open le-tyang opened 1 year ago

le-tyang commented 1 year ago

Hi there,

We recently migrated to V7, and it works perfectly, in our local machine and CircleCI.

The issue now is with Xcode Cloud, as we are getting this error from logs.

PhaseScriptExecution R.swift\ generate\ resources\ for\ application\ APPLICATION_NAME/Volumes/workspace/DerivedData/Build/Intermediates.noindex/APPLICATION_NAME.build/Debug-iphonesimulator/APPLICATION_NAME.build/Script-72183A77293DDBE600A947EF.sh (in target 'APPLICATION_NAME' from project 'APPLICATION_NAME')
    cd /Volumes/workspace/repository
    /bin/sh -c /Volumes/workspace/DerivedData/Build/Intermediates.noindex/APPLICATION_NAME.build/Debug-iphonesimulator/APPLICATION_NAME.build/Script-72183A77293DDBE600A947EF.sh

Error: You don’t have permission to save the file “R.generated.swift” in the folder "Resources".
LLVM Profile Error: Failed to write file "default.profraw": Operation not permitted
Command PhaseScriptExecution failed with a nonzero exit code

Looks like the build script doesn't have access to Resources folder in Xcode cloud 🤔 We've done everything as the migration guideline suggested.

Do you have any suggestion? 🤔

Thanks!

rist commented 1 year ago

having the same issue

Showing All Issues
PhaseScriptExecution R.swift\ generate\ resources\ for\ framework\ MUBIUI /Volumes/workspace/DerivedData/Build/Intermediates.noindex/MUBI.build/Debug-iphoneos/MUBIUI.build/Script-72E99122293DFD2A00E48A9F.sh (in target 'MUBIUI' from project 'MUBI')
    cd /Volumes/workspace/repository
    /bin/sh -c /Volumes/workspace/DerivedData/Build/Intermediates.noindex/MUBI.build/Debug-iphoneos/MUBIUI.build/Script-72E99122293DFD2A00E48A9F.sh

Error: You don’t have permission to save the file “R.generated.swift” in the folder “Resources”.
LLVM Profile Error: Failed to write file "default.profraw": Operation not permitted
Command PhaseScriptExecution failed with a nonzero exit code

Error: You don’t have permission to save the file “R.generated.swift” in the folder “Resources”.

LLVM Profile Error: Failed to write file "default.profraw": Operation not permitted

Command PhaseScriptExecution failed with a nonzero exit code

image

tomlokhorst commented 1 year ago

Thanks for your comments.

I haven't used R.swift with Xcode Cloud, so I haven't seen this issue. If there's anyone with experience of running R.swift on Xcode Cloud, please leave a comment.

rist commented 1 year ago

SwiftLint was having a vaguely similar issue when running on Xcode cloud - perhaps some of their approach could be helpful https://github.com/realm/SwiftLint/pull/4485

sacred0x01 commented 1 year ago

Hi!

We also have an issue with Xcode Cloud

Archive - iOS encountered a failure that caused the build to fail. Issue

file:///Volumes/workspace/DerivedData/SourcePackages/checkouts/R.swift/Plugins/RswiftGenerateInternalResources/RswiftGenerateInternalResources.swift
“RswiftGenerateInternalResources” is disabled

Any ways to fix it somehow?

PChmiel commented 1 year ago

Maybe try to disable plugin validation, you could set custom build scripts and run defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES. I had to do the same in fastlane used by github actions.

ky1ejs commented 1 year ago

@le-tyang @rist did you find a solution to the You don’t have permission to save the file in the end?

At first I had the same issue as @sacred0x01 but fixed it with @PChmiel's response, but now I get a Command PhaseScriptExecution failed with a nonzero exit code failure on Xcode Cloud. By looking into the zip file of logs that Xcode Cloud gives you, I see the same error as you:

2022-12-24T19:01:01.972723034Z  Error: You don’t have permission to save the file “R.generated.swift” in the folder “Re
2022-12-24T19:01:01.972891949Z  sources”.
2022-12-24T19:01:01.973065155Z  Command PhaseScriptExecution failed with a nonzero exit code

My project is pretty small, so I'll remove R.swift for now. But I've been a big fan for 6+ years so would love to be able to use it again.

In truth, Xcode Cloud is a bit of a pain but it's more of a pain to set up GH Actions with Xcode Connect IMO.

le-tyang commented 1 year ago

@ky1ejs , unfortunately, no :(

We ended up replacing R.swift with SwiftGen as some of our packages are using SwiftGen as well. But I reckon you should be able to change it back to use build phase script.

sergsadovyi commented 1 year ago

have the same issue with Xcode Cloud, waiting for some resolution

Faktorealchik commented 1 year ago

Also have the same issue with Xcode Cloud

RswiftGenerateInternalResource is disabled

DonBaronFactory commented 1 year ago

Was struggling getting RSwift working with XCode Cloud. Managed to get it working like that:

Xcode cloud will not moan anymore that the rswift executable cannot be part of the package and will archive the build successfully

Check out Apple Doc: https://developer.apple.com/documentation/xcode/writing-custom-build-scripts

sergsadovyi commented 1 year ago

@DonBaronFactory could you share ci_pre_xcodebuild.sh and Build Phase contents?

DonBaronFactory commented 1 year ago

I only use "ci_pre_xcodebuild" since Rswift just needs to generate the source files before compiling. The content is as follows:

#!/bin/sh

#  ci_pre_xcodebuild.sh
#  
#  Created on 24.01.23.
#  

rswift generate "$SRCROOT/<YourAppName>/Generated/R.generated.swift"

My Build Phase Script looks like that:

"$SRCROOT/<YourAppName>/ci_scripts/rswift" generate "$SRCROOT/<YourAppName>/Generated/R.generated.swift"
sacred0x01 commented 1 year ago

@DonBaronFactory look like you are using not the latest version, which is works quite different than previous one

DonBaronFactory commented 1 year ago

I installed with SPM and when I try to check the version it just refers to "master"... tried updating too but doesn't seem to do nothing. I read though that SPM got a problem in XCode 14... dunno, but for now I'm just happy it works, independently of which version it is

alexanderwe commented 1 year ago

Also have the same issue with Xcode Cloud

RswiftGenerateInternalResource is disabled

@Faktorealchik I fixed this issue by adding this to my ci_post_clone.sh script, like mentioned here as well https://github.com/mac-cain13/R.swift/issues/777#issuecomment-1361337749

#!/bin/sh

# Disable SPM built tool validation - it seems like the enabled flag is stored in the .xcodeproj file
# see: https://forums.swift.org/t/telling-xcode-14-beta-4-to-trust-build-tool-plugins-programatically/59305/4
defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES

But then I do also face this error when using the SPM build tool plugin

Error: You don’t have permission to save the file “R.generated.swift” in the folder “Resources”.
Command PhaseScriptExecution failed with a nonzero exit code

Seems like since we cannot get sudo on Xcode cloud, we are not allowed to save new files ?

MaxenceMottard commented 1 year ago

Also have the same issue with Xcode Cloud RswiftGenerateInternalResource is disabled

@Faktorealchik I fixed this issue by adding this to my ci_post_clone.sh script, like mentioned here as well #777 (comment)

#!/bin/sh

# Disable SPM built tool validation - it seems like the enabled flag is stored in the .xcodeproj file
# see: https://forums.swift.org/t/telling-xcode-14-beta-4-to-trust-build-tool-plugins-programatically/59305/4
defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES

But then I do also face this error when using the SPM build tool plugin

Error: You don’t have permission to save the file “R.generated.swift” in the folder “Resources”.
Command PhaseScriptExecution failed with a nonzero exit code

Seems like since we cannot get sudo on Xcode cloud, we are not allowed to save new files ?

Has anyone found a solution? I have the same error after changing IDESkipPackagePluginFingerprintValidatation parameter.

el-hoshino commented 1 year ago

Same issue here, and I'm importing Rswift using Package.swift instead of in Xcode project dependencies settings 🤔

2023-03-08T11:53:44.043893938Z  WriteAuxiliaryFile /Volumes/workspace/DerivedData/Build/Intermediates.noindex/MainPackage.build/Debug-iphonesimulator/MainPackage.build/Script-8592293820177808654.sh (in target 'MainPackage' from project 'MainPackage')
2023-03-08T11:53:44.043944422Z      cd /Volumes/workspace/repository/MainPackage
2023-03-08T11:53:44.044069113Z      write-file /Volumes/workspace/DerivedData/Build/Intermediates.noindex/MainPackage.build/Debug-iphonesimulator/MainPackage.build/Script-8592293820177808654.sh
2023-03-08T11:53:44.044145671Z  
2023-03-08T11:53:44.044264203Z  PhaseScriptExecution R.swift\ generate\ resources\ for\ generic\ module\ MainPackage /Volumes/workspace/DerivedData/Build/Intermediates.noindex/MainPackage.build/Debug-iphonesimulator/MainPackage.build/Script-8592293820177808654.sh (in target 'MainPackage' from project 'MainPackage')
2023-03-08T11:53:44.044404876Z      cd /Volumes/workspace/repository/MainPackage
2023-03-08T11:53:44.044517042Z      /bin/sh -c /Volumes/workspace/DerivedData/Build/Intermediates.noindex/MainPackage.build/Debug-iphonesimulator/MainPackage.build/Script-8592293820177808654.sh
2023-03-08T11:53:44.044607100Z  Error: You don’t have permission to save the file “R.generated.swift” in the folder “MainPack
2023-03-08T11:53:44.044724976Z  age”.
2023-03-08T11:53:44.044811303Z  Command PhaseScriptExecution failed with a nonzero exit code
bamboo-wood commented 1 year ago

Hello, I am also experiencing the same issue. It is causing some inconvenience on my end as well. Have you found a solution to this problem or is there any progress on it?😩

2023-03-14T08:43:56.859625911Z  Error: You don’t have permission t
2023-03-14T08:43:56.859670325Z  o save the file “R.generated.swift” in the folder 
2023-03-14T08:43:56.859741686Z  “Res
2023-03-14T08:43:56.859783590Z  ources
2023-03-14T08:43:56.859822257Z  ”.
2023-03-14T08:43:56.859858403Z  
2023-03-14T08:43:56.859908745Z  Command PhaseScriptExecution failed with a nonzero exit code
rogerioth commented 1 year ago

Experiencing the same issue with a minimal project configured to run on Azure Pipelines

The following build commands failed:
    PhaseScriptExecution R.swift\ generate\ resources\ for\ application\ "X" /Users/runner/Library/Developer/Xcode/DerivedData/X-escdvxpbbjcblrgcmlblxlyfjsie/Build/Intermediates.noindex/X.build/Debug-iphonesimulator/X.build/Script-4349C16B29C211F7005559CC.sh (in target 'X' from project 'X')
(1 failure)
##[error]Error: /usr/bin/xcodebuild failed with return code: 65

Added the plugin validation disable with no effect (at least on this specific error) defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES

SandrikaJanjghava commented 1 year ago

I'm having the same issue with: `The following build commands failed: PhaseScriptExecution R.swift\ generate\ resources\ for\ application\ .... (1 failure)

[error]Error: /usr/bin/xcodebuild failed with return code: 65`

On local machine is working without issues, also it works on Mac Studio, but the Azure pipeline fails with this error. Any solutions?

SandrikaJanjghava commented 1 year ago

Hello. Does anyone have found solution? Or waiting for R.swift compatibility?

slitvinov-promwad commented 1 year ago
#!/bin/sh

#  ci_pre_xcodebuild.sh
#  
#  Created on 24.01.23.
#  

rswift generate "$SRCROOT/<YourAppName>/Generated/R.generated.swift"

Hello, I tried to repeat this solution and it failed since the rswift executable cannot find environment variables PROJECT_FILE_PATH and TARGET_NAME running in a cloud environment.

When I tried to change my CI script to

rswift generate "$SRCROOT/Generated/R.generated.swift" --xcodeproj "$CI_PROJECT_FILE_PATH" --target "@CI_XCODE_SCHEME"

it gave me the following error:

Error: ResourceUnsupportedExtensionError(url: file:///Volumes/workspace/repository/UmbrellaApp.xcworkspace/, typeName: "Xcodeproj", supportedExtensions: Set(["xcodeproj"]))

So obviously rswift does not work with workspaces and there is no way to get a project name from Xcode Cloud environment variables. Finally, I ended up with the following solution:

  1. Copy the rswift executable to the root project folder as described in the installation manual.
  2. Remove *.generated.swift from .gitignore
  3. Change my build scripts as follows:
if [ -z ${CI+x} ] || [ "$CI" = false ]; then
  "$SRCROOT/rswift" generate "$SRCROOT/Generated/R.generated.swift"
fi

The one possible downside is that there might be merge conflicts but it is a minor one.

iva1ex commented 1 year ago

Hello. Has anyone found a solution?

denis15yo commented 1 year ago

Hi! Any news on the solution to this problem?

s4cha commented 1 year ago

Hi! Any news on the solution to this problem?

@denis15yo I personally switched to Swiftgen and pre-generated the files manually (via command line) this means the build no longer depends on yet another tool, which I think is always a good thing.

denis15yo commented 1 year ago

Hi! Any news on the solution to this problem?

@denis15yo I personally switched to Swiftgen and pre-generated the files manually (via command line) this means the build no longer depends on yet another tool, which I think is always a good thing.

Thanks for the answer So far, I am using a similar solution: I stayed with rswift, but now I use RswiftGenerateResourcesCommand, which I run locally and push the R.generated.swift files in the repository.

But in any case, I like the solution with buildTool plugins better, so I hope the problem will be solved someday)

vindicatesociety commented 11 months ago

Please provide instructions to remove R.swift altogether. It's not worth breaking your build.

After removing the r swift packages and build settings, I still get an error.

There is no script. Error: You don't have permission to save the file "R.generated.swift" in the folder "Resources."

KatyaDv commented 10 months ago

Hey! I am still experiencing the problem with Xcode Cloud, RswiftGenerateInternalResource is disabled, Xcode 15.0, Rswift 7.4.0.

Is there maybe any updates on that?

I am setting Rswift up with SPM, having 2 targets depending on it

P.S. Have added ci_pre_xcodebuild.sh phase and added rswift generate "$SRCROOT/ProjectName/Generated/R.generated.swift" command there. As well as brought rswift.exec to the ci_scripts folder.

Now I see that error:

_Run command: 'cd /Volumes/workspace/repository/ci_scripts && /Volumes/workspace/repository/ci_scripts/ci_pre_xcodebuild.sh' Error: Missing argument PROJECT_FILEPATH Usage: rswift See 'rswift --help' for more information. Error Command exited with non-zero exit-code: 64

@tomlokhorst

joshkopecek commented 9 months ago

Using R.Swift 7.4.0, I solved this by:

  1. Having a separate branch that I run on Xcode Cloud (say internal)
  2. Removing the RswiftGenerateInternalResource Build Tool Plugin on the internal branch, but keeping it on the development one.
  3. Manually including the R.generated.swift file in the project only on the internal branch (just drag it into the project).
  4. Running build on the development branch to make sure the R.generated.swift file is up to date, and merging any changes into internal.
  5. Push the internal branch.

That way, you use the Build Tool Plugin on your development branch, and the manual inclusion method on the internal Xcode Cloud branch, and you circumvent any issues with trying to build and include the R.generated.swift file through Xcode Cloud.

Xcode seems to be switching towards resources being available at build time (images, colours) more and more, which I can only say is a good thing, but RSwift and SwiftGen still remain decent for more legacy projects.