Skip to content

Commit

Permalink
fix: check for main.swift when finding identifying binary targets (#96
Browse files Browse the repository at this point in the history
)

Closes #50.
  • Loading branch information
cgrindel committed Dec 30, 2022
1 parent 0e5dc44 commit c176e10
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
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
)

0 comments on commit c176e10

Please sign in to comment.