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

Generated mocks don't work on Xcode Cloud #339

Closed
legoesbenr opened this issue Sep 13, 2024 · 1 comment
Closed

Generated mocks don't work on Xcode Cloud #339

legoesbenr opened this issue Sep 13, 2024 · 1 comment
Labels
generator bug Causes malformed generated code

Comments

@legoesbenr
Copy link

New Issue Checklist

Overview

I have recently run into a weird issue with mocking in our iOS unit tests.
Mocking and our unit tests works just fine locally and it has also worked fine when building on Xcode Cloud.
Until recently, when it started to throw this error:

Operation '<MockingbirdGenerator.GenerateFileOperation: 0x7fb81740beb0>' failed with error 'Error Domain=NSCocoaErrorDomain Code=516 "“AppNameMocks.generated.swift” couldn’t be moved to “MockingbirdMocks” because an item with the same name already exists."

From the error message the problem is quite obvious, but there are not changes to our the post build script, which have worked fine for almost a year on Xcode Cloud.
Our PostBuildScript looks like this:

set -eu

# Prevent Xcode 13 from running this script while indexing.
[[ "${ACTION}" == "indexbuild" ]] && exit 0

# Infer the derived data location from the build environment.
[[ -z "${DERIVED_DATA+x}" ]] && DERIVED_DATA="$(echo "${BUILD_ROOT}" | sed -n 's|\(.*\)/Build/.*|\1|p')"

"${DERIVED_DATA}/SourcePackages/checkouts/mockingbird/mockingbird" generate --targets "AppName" "AppName" --outputs "${SRCROOT}/MockingbirdMocks/AppNameMocks.generated.swift" "${SRCROOT}/MockingbirdMocks/AppNameMocks.generated.swift"

Environment

  • Mockingbird via SPM version 0.20.0
  • Xcode 15.4 and Swift version 5.2
  • Swift Package manager
  • XCTest
  • Custom configuration
    • none
@legoesbenr legoesbenr added the generator bug Causes malformed generated code label Sep 13, 2024
@legoesbenr
Copy link
Author

I found that we have two targets after each other in the command and the output defined twice, in the command.
Reducing this to one target and one output parameter fixed it. Don't know how this worked for 1+ year.

Also; the documentation is extremely thin and actually wrong compared to the example (if you look at the post build script).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator bug Causes malformed generated code
Projects
None yet
Development

No branches or pull requests

1 participant