swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

[SR-13739] 'Unexpected duplicate tasks' error when using Swift Package with bundle resources linked from a Unit Test Target #4486

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-13739
Radar rdar://70332761
Original Reporter claus.joergensen@outlook.com (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 33 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 5f0ef4b08bb215cba06309b7378264e9

Issue Description:

Xcode fails to builds a test target linked to a framework that imports a Swift Package

error: Unexpected duplicate tasks:
Target 'MyAppTests' (project 'MyApp') has copy command from 'SchibstedAccount_SchibstedAccount.bundle' to 'SchibstedAccount_SchibstedAccount.bundle'
Target 'MyAppTests' (project 'MyApp') has copy command from 'SchibstedAccount_SchibstedAccount.bundle' to 'SchibstedAccount_SchibstedAccount.bundle' 

See attached sample project. The error occurs when building the Test target, there's no errors for the App target.

This is an issue in both Xcode 12.0.1 and Xcode 12.2 beta 3.

I've also filed it as a Xcode bug (FB8802612)

swift-ci commented 4 years ago

Comment by Eric Yanush (JIRA)

I also have an open feedback item for this issue (FB8751233).

swift-ci commented 3 years ago

Comment by Marco Eidinger (JIRA)

I upvoted because this issue affects test targets for all apps which import any Swift Package that is bundling resources.

My team is building a Swift Package with swift-tools-version 5.3 to bundle resources. We would like to make use of swift snapshot-testing on a test target of an example app consuming our Swift Package. But this will not work because of issue SR-13739

Edit: I also created a feedback item for this issue (FB8891315)

swift-ci commented 3 years ago

Comment by David Xu (JIRA)

I will upvote this issue since my app hit the same problem.

swift-ci commented 3 years ago

Comment by Bill Zhou (JIRA)

Looking for solution here

swift-ci commented 3 years ago

Comment by Eric Yanush (JIRA)

I'd encourage anyone else encountering this issue to file a bug via Feedback Assistant; Apple has stated in the past that the more radars (now feedback assistant items) they receive for a given issue, the quicker it gains visibility at Apple.

sjavora commented 3 years ago

Upvoted and reported in Feedback Assistant as FB8893830.

swift-ci commented 3 years ago

Comment by Angelo Di Paolo (JIRA)

Seeing the a similar issue except I'm not seeing it in a test target. I'm seeing this when adding a binary dependency package to a static framework target.

error: Unexpected duplicate tasks:
1) Target 'Scanner' (project 'Scanner') has copy command from '/Users/adipaol/Library/Developer/Xcode/DerivedData/App-fbbprhzekdwjqlglulryiasshtmd/SourcePackages/artifacts/DMSDK/DMSDK.xcframework/ios-i386_x86_64-simulator/DMSDK.framework' to '/Users/adipaol/Library/Developer/Xcode/DerivedData/App-fbbprhzekdwjqlglulryiasshtmd/Build/Products/Debug-iphonesimulator/Scanner.framework/Frameworks/DMSDK.framework'
2) Target 'Scanner' (project 'Scanner') has copy command from '/Users/adipaol/Library/Developer/Xcode/DerivedData/App-fbbprhzekdwjqlglulryiasshtmd/SourcePackages/artifacts/DMSDK/DMSDK.xcframework/ios-i386_x86_64-simulator/DMSDK.framework' to '/Users/adipaol/Library/Developer/Xcode/DerivedData/App-fbbprhzekdwjqlglulryiasshtmd/Build/Products/Debug-iphonesimulator/Scanner.framework/Frameworks/DMSDK.framework'
swift-ci commented 3 years ago

Comment by Dirko Swanepoel (JIRA)

Also getting this on the app target.

Unexpected duplicate tasks:
1) Target '[REDACTED]' (project '[REDACTED]') has copy command from '/Users/[REDACTED]/Library/Developer/Xcode/DerivedData/[REDACTED]-exyzolodqlyjnvcxnmutwlnnsrry/SourcePackages/artifacts/GoogleMapsUtils/GoogleMapsUtils.xcframework/ios-arm64_i386_x86_64-simulator/GoogleMapsUtils.framework' to '/Users/[REDACTED]/Library/Developer/Xcode/DerivedData/[REDACTED]-exyzolodqlyjnvcxnmutwlnnsrry/Build/Products/Debug-iphonesimulator/[REDACTED].app/Frameworks/GoogleMapsUtils.framework'
2) Target '[REDACTED]' (project '[REDACTED]') has copy command from '/Users/[REDACTED]/Library/Developer/Xcode/DerivedData/[REDACTED]-exyzolodqlyjnvcxnmutwlnnsrry/SourcePackages/artifacts/GoogleMapsUtils/GoogleMapsUtils.xcframework/ios-arm64_i386_x86_64-simulator/GoogleMapsUtils.framework' to '/Users/[REDACTED]/Library/Developer/Xcode/DerivedData/[REDACTED]-exyzolodqlyjnvcxnmutwlnnsrry/Build/Products/Debug-iphonesimulator/[REDACTED].app/Frameworks/GoogleMapsUtils.framework'
swift-ci commented 3 years ago

Comment by Simon-Pierre Roy (JIRA)

I also get this and created a feedback entry.

But I discovered that removing `allow testing host application apis` from the test target (need to remove all code needing `@testable import APP_NAME`) will remove the duplicate copy task! This is not a real solution, since you can not test symbols in that app module.

gwynne commented 3 years ago

Still occurs in Xcode 12.4.

Mordil commented 3 years ago

Still occurs in Xcode 12.5 Beta 1 & 2

Mordil commented 3 years ago

Still reproduces in Xcode 12.5 Beta 3

swift-ci commented 3 years ago

Comment by Pär Gregersson (JIRA)

The only workaround I have found is to remove the framework from linked libraries and manually add the -framework SomethingKit to the Other linker flags in the test targets build settings.
Hopefully this might help someone else.

Edit: And if you need to link a swift package framework manually, try adding $(BUILT_PRODUCTS_DIR)/PackageFrameworks to the Framework search paths.

swift-ci commented 3 years ago

Comment by Eric Yanush (JIRA)

I can confirm that the workaround gregersson (JIRA User) posted does work!

Now that it's been suggested, I feel a bit foolish not having tried manually linking framework built by SwiftPM to the test target before now.

swift-ci commented 3 years ago

Comment by F H (JIRA)

I can confirm that the workaround gregersson (JIRA User) posted also fixes the issue `error: Unexpected duplicate tasks: 1) Command: ProcessXCFramework`

jsorge commented 3 years ago

I'm attempting to put this workaround in and it's not working for me. Even in the attached sample app, if I remove `SomethingKit` from the linked libraries to `MyAppTests` and add `-framework SomethingKit` to the `MyAppTests` build settings, I still get the duplicate tasks error. This is on Xcode 12.4. What am I doing wrong here?

mayoff commented 3 years ago

I was not able to work around the problem by adding -framework SomethingKit to Other Linker Flags (aka OTHER_LDFLAGS).

I was able to work around it by not linking SomethingKit against MyAppTests at all. Instead, I added -undefined dynamic_lookup to Other Linker Flags for MyAppTests. Because MyAppTests is only ever loaded into a running MyApp process, and MyApp links SomethingKit, MyAppTests is able to find the symbols it needs at runtime.

(Note that the Host Application for MyAppTests is set to MyApp in the General tab of the MyAppTests configuration. That's why it is loaded into a MyApp process.)

swift-ci commented 3 years ago

Comment by Rogerio de Paula Assis (JIRA)

Thanks @mayoff that was the only solution that would allow us to successfully build and run our unit test target!

Mordil commented 3 years ago

This is still reproducing with Xcode 12.5 RC (12E262)

swift-ci commented 3 years ago

Comment by Dave Paul (JIRA)

+1. Not working as of Xcode 12.5 RC This is a major blocker for us moving to SPM.

I tried the workarounds listed above and managed to get the tests running, only to crash due to runtime dependency issues.

swift-ci commented 3 years ago

Comment by Joseph Ross (JIRA)

I'm seeing the same issue after upgrading to Xcode 12.5. The interesting twist in my case is that the tests pass when I run from the Xcode GUI, but fail when I run the tests from the command line.

Mordil commented 3 years ago

This does not appear to reproduce with the Xcode 13 Beta 1 build! (13A5154h)

swift-ci commented 3 years ago

Comment by Tassio Moreira Marques (JIRA)

I'm facing the same issue with Appboy_iOS_SDK_AppboyKit.bundle in Xcode 12.5 (12E262).

swift-ci commented 3 years ago

Comment by Eric Yanush (JIRA)

tassiomm (JIRA User) this was fixed in Xcode 13, try upgrading to Xcode 13 and re-compiling.

swift-ci commented 3 years ago

Comment by Tassio Moreira Marques (JIRA)

e.yanush (JIRA User) man, that sucks. My code is not really ready for XCode 13. I was hoping I didn't really need that lol
Thanks!