Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Xcode Cloud #777

Open
le-tyang opened this issue Dec 5, 2022 · 29 comments
Open

Issue with Xcode Cloud #777

le-tyang opened this issue Dec 5, 2022 · 29 comments

Comments

@le-tyang
Copy link

le-tyang commented Dec 5, 2022

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
Copy link

rist commented Dec 5, 2022

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
Copy link
Collaborator

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
Copy link

rist commented Dec 5, 2022

SwiftLint was having a vaguely similar issue when running on Xcode cloud - perhaps some of their approach could be helpful realm/SwiftLint#4485

@sacred0x01
Copy link

sacred0x01 commented Dec 20, 2022

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
Copy link

PChmiel commented Dec 21, 2022

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
Copy link
Contributor

ky1ejs commented Dec 24, 2022

@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 added a commit to ky1ejs/my-tfc-bb that referenced this issue Dec 24, 2022
@le-tyang
Copy link
Author

@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
Copy link

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

@Faktorealchik
Copy link

Also have the same issue with Xcode Cloud

RswiftGenerateInternalResource is disabled

@DonBaronFactory
Copy link

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

@sergsadovyi
Copy link

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

@DonBaronFactory
Copy link

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
Copy link

sacred0x01 commented Jan 24, 2023

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

@DonBaronFactory
Copy link

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
Copy link

alexanderwe commented Jan 29, 2023

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 ?

@MaxenceMottard
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

SandrikaJanjghava commented Mar 22, 2023

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
Copy link

SandrikaJanjghava commented Apr 6, 2023

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

@ghost
Copy link

ghost commented Apr 12, 2023

#!/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
Copy link

iva1ex commented Jun 18, 2023

Hello. Has anyone found a solution?

@denis15yo
Copy link

Hi! Any news on the solution to this problem?

@s4cha
Copy link

s4cha commented Jun 27, 2023

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
Copy link

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
Copy link

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
Copy link

KatyaDv commented Oct 11, 2023

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

@joshkopecek
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests