R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Issue with Xcode Cloud

Open le-tyang opened this issue 2 years ago • 29 comments
trafficstars

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!

le-tyang avatar Dec 05 '22 08:12 le-tyang

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

rist avatar Dec 05 '22 10:12 rist

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.

tomlokhorst avatar Dec 05 '22 12:12 tomlokhorst

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

rist avatar Dec 05 '22 12:12 rist

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?

sacred0x01 avatar Dec 20 '22 21:12 sacred0x01

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.

PChmiel avatar Dec 21 '22 13:12 PChmiel

@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.

ky1ejs avatar Dec 24 '22 19:12 ky1ejs

@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.

le-tyang avatar Dec 26 '22 10:12 le-tyang

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

sergsadovyi avatar Dec 27 '22 14:12 sergsadovyi

Also have the same issue with Xcode Cloud

RswiftGenerateInternalResource is disabled

Faktorealchik avatar Dec 31 '22 13:12 Faktorealchik

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

  • Create a folder in App Root named "ci_scripts"
  • Create sh scripts as required:
    • ci_pre_xcodebuild.sh
    • ci_post_clone.sh
    • ci_post_xcodebuild.sh
  • Make scripts executable (chmod +x)
  • copy RSwift excutable into that folder "ci_scripts"
  • Edit ci_pre_xcodebuild.sh and add your rswift command (similar to build phase) but point to the rswift exec in that folder
  • Edit build phase and also point to the rswift exec in the ci_scripts folder

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

DonBaronFactory avatar Jan 24 '23 11:01 DonBaronFactory

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

sergsadovyi avatar Jan 24 '23 14:01 sergsadovyi

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"

DonBaronFactory avatar Jan 24 '23 16:01 DonBaronFactory

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

sacred0x01 avatar Jan 24 '23 17:01 sacred0x01

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

DonBaronFactory avatar Jan 24 '23 17:01 DonBaronFactory

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 ?

alexanderwe avatar Jan 29 '23 21:01 alexanderwe

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.

MaxenceMottard avatar Feb 03 '23 17:02 MaxenceMottard

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

el-hoshino avatar Mar 08 '23 12:03 el-hoshino

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

bamboo-wood avatar Mar 15 '23 03:03 bamboo-wood

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

rogerioth avatar Mar 15 '23 14:03 rogerioth

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 avatar Mar 22 '23 06:03 SandrikaJanjghava

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

SandrikaJanjghava avatar Apr 06 '23 20:04 SandrikaJanjghava

#!/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.

slitvinov-promwad avatar Apr 12 '23 08:04 slitvinov-promwad

Hello. Has anyone found a solution?

iva1ex avatar Jun 18 '23 12:06 iva1ex

Hi! Any news on the solution to this problem?

denis15yo avatar Jun 26 '23 12:06 denis15yo

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.

s4cha avatar Jun 27 '23 16:06 s4cha

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)

denis15yo avatar Jun 27 '23 16:06 denis15yo

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."

vindicatesociety avatar Oct 04 '23 14:10 vindicatesociety

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_FILE_PATH Usage: rswift See 'rswift --help' for more information. Error Command exited with non-zero exit-code: 64

@tomlokhorst

KatyaDv avatar Oct 11 '23 15:10 KatyaDv

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.

joshkopecek avatar Nov 23 '23 12:11 joshkopecek