Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 174 forks source link

Builds failing on Bitrise with stack Xcode 13.3.x (beta) #417

Closed brandtdaniels closed 2 years ago

brandtdaniels commented 2 years ago

Bitrise stack "Xcode 13.3.x (beta) on macOS 12.2 (Monterey)" is failing builds with the following error message

Last lines of the build log:
Script path: /Users/vagrant/git/CRM
xargs: /Users/vagrant/git/CRM/cuckoo_generator: terminated with signal 4; aborting
Command PhaseScriptExecution failed with a nonzero exit code

Test session results, code coverage, and logs:
    /var/folders/62/0p2cg52j6r16xjxfqch4vgt40000gn/T/XCUITestOutput573379856/Test.xcresult

Testing failed:
    Command PhaseScriptExecution failed with a nonzero exit code
    Testing cancelled because the build failed.

** TEST FAILED **

The following build commands failed:
    PhaseScriptExecution Cuckoo\ Run\ Script /Users/vagrant/Library/Developer/Xcode/DerivedData/CRM-gfmkxxwjwsejasaegkkqxuwbswfa/Build/Intermediates.noindex/CRM.build/Debug-iphonesimulator/CRMTests.build/Script-3312E990D1E37BD0916B2578.sh (in target 'CRMTests' from project 'CRM')
(1 failure)

Recently included the following conditionals in the Cuckoo Run Script which seems to have no improvement

if [ $ACTION == "indexbuild" ]; then
  echo "Not running Cuckoo generator during indexing."
  exit 0 
fi

# Skip for preview builds
if [ "${ENABLE_PREVIEWS}" = "YES" ]; then
  echo "Not running Cuckoo generator during preview builds."
  exit 0
fi
brandtdaniels commented 2 years ago

@MatyasKriz Have you seen any issues with the latest Xcode beta?

MatyasKriz commented 2 years ago

Hey, @brandtdaniels. I haven't tried compiling nor running Cuckoo on the beta builds of Xcode. Not sure what the issue could be.

MatyasKriz commented 2 years ago

Is there more info somewhere in the logs? My internet connection isn't stellar to download the Xcode beta just to find an issue.

brandtdaniels commented 2 years ago

I didn't really see anything more in the logs

MatyasKriz commented 2 years ago

Is it possible to switch to an earlier Xcode on Bitrise, or is this just a heads up that Cuckoo fails to run in Xcode 13.3 beta?

I'll have to take a look at the missing CI in this project.

brandtdaniels commented 2 years ago

We typically prepare for upcoming versions of Xcode/iOS as soon as they become available. We try to catch these issues proactively. This is sort of a heads up, but would also like to resolve this as we have nightly builds that run specs against the latest stacks (including betas)

karim-alweheshy commented 2 years ago

For me it is failing on lastest xcode xargs: /{fill_in_dir}/Pods/Cuckoo/cuckoo_generator: terminated with signal 5; aborting

jandrewmoore commented 2 years ago

My project is failing after updating Xcode, as well, but with signal 4.

xargs: [redacted]/Pods/Cuckoo/cuckoo_generator: terminated with signal 4; aborting
Command PhaseScriptExecution failed with a nonzero exit code

Doesn't seem like adding --debug is adding any additional information in this case.

antoniocasero commented 2 years ago

Same problem here, usually, I would try my best to fix it, but it crashes without reason. I observed this issue only happens for some specific files.

antoniocasero commented 2 years ago

Ok, after exploring why only some files were making the script crash. I found out that if the protocol defines a function without a label, it crashes.

func foo(_ bar: Bar) // It crashes
func foo(bar: Bar) // All good
JavaAdam commented 2 years ago

My project is failing after updating Xcode, as well, but with signal 4.

xargs: [redacted]/Pods/Cuckoo/cuckoo_generator: terminated with signal 4; aborting
Command PhaseScriptExecution failed with a nonzero exit code

Doesn't seem like adding --debug is adding any additional information in this case.

It's the same for me.

samshiffman321 commented 2 years ago

I'm also seeing the same issue after upgrading Xcode to 13.3 cuckoo_generator: terminated with signal 4; aborting

dongdonggaui commented 2 years ago

Ok, after exploring why only some files were making the script crash. I found out that if the protocol defines a function without a label, it crashes.

func foo(_ bar: Bar) // It crashes
func foo(bar: Bar) // All good

It seems that SourceKit has been updated. When parsing parameters without a label such as func foo(_ bar: Bar), the parameter key.nameoffset and key.namelength 2 values are lost.

MatyasKriz commented 2 years ago

Hey everyone! Thanks a lot for the leads, especially @antoniocasero and @dongdonggaui for finding the issue. πŸ™‚ I've verified that the problem is indeed because of the missing properties, though the name range isn't used, so I've just made it optional for now.

I've merged and released the fix, please try it out and let me know if it helped. πŸ™‚

brandtdaniels commented 2 years ago

I've merged and released the fix, please try it out and let me know if it helped. πŸ™‚

Does it take time to propagate the release? The update isn't being picked up when trying to update the package on my end.

MatyasKriz commented 2 years ago

Does it take time to propagate the release?

Which package manager?

brandtdaniels commented 2 years ago

Which package manager?

Sorry, SPM

MatyasKriz commented 2 years ago

I see, that's my bad. The change here is actually in the generator, not Cuckoo itself, but the binary hasn't been uploaded for some reason. I've fixed that, so now the newest one should get downloaded. πŸ™‚

brandtdaniels commented 2 years ago

@MatyasKriz I'm getting this error message when trying to resolve packages:

Dependencies could not be resolved because root depends on 'Cuckoo' 1.7.0..<2.0.0.
'Cuckoo' >= 1.7.0 cannot be used because package 'cuckoo' is required using a stable-version but 'cuckoo' depends on an unstable-version package 'ocmock' and no versions of 'Cuckoo' match the requirement 1.7.1..<2.0.0.
MatyasKriz commented 2 years ago

@brandtdaniels hm, that must be the addition of OCMock, I'll see what I can do. In the meantime, as these changes are in the generator binary only, you can fallback to 1.6.0 for now.

brandtdaniels commented 2 years ago

@brandtdaniels hm, that must be the addition of OCMock, I'll see what I can do. In the meantime, as these changes are in the generator binary only, you can fallback to 1.6.0 for now.

Can you clarify how 1.6.0 on SPM will pick up the new generator? I know there were some steps I took to manually copy some scripts/binaries into the project to get Cuckoo to work with SPM.

MatyasKriz commented 2 years ago

Can you clarify how 1.6.0 on SPM will pick up the new generator?

The run script is responsible for downloading and running the generator. SwiftPM itself is way too limited for that.

MatyasKriz commented 2 years ago

@ajpallares sorry to ping you in this issue, but do you happen to know how to work around the OCMock unstability?

sskjames commented 2 years ago

Hi @MatyasKriz, using cocoapods here, got the Cuckoo 1.7.0 release. It's working for me. Thank you very much for the fix.

ajpallares commented 2 years ago

@MatyasKriz I'm afraid that a simple workaround is not possible. It looks like referencing a dependency using the commit hash or branch name) is considered an "unstable reference" by SPM. And a stable reference, i.e. a tag, can only depend on unstable references... (a better explanation here) This was my mistake, I did not realize of this limitation of the SPM.

This is, in fact, pointed out in the very OCMock repo, but which I did not see beforehand :(

There might be a possible workaround for this, which involves having a local Swift Package which wraps the unstable package. I need to investigate this in depth. We might take advantage of the fact that we actually need to have the Swift wrapper Cuckoo+OCMock.

Sorry for the inconvenience and I hope I can solve this soon using that workaround.

MatyasKriz commented 2 years ago

@ajpallares thanks for the thorough analysis. πŸ™‚ Don't worry about it, this kind of stuff happens. I'm glad you're here to help us push through. I'll release 1.7.1 without the SPM changes for now, so there's no pressure at all.

brandtdaniels commented 2 years ago

@brandtdaniels hm, that must be the addition of OCMock, I'll see what I can do. In the meantime, as these changes are in the generator binary only, you can fallback to 1.6.0 for now.

@MatyasKriz It sounds like you're saying I don't need to do anything and the Bitrise build should just pick up the new generator binary. This doesn't seem to be the case. Can you clarify a little more how an older version of Cuckoo will pickup a new generator binary?

MatyasKriz commented 2 years ago

@brandtdaniels Depending on how you call the run script, you can download a specific version of the generator or the latest one if no version is specified. However, this happens only if there isn't a generator binary already present. To override, pass the `--cleanβ€˜ flag as well.

brandtdaniels commented 2 years ago

@brandtdaniels Depending on how you call the run script, you can download a specific version of the generator or the latest one if no version is specified. However, this happens only if there isn't a generator binary already present. To override, pass the `--cleanβ€˜ flag as well.

Thank you. Bitrise starts clean every build, so I would assume that it would download the generator every time. I did just notice though that we have "cuckoo_generator" committed to our repository. Is having it committed good practice? with SPM?

Locally, I deleted the cuckoo_generator and ran the specs to see if it would download a newer one and I got this error

No Cuckoo Generator found.
~/Developer/git/mobile.crm.ios/CRM ~/Developer/git/mobile.crm.ios/CRM
Couldn't build. Generator source code not found. (expected in the 'Generator' directory)
Downloading version ...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   126  100   126    0     0    372      0 --:--:-- --:--:-- --:--:--   381
Error: Failed to fetch download URL for the Cuckoo Generator.
Command PhaseScriptExecution failed with a nonzero exit code
brandtdaniels commented 2 years ago

To work with SPM, I had to download the latest cuckoo_generator Add execute permissions chmod +x cuckoo_generator and commit to my repository. I was then able to build and run specs on Xcode 13.3.x

MatyasKriz commented 2 years ago

@brandtdaniels I'd highly recommend against commiting binaries into the git repo. Every time you update a binary in git, it essentially doubles in size. I'd also suggest you delete the commits that added the binary in the first place.

The problem you're facing is that there's no way for us to update your run script at the moment, as it has been fixed a while back. Simply download the latest run script from master and run it with arguments --download --clean. Let me know if that works for you.

jgavris commented 2 years ago

If you're using Git LFS (large file storage), you can check in the binaries (cuckoo generator etc) into your repo and mostly have constant size over time, which is not terrible. Aka if you upgrade cuckoo a few times, the overall repo / checkout size won't change.

Git LFS only requires downloading the versions of the files (tracked by LFS) that are reachable from the commit you are checking out, not every delta in between like normal git tracked files. We (and possibly a lot of other Cocoapods users) 'vendor' the entire Pods directory into git repo (checked in) and added this hook to our Podfile to automatically track any files over 300k (change to suite your taste) after running pod install.

post_install do |installer_representation|
  # Update git-lfs tracked files.
  Dir.chdir("Pods") do
    system "rm -f .gitattributes | find . -size +300k | xargs git lfs track"
    system "sort -n .gitattributes > /tmp/.gitattributes && mv /tmp/.gitattributes .gitattributes"
  end
end

Automatic tracking of large files in Git LFS is a highly requested feature (see https://github.com/git-lfs/git-lfs/issues/282), but one fairly easily worked around with a little bit of scripting.

MatyasKriz commented 2 years ago

@jgavris I don't know your setup and I assumed that the binary was not in LFS. Of course, if you want to keep the binary in the repo, it's your call. πŸ™‚

brandtdaniels commented 2 years ago

Simply download the latest run script from master and run it with arguments --download --clean. Let me know if that works for you.

It looks like the run script on master hasn't been updated in 2 years

MatyasKriz commented 2 years ago

Simply download the latest run script from master and run it with arguments --download --clean. Let me know if that works for you.

It looks like the run script on master hasn't been updated in 2 years

I see, time flies. πŸ˜… Though the current version seems to work without problems.

brandtdaniels commented 2 years ago

@brandtdaniels I'd highly recommend against commiting binaries into the git repo. Every time you update a binary in git, it essentially doubles in size. I'd also suggest you delete the commits that added the binary in the first place.

The problem you're facing is that there's no way for us to update your run script at the moment, as it has been fixed a while back. Simply download the latest run script from master and run it with arguments --download --clean. Let me know if that works for you.

After removing the binary from the repo, and adding --clean --download to the script, I am facing the same problem I originally had with Xcode 13.3.x:

 The following build commands failed:
    PhaseScriptExecution Cuckoo\ Run\ Script /Users/vagrant/Library/Developer/Xcode/DerivedData/CRM-gfmkxxwjwsejasaegkkqxuwbswfa/Build/Intermediates.noindex/CRM.build/Debug-iphonesimulator/CRMTests.build/Script-3312E990D1E37BD0916B2578.sh (in target 'CRMTests' from project 'CRM')
(1 failure)
MatyasKriz commented 2 years ago

Let's keep this issue closed and not ping all the other participants with debugging. The original issue has been fixed and now we just need to find out how to get your build script to correctly download the latest binary. Please open a new issue with some more information – if you run the run script by itself with the parameters, does it work? You mentioned something about a custom script, can that cause interference somehow?

ppamorim commented 1 year ago

@MatyasKriz This is not fixed, it's returning signal 9 on cuckoo runner. I tested the version 1.10.1. I have to use the version 1.0.0 to make my tests work. I am using Xcode 14.2.

The code used to generate the mock is:

"${PROJECT_DIR}/Scripts/cuckoo" --clean --download generate --testable "${PROJECT_NAME}" \
--output "${OUTPUT_FILE}" \

Results into:

Generated Mocks File = /Users/me/myProject/MyProjectTests/GeneratedMocks.swift
Mocks Input Directory = /Users/me/myProject/MyProject
Script path: /Users/me/myProject/Scripts
Performing clean build.
No Cuckoo Generator found.
~/Repository/myProject/Scripts ~/Repository/myProject
Downloading latest version...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3891  100  3891    0     0   9305      0 --:--:-- --:--:-- --:--:--  9421
Downloading Cuckoo Generator from URL: https://github.com/Brightify/Cuckoo/releases/download/1.10.1/cuckoo_generator
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

  5 9328k    5  552k    0     0   624k      0  0:00:14 --:--:--  0:00:14  624k
 41 9328k   41 3871k    0     0  2044k      0  0:00:04  0:00:01  0:00:03 3289k
 71 9328k   71 6655k    0     0  2312k      0  0:00:04  0:00:02  0:00:02 3059k
100 9328k  100 9328k    0     0  2509k      0  0:00:03  0:00:03 --:--:-- 3098k
~/Repository/myProject
xargs: /Users/me/myProject/Scripts/cuckoo_generator: terminated with signal 9; aborting
Command PhaseScriptExecution failed with a nonzero exit code

Generated Mocks File = /Users/me/myProject/MyProjectTests/GeneratedMocks.swift

Mocks Input Directory = /Users/me/myProject/MyProject

Script path: /Users/me/myProject/Scripts

Performing clean build.

No Cuckoo Generator found.

~/Repository/myProject/Scripts ~/Repository/myProject

Downloading latest version...

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3891  100  3891    0     0   9305      0 --:--:-- --:--:-- --:--:--  9421

Downloading Cuckoo Generator from URL: https://github.com/Brightify/Cuckoo/releases/download/1.10.1/cuckoo_generator

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

  5 9328k    5  552k    0     0   624k      0  0:00:14 --:--:--  0:00:14  624k
 41 9328k   41 3871k    0     0  2044k      0  0:00:04  0:00:01  0:00:03 3289k
 71 9328k   71 6655k    0     0  2312k      0  0:00:04  0:00:02  0:00:02 3059k
100 9328k  100 9328k    0     0  2509k      0  0:00:03  0:00:03 --:--:-- 3098k

~/Repository/myProject

xargs: /Users/me/myProject/Scripts/cuckoo_generator: terminated with signal 9; aborting

Command PhaseScriptExecution failed with a nonzero exit code