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-13393] Swift Tools 5.3-5.5 Package Manager (& Xcode 12-13.0) incorrectly emit errors for .swift files as "unhandled" #4509

Open
haikusw opened this issue Aug 14, 2020 · 3 comments
Labels

Comments

@haikusw
Copy link

haikusw commented Aug 14, 2020

Previous ID SR-13393
Radar rdar://67093441
Original Reporter @haikusw
Type Bug

Attachment: Download

Environment

macOS 10.15.6

Xcode 12 beta 4:

% xcode-select -p
/Applications/Xcode-beta.app/Contents/Developer

% swift --version
Apple Swift version 5.3 (swiftlang-1200.0.25.2 clang-1200.0.27.1)
Target: x86_64-apple-darwin19.6.0
% swift package --version
Swift Package Manager - Swift 5.3.0
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 3707421ab7f141cc629e3e38c88758b8

Issue Description:

Swift package manager (and Xcode 12 b 4) have trouble in a simple command line tool package with a single module. It gets confused about the swift files in the module sub-directory and shows errors about "found N file(s) which are unhandled; ..."

% xcrun swift package describe

error: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target

~/bugtest/Sources/module1/file1.swift

Changing the swift-tools-version:5.3 to 5.2 resolves the issue.

This error makes it impossible to build these packages on the command line or in Xcode because the targets do not seem to be recognized properly.

Here's the package file:

// swift-tools-version:5.3
import PackageDescriptionlet package = Package(
  name: "bugtest",
  products: [
    .executable(
      name: "bugtest",
      targets: ["bugtest"]),
    .library(
      name: "module1",
      targets: ["module1"]),
  ],
  dependencies: [],
  targets: [
    .target(
      name: "bugtest",
      dependencies: ["module1"],
      path: "Sources",
      sources: ["main.swift"]),
    .target(
      name: "module1",
      dependencies: []),
    .testTarget(
      name: "bugtestTests",
      dependencies: ["bugtest"]),
  ]
)

and the file hierarchy:

bugtest/Package.swift
bugtest/README.md
bugtest/Sources
bugtest/Sources/main.swift
bugtest/Sources/module1
bugtest/Sources/module1/file1.swift
bugtest/Tests
bugtest/Tests/bugtestTests
bugtest/Tests/bugtestTests/bugtestTests.swift
bugtest/Tests/bugtestTests/XCTestManifests.swift
bugtest/Tests/LinuxMain.swift

If you run package describe you get the following:

// with Package.swift first line: // swift-tools-version:5.3
 
% xcrun swift package describe  
error: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    /Users/tyler/bugtest/Sources/module1/file1.swift


Name: bugtest
Path: /Users/tyler/bugtest
Modules:
    Name: module1
    C99name: module1
    Type: library
    Module type: SwiftTarget
    Path: /Users/tyler/bugtest/Sources/module1
    Sources: file1.swift


    Name: bugtestTests
    C99name: bugtestTests
    Type: test
    Module type: SwiftTarget
    Path: /Users/tyler/bugtest/Tests/bugtestTests
    Sources: XCTestManifests.swift, bugtestTests.swift


    Name: bugtest
    C99name: bugtest
    Type: executable
    Module type: SwiftTarget
    Path: /Users/tyler/bugtest/Sources
    Sources: main.swift

change the first line of the Package.swift file to 5.2 and it works as expected (the files are auto-discovered in the module source folder inside the Sources directory):

// with Package.swift first line: // swift-tools-version:5.2

% xcrun swift package describe
Name: bugtest
Path: /Users/tyler/bugtest
Modules:
    Name: module1
    C99name: module1
    Type: library
    Module type: SwiftTarget
    Path: /Users/tyler/bugtest/Sources/module1
    Sources: file1.swift


    Name: bugtestTests
    C99name: bugtestTests
    Type: test
    Module type: SwiftTarget
    Path: /Users/tyler/bugtest/Tests/bugtestTests
    Sources: XCTestManifests.swift, bugtestTests.swift


    Name: bugtest
    C99name: bugtest
    Type: executable
    Module type: SwiftTarget
    Path: /Users/tyler/bugtest/Sources
    Sources: main.swift

Explicit specification of the path: and sources: in the "module1" target does not work around this issue. It prevents building on the command line or in Xcode because the targets are not understood properly.

Sample package directory attached.

Also filed via FeedbackAssistant:
{{ https://feedbackassistant.apple.com/feedback/8401865}}

@haikusw
Copy link
Author

haikusw commented Aug 31, 2020

Still an issue in Xcode tools 12b6.

Significant problem in that it seems to mean that a command line tool (`.executable` product) cannot use modules which makes it hard to write automated tests.

Only option seems to be to dial back to swift 5.2 and not use resource files (test data files) which makes the `.resources` enhancement unusable in this context.

@haikusw
Copy link
Author

haikusw commented Sep 20, 2020

Still an issue in Xcode tools 12GM 12A7209 🙁

Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
Target: x86_64-apple-darwin19.6.0

and downloading the package and running the indicated command produces the same output:

bugtest % xcrun swift package describe
 warning: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
 /Users/tyler/Desktop/bugtest/Sources/module1/file1.swift

Name: bugtest
 Path: /Users/tyler/Desktop/bugtest
 Modules:
 Name: module1
 C99name: module1
 Type: library
 Module type: SwiftTarget
 Path: /Users/tyler/Desktop/bugtest/Sources/module1
 Sources: file1.swift
Name: bugtestTests
 C99name: bugtestTests
 Type: test
 Module type: SwiftTarget
 Path: /Users/tyler/Desktop/bugtest/Tests/bugtestTests
 Sources: XCTestManifests.swift, bugtestTests.swift
Name: bugtest
 C99name: bugtest
 Type: executable
 Module type: SwiftTarget
 Path: /Users/tyler/Desktop/bugtest/Sources
 Sources: main.swift

and switching `swift-tools-version:5.3` to use 5.2 fixes is as before, but then one can't use resources... :-/

@haikusw
Copy link
Author

haikusw commented Sep 24, 2021

Issue still present in Xcode 13.0 / Swift 5.5.

Further, if I update the swift-tools-version line in the Package.swift file to 5.5, and updated the `target` for "bugtest" to be an `.executableTarget` for swift 5.4 and later, then I get the same warning whenever I use the package or describe it (though it executes properly)…

bugtest % swift run
'bugtest' /Users/tyler/Desktop/bugtest: warning: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    /Users/tyler/Desktop/bugtest/Sources/module1/file1.swift


[5/5] Build complete!
Hello cruel world...

and

bugtest % swift test
'bugtest' /Users/tyler/Desktop/bugtest: warning: found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    /Users/tyler/Desktop/bugtest/Sources/module1/file1.swift


[4/4] Build complete!
Test Suite 'All tests' started at 2021-09-24 15:32:44.982
Test Suite 'bugtestPackageTests.xctest' started at 2021-09-24 15:32:44.982
Test Suite 'bugtestTests' started at 2021-09-24 15:32:44.982
Test Case '-[bugtestTests.bugtestTests testExample]' started.
Test Case '-[bugtestTests.bugtestTests testExample]' passed (0.001 seconds).
Test Suite 'bugtestTests' passed at 2021-09-24 15:32:44.984.
     Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'bugtestPackageTests.xctest' passed at 2021-09-24 15:32:44.984.
     Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'All tests' passed at 2021-09-24 15:32:44.984.
     Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.002) seconds

An updated package that uses swift-tools 5.5 will be attached: updated_bugtest.zip

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