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-1379] Swift Package Manager and main.swift #5451

Open
swift-ci opened this issue May 2, 2016 · 4 comments
Open

[SR-1379] Swift Package Manager and main.swift #5451

swift-ci opened this issue May 2, 2016 · 4 comments
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2016

Previous ID SR-1379
Radar None
Original Reporter contraultra (JIRA User)
Type Bug

Attachment: Download

Environment
$ swift --version
Swift version 3.0-dev (LLVM 752e1430fc, Clang 1e6cba3ce3, Swift 56052cfe61)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes 0
Component/s Compiler, Package Manager
Labels Bug
Assignee None
Priority Medium

md5: b3b8d38188bf24995cd29d03a4f52b43

Issue Description:

Hi there,

I was advised to post this as a bug report. This was originally an email out to the Swift Users mailing list.

This is what happened as I was trying out the Swift Package Manager for another project similar to the one shown below:

~ $ mkdir example
~ $ cd example/
example $ touch Package.swift
example $ mkdir Sources
example $ vi Sources/Example.swift
example $ cat Sources/Example.swift
func printOther() {
  print("other")
}
example $ vi Sources/Main.swift
example $ cat Sources/Main.swift
print("Hello World")
printOther()

example $ swift build
Compile Swift Module 'example' (2 sources)
/PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at the top level
print("Hello World")
^
/PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at the top level
printOther()
^
/PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at the top level
print("Hello World")
^
/PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at the top level
printOther()
^
<unknown>:0: error: build had 1 command failures
error: exit(1): /PATH-SWIFT/usr/bin/swift-build-tool -f /PATH/example/.build/debug.yaml

example $ mv Sources/Main.swift Sources/main.swift
example $ swift build
Compile Swift Module 'example' (2 sources)
Linking .build/debug/example
example $ .build/debug/example
Hello World
other
example $

I had to rename Main.swift to main.swift. Is there a design decision on why the filename for the main swift file has to be lowercase or is this a bug?

If it's a design decision, why are directory names for source files allowed to have variations like Sources, Source, src and srcs as stated here but not the main swift file?

I'd be ok if only Main.swift and main.swift are allowed since other files in the Sources directory are commonly UpperCamelCase due to the Type naming conventions e.g. example-package-playingcard/Sources.

Or maybe I'm just being pedantic?

p.s. even Package.swift is capitalized and not package.swift

@swift-ci
Copy link
Contributor Author

swift-ci commented May 2, 2016

Comment by Kostiantyn Koval (JIRA)

I think `main.` file with lowercase letter is a standard and it's commonly used in many languages. I think we should be consistent and keep `main.swift` and not `Main.swift`

P.S
If I make a new project in Xcode, it creates main.swift file too.

@ddunbar
Copy link
Member

ddunbar commented May 5, 2016

I think we should consider rejecting Main.swift as a source file name. Even if we think it should be spelled main.swift, that makes having a non-main Main.swift is confusing at best.

@ankitspd
Copy link
Member

How about a warning?

@swift-ci
Copy link
Contributor Author

Comment by Paulo Ricardo Lopes de Faria (JIRA)

I suggest SwiftPM considers Main.swift and main.swift the same thing. Or rather use Main.swift instead of main.swift. I think naming consistency inside Swift ecosystem makes much more sense than consistency with other languages.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 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

4 participants