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

[SR-5027] typo in the tests directory name leads to linker errors in SwiftPM #5004

Closed
weissi opened this issue May 26, 2017 · 3 comments
Closed
Labels

Comments

@weissi
Copy link
Member

weissi commented May 26, 2017

Previous ID SR-5027
Radar None
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 734451aac566b34f637735a73a8ff5c7

relates to:

  • SR-9359 SwiftPM should have better diagnostics if tests depend on executable target

Issue Description:

tl;dr When having a typo in the tests directory name, the module to be tested doesn't get linked.

Full version

I have a project with the following structure

├── Package.swift
├── Tests
│   ├── LinuxMain.swift
│   └── SwiftPMOddErrorzTests
│       └── SwiftPMOddErrorsTests.swift
└── src
    └── SwiftPMOddErrors
        └── something.swift

the package manifest declares a target SwiftPMOddErrors:

// swift-tools-version:3.1

import PackageDescription

let package = Package(
    name: "swiftpm-odd-errors",
    targets: [
        Target(name: "SwiftPMOddErrors")
    ]
)

the code for that module is in src/SwiftPMOddErrors.

In the Tests directory, I have a directory called Tests/SwiftPMOddErrorz (notice Error_z_ vs Error_s_, ie a small typo).

Compiling that project with swift build works just fine but running the tests (swift test) leads to

Linking ./.build/debug/swiftpm-odd-errorsPackageTests.xctest/Contents/MacOS/swiftpm-odd-errorsPackageTests
Undefined symbols for architecture x86_64:
  "__TF16SwiftPMOddErrors3mooFT_T_", referenced from:
      __TFC21SwiftPMOddErrorzTests16SwiftPMOddErrors7testMoofT_T_ in SwiftPMOddErrorsTests.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /private/tmp/swiftpm-odd-errors/.build/debug.yaml test

Checking the compiler/linker invocations from swift test -v, we can see that the module SwiftPMOddErrors (the one with the correct name) isn't actually included in the build:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -target 'x86_64-apple-macosx10.10' -sdk '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk' -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -g -L/private/tmp/swiftpm-odd-errors/.build/debug -o /private/tmp/swiftpm-odd-errors/.build/debug/swiftpm-odd-errorsPackageTests.xctest/Contents/MacOS/swiftpm-odd-errorsPackageTests -module-name swiftpm-odd-errorsPackageTests -Xlinker -bundle /private/tmp/swiftpm-odd-errors/.build/debug/SwiftPMOddErrorzTests.build/SwiftPMOddErrorsTests.swift.o

That's because the other-args section in debug.yaml's "<SwiftPMOddErrorzTests.module>" doesn't contain the module map for the SwiftPMOddErrors module.

My guess is that when SwiftPM tried to link a tests module XXXTests it automatically adds the module XXX 's module map and everything works. Now if you mistype the tests to XXYTests, then it tries to find module XXY but doesn't find it. Unfortunately it doesn't output any diagnostics...

Please find attached a tar ball with a minimal repro repo. The first commit contains the working state and the second commit then breaks it. The diff is

$ git show HEAD
commit aac0c0b1d0e40ef7906c51929f8fd50fcf5f890e
Author: Johannes Weiß <johannesweiss@apple.com>
Date:   Fri May 26 15:55:18 2017 +0100

    now broken

diff --git a/Tests/SwiftPMOddErrorsTests/SwiftPMOddErrorsTests.swift b/Tests/SwiftPMOddErrorzTests/SwiftPMOddErrorsTests.swift
similarity index 100%
rename from Tests/SwiftPMOddErrorsTests/SwiftPMOddErrorsTests.swift
rename to Tests/SwiftPMOddErrorzTests/SwiftPMOddErrorsTests.swift
@ankitspd
Copy link
Member

This is expected, we establish an automatic dependency if there are `Foo` and `FooTest` targets. In all other cases, you need to manually specify the dependency.

The automatic dependency rule is removed from V4 manifest, so you will always need to specify the dependencies in the new manifest.

@weissi
Copy link
Member Author

weissi commented May 30, 2017

@aciidb0mb3r but it should be a compiler error not a linker error, right?

@ankitspd
Copy link
Member

Yeah, see: https://bugs.swift.org/browse/SR-1393

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants