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-13084] Resource declarations with no content should raise warning #4530

Open
swift-ci opened this issue Jun 25, 2020 · 5 comments
Open

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-13084
Radar rdar://problem/64947439
Original Reporter Sherlouk (JIRA User)
Type Improvement

Attachment: Download

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

md5: 1559a4bf57fa42180de74c45645fced2

Issue Description:

I discovered in testing resources in a Swift package that if you reference a file or directory that does not exist you get no `Bundle.module` generated but no warning/error is thrown.

This makes it harder to discover the flaw as it's not immediately clear that the fault is with your package definition.

I think it would be helpful if, when the package definition is parsed, a warning was provided to the user informing them that one of their resource definitions was invalid - "no resources were found at the path given".

I've attached a sample project which demonstrates me trying to access missing resources via the copy and process methods - and the fact I can't access `Bundle.module` (which does make sense). This is otherwise the template app you get from New -> Swift Package.

Tested in Xcode 12.0 Beta 1 (12A6159) with macOS as the build target and Swift 5.3.

@abertelrud
Copy link
Contributor

@swift-ci create

@abertelrud
Copy link
Contributor

Since the error about the missing symbols comes from the compiler, it's a bit tricky to intercept the error message. One option would be to always generate the module accessor as a stub, and to mark it as unavailable so that you get a compile time error explaining that no resource bundle was generated used because there were no resources in the target (and then the target name, etc). I don't know the exact syntax but I know there is a way to mark a property as unavailable.

@swift-ci
Copy link
Contributor Author

Comment by James Sherlock (JIRA)

Interesting idea there Anders about marking a property as unavailable, the syntax appears to be something like this:

@available(*, unavailable, message: "...")

This would be changes in the BuildPlan.swift (https://github.com/apple/swift-package-manager/blob/master/Sources/Build/BuildPlan.swift#L588-L596) – just need to work out where the check is for whether there are any resources available and route that through to the method. Once we have that simple availability boolean passed to the right function it's a trivial case of injecting the "available" declaration into the template.

Alternatively, I wonder if we are able to detect this earlier in the chain? I see within the PackageDescription4Loader.swift (https://github.com/apple/swift-package-manager/blob/master/Sources/PackageLoading/PackageDescription4Loader.swift#L149-L151) we actually trigger an error if you attempt to supply an empty array for resources. Do you think it's reasonable to further expand this logic to check for valid resources at the path given or is this the wrong time to be making this check?

What do you think?

@swift-ci
Copy link
Contributor Author

Comment by James Sherlock (JIRA)

Initial experiment with part A of the above comment:

Sherlouk@3647a6a

@swift-ci
Copy link
Contributor Author

Comment by James Sherlock (JIRA)

Merge Request: #2789

(This includes part B of the suggestion above)

@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
Projects
None yet
Development

No branches or pull requests

3 participants