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-3982] Add support for directories in /Sources in package manager #5102

Closed
swift-ci opened this issue Feb 17, 2017 · 2 comments
Closed

[SR-3982] Add support for directories in /Sources in package manager #5102

swift-ci opened this issue Feb 17, 2017 · 2 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3982
Radar None
Original Reporter petaren (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

MacOS 10.12.3
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9
Xcode: Version 8.2.1 (8C1002)

Tested and Verified on Ubuntu 16.04 too:
Swift version 3.0.2 (swift-3.0.2-RELEASE)
Target: x86_64-unknown-linux-gnu

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

md5: 4b56fd7b3b6a10be28430c3b9f7314e2

Issue Description:

It is not possible to have any subdirectories under the Sources/ directory. Creating subdirectories gives the following error:

error: the package has an unsupported layout, unexpected source file(s) found: /Users/petar/Downloads/SwiftPackageTest/Sources/main.swift
fix: move the file(s) inside a module

One should be able to organize code using subdirectories. Not being able to do so will make the folder structure hard to maintain over time.

See example demonstrating this below:

()==[:::::::::::::>  ~/Downloads/SwiftPackageTest @ Petar-MBP (petar) 
$swift package init --type executable
Creating executable package: SwiftPackageTest
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/main.swift
Creating Tests/
()==[:::::::::::::>  ~/Downloads/SwiftPackageTest @ Petar-MBP (petar) 
$swift build
Compile Swift Module 'SwiftPackageTest' (1 sources)
Linking ./.build/debug/SwiftPackageTest
()==[:::::::::::::>  ~/Downloads/SwiftPackageTest @ Petar-MBP (petar) 
$./.build/debug/SwiftPackageTest
Hello, world!
()==[:::::::::::::>  ~/Downloads/SwiftPackageTest @ Petar-MBP (petar) 
$mkdir Sources/folder_to_organize_code
()==[:::::::::::::>  ~/Downloads/SwiftPackageTest @ Petar-MBP (petar) 
$swift build
error: the package has an unsupported layout, unexpected source file(s) found: /Users/petar/Downloads/SwiftPackageTest/Sources/main.swift
fix: move the file(s) inside a module
()==[:::::::::::::>  ~/Downloads/SwiftPackageTest @ Petar-MBP (petar) 
@ankitspd
Copy link
Member

Directories under Sources/ acts as Swift modules. The rules for layouts is here: https://github.com/apple/swift-package-manager/blob/master/Documentation/Reference.md#module-format-reference

You can arrange your sources inside a module's directory when using multiple module layout, something like this:

One module layout example (this has one executable module)
.
├── Package.swift
└── Sources
    └── main.swift

Multiple module layout example (this has two modules one executable and one library. The exe module has a subdir models.)
.
├── Package.swift
└── Sources
    ├── exe
    │   ├── main.swift
    │   └── models
    │       └── hello.swift
    └── module2
        └── foo.swift

@swift-ci
Copy link
Contributor Author

Comment by Petar (JIRA)

Thank you! I tried looking for this but failed to find any information.

@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