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

fix: check for main.swift when finding identifying binary targets #96

Merged
merged 4 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/vapor_example/Sources/Run/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")

swift_library(
swift_binary(
name = "Run",
srcs = ["main.swift"],
module_name = "Run",
Expand Down
15 changes: 0 additions & 15 deletions examples/vapor_example/Sources/Run/Info.plist

This file was deleted.

2 changes: 1 addition & 1 deletion gazelle/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func genRulesFromSrcFiles(sc *swiftcfg.SwiftConfig, args language.GenerateArgs)
// Collect Swift files
swiftFiles := swift.FilterFiles(append(args.RegularFiles, args.GenFiles...))

// Do not quick exit if we do not have any Swift source files in this directory. They may be
// Do not quick exit if we do not have any Swift source files in this directory. There may be
// Swift source files in sub-directories.

// Be sure to use args.Rel when determining whether this is a module directory. We do not want
Expand Down
5 changes: 5 additions & 0 deletions gazelle/internal/swift/file_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func NewFileInfoFromReader(rel, abs string, reader io.Reader) *FileInfo {
Rel: rel,
Abs: abs,
IsTest: testSuffixes.HasSuffix(rel),
// There are several ways to detect a main.
// 1. A file named "main.swift"
// 2. @main annotation
// 3. public static func main()
ContainsMain: filepath.Base(rel) == "main.swift",
}

scanner := bufio.NewScanner(reader)
Expand Down
3 changes: 2 additions & 1 deletion gazelle/internal/swift/module_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package swift
type ModuleType int

const (
LibraryModuleType ModuleType = iota
UnknownModuleType ModuleType = iota
LibraryModuleType
BinaryModuleType
TestModuleType
)