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-66] Unsupported source layout doesn't error as expected #5402

Closed
swift-ci opened this issue Dec 5, 2015 · 11 comments
Closed

[SR-66] Unsupported source layout doesn't error as expected #5402

swift-ci opened this issue Dec 5, 2015 · 11 comments
Assignees
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Dec 5, 2015

Previous ID SR-66
Radar None
Original Reporter py (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee @mxcl
Priority Medium

md5: 5cbcbb0092370ff69ffe83ac2bae3689

Issue Description:

As discussed on the swift-build-dev mailing list, when running swift build on the following directory structure, types defined in A.swift are considered to be undeclared in B.swift.

Sources/A.swift
Sources/B/B.swift

This ticket serves as a place to diagnose the issue and improve documentation, as requested by @ddunbar

It was suggested by @mxcl that this layout should either be supported or error.

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 5, 2015

Comment by Yavuz Nuzumlali (JIRA)

Max Howell, actually I want to challenge this one and make this layout supported, but I feel there would be an ambiguity in this case. Should we assume the following:

  • There will be one target if there is any swift source file in the root directory.

  • If there is no source files in root directory, we should treat each folder as a target, and behave accordingly.

Other than that, I think it's really hard to decide when a directory should be treated as a target or just a source container.

If you could make the decision, I can help with the implementation if it's good for you.

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 7, 2015

Comment by Kostiantyn Koval (JIRA)

Currently this layout would produce:
B.a library and A.Swift would be ignored.

.build/B.a

There could many a

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 7, 2015

Comment by Yavuz Nuzumlali (JIRA)

Yeah, it directly ignores source files inside the root directory if there is a subdirectory inside the root.

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 7, 2015

Comment by Kostiantyn Koval (JIRA)

I can image many ambiguity situations. So I would prefer to show warning and warn user that A.swift file is ignored.

Examples:

Sources/A.swift
Sources/B/B.swift
//Creates A.a library (B.swift is included to it)

Sources/A.swift
Sources/C/main.swift
Sources/B/B.swift
//Creates C executable (with A.swift and B.swift included)

Sources/main.swift
Sources/C/main.swift
Sources/B/B.swift
//What should happened in that case?

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 7, 2015

Comment by Yavuz Nuzumlali (JIRA)

Is it acceptable for a package to have two `main.swift` files, or should it be acceptable? I can't imagine a case where an executable module wants to include another executable submodule. Maybe we can force packages to have just one `main.swift` file?

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 7, 2015

Comment by Kostiantyn Koval (JIRA)

Right now you can have 2 separate independent executables in package. As for me it's correct behaviour.
You could be working on a project that makes 2 command lien tools that reuses some common lib.a in one Package

Sources/C/main.swift
Sources/F/main.swift

Compiling Swift Module 'f' (1 sources)
Compiling Swift Module 'c' (1 sources)
Linking Executable:  .build/debug/c
Linking Executable:  .build/debug/f

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 7, 2015

Comment by Yavuz Nuzumlali (JIRA)

Your sample is perfectly valid because you include them for separate targets. I have meant to have one in root dir, one in target dir. But yeah, your case shows checking for multiple `main.swift` is not enough, we need a hierarchical check.

@mxcl@ddunbar, thoughts on this? I'm personally OK with preventing this also, because now I feel that it may be hard to clearly discriminate for user when directories will be interpreted as modules and when they will be interpreted as just ordinary directories.

However, current situation definitely causes ambiguity.

@mxcl
Copy link
Contributor

mxcl commented Dec 7, 2015

I don't think it should be supported because if you have this:

    Sources/A/A.swift
    Sources/B/B.swift

And then accidentally create:

    Sources/C.swift

You project would transition from 2 targets to 1 target with unexpected compile errors.

So I prefer the warning that `C.swift` would be ignored from these suggestions.

This means that in order to have a single target with subdirectories for source organization you would need to layout it out with a single level of nesting. Or you would need to override the configuration for the Package in the Package.swift.

—Which is non-ideal, however I think we are preferring workflows for many-module projects rather than single module targets.

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 8, 2015

Comment by Yavuz Nuzumlali (JIRA)

Seems reasonable to me. With improved layout documentation, I don't think we will have much trouble.

I will add presenting warning to users for such cases. We can continue discussion under my future PR.

@mxcl
Copy link
Contributor

mxcl commented Dec 24, 2015

Latest master considers this invalid. However I am torn about it. I think maybe we should make it valid as it quite common for users to start a project with sources in Sources/ and then as they work begin organizing it into subfolders.

@ddunbar
Copy link
Member

ddunbar commented Dec 25, 2015

What would it mean? Would the sources there be one target and subfolders other targets? Or would it all form a single target?

IMHO it is easy enough to transition layouts, esp. if the diagnostics are good, but I don't have a very strong opinion on it.

@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

3 participants