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-15715] SwiftPM resource access with 'url(forResource:…)' is inconsistent (at best) and causes "core dumped" (at worst) #4363

Open
swift-ci opened this issue Jan 11, 2022 · 0 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-15715
Radar None
Original Reporter --marc (JIRA User)
Type Bug

Attachment: Download

Environment

macOS CLI (command line)

  • Swift Package Manager - Swift 5.5.0

  • swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)

  • Target: x86_64-apple-macosx11.0

  • macOS: macOS 11.6.2 (20G314)

macOS Xcode

  • Version 13.2.1 (13C100)

Linux CLI (command line)

  • Swift Package Manager - Swift 5.5.0

  • Swift version 5.5.2 (swift-5.5.2-RELEASE)

  • Target: x86_64-unknown-linux-gnu

  • Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-92-generic x86_64)

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

md5: 5b8896cfd86d3915bdc8affb3b131069

Issue Description:

The `url(forResource:withExtension:subdirectory:localization: )` resource location method is (at best) inconsistent across platforms and can (at worst) cause a "core dumped" error when used with a Swift Package which includes resources.

The attached `CLIQuickstartLib` project is a standalone, very-close-to-minimal Swift Package which is set up to evaluate access approaches to package resources. Resources are included for each of the targets: library, executable and tests.

The resource access evaluation scenarios factors include:

  • platform: Linux, macOS

  • build chain execution: Linux command line interface (CLI), macOS command line interface (CLI), macOS Xcode IDE (open from Package.swift directly, not an `generate-xcodeproj`)

  • top level resources directory name: `Resources` or something else

  • resource asset directory level: top level or some sub directory

  • use of localization

In particular, the `checkResourceAccessApproaches()` method in `SpmHelper.swift` partially enumerates various ways that `url(forResource:withExtension:…)` might be called to access package resources.

In general, `url(forResource: …)` is expected to reliably handle cross-platform differences in a reliably consistent and robust way. However, it does not.

However, here is a table of what was observed:

(subdirectory) `forResource:` Linux CLI macOS CLI macOS Xcode
*`Resources/resource_file_tool.txt`*
`(Resources)resource_file_tool.txt`
`resource_file_tool.txt`
*`Resources/resource_file_lib.txt`*
`(Resources)resource_file_lib.txt`
`resource_file_lib.txt`
*`Resources/img/watch.jpg`*
`(Resources/img)watch.jpg`
`img/watch.jpg`
`(img)watch.jpg`
`watch.jpg`
*`Resources_A/resource_file_lib_a.txt`*
`(Resources_A)resource_file_lib_a.txt`
`resource_file_lib_a.txt`
*`Resources_A/img/electricity.jpg`*
`(Resources_A/img)electricity.jpg`
`img/electricity.jpg`
`(img)electricity.jpg`
`electricity.jpg`
"en" *`Resources/LocalData00.json`*
"en" `(Resources)LocalData00.json`
"en" `LocalData00.json`
"es-MX" `LocalData00.json`
"en" `Resources/DataFiles/…/LocalData01.json`
"en" `Resources_A/…/LocalData10.json`
"en" `Resources_A/DataFiles/…/LocalData11.json`

⚑ Fatal Runtime Error (Linux CLI)

# Foundation/NSCFString.swift:119: Fatal error: Constant strings cannot be deallocated
# Illegal instruction (core dumped)

Issues

  • Top level resource assets can not accessed in a uniform, reliable way across platforms. (i.e. without using #if os(…))

  • Top level resource directory name affects how assets can be successfully accessed.

  • In some cases, Swift Foundation on Linux exhibits a fatal "core dumped" runtime error. (this really should fail more gracefully!)

  • Localized files cannot be access in the same way on the Linux and macOS command build/test/run.

  • Localized files cannot be access via the localization argument if `Package.swift` is opened with Xcode.

Replication Steps

Run the `CLIQuickstartLib` package on the macOS and Linux terminal command line.

 swift build
 swift run
 swift test
 

For Xcode, open Package.swift directly. Do not use `generate-xcodeproj`. Set the schema to "CLIQuickstartTool > My Mac". Use the Xcode menus "Product > Build", "Product > Run", and "Product > Test"

Look at the console results in all cases.

@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