Skip to content
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
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Sources/WeaverCodeGen/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private extension Lexer {
return nil
}

guard let nextLine = findNextLine(after: currentLine, containing: syntaxToken.offset) else {
guard let nextLine = findNextLine(after: currentLine, containing: syntaxToken.offset.value) else {
return nil
}
currentLine = nextLine
Expand All @@ -144,8 +144,8 @@ private extension Lexer {

do {
guard let token = try TokenBuilder.makeAnnotationToken(string: content,
offset: syntaxToken.offset,
length: syntaxToken.length,
offset: syntaxToken.offset.value,
length: syntaxToken.length.value,
line: currentLine) else {
return nil
}
Expand Down
40 changes: 24 additions & 16 deletions Sources/WeaverCommand/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,41 @@ extension Configuration {

func inputPaths() throws -> [Path] {
var inputPaths = Set<Path>()

let inputDirectories = Set(inputPathStrings
.lazy
.map { self.projectPath + $0 }
.filter { $0.exists && $0.isDirectory }
.map { $0.absolute().string })

if inputDirectories.isEmpty == false {
let grepArguments = ["-lR", "-e", Configuration.annotationRegex, "-e", Configuration.propertyWrapperRegex] + Array(inputDirectories)
inputPaths.formUnion(try shellOut(to: "grep", arguments: grepArguments)
.split(separator: "\n")
.lazy
.map { Path(String($0)) }
.filter { $0.extension == "swift" })
}

inputPaths.formUnion(inputPathStrings
.lazy
.map { self.projectPath + $0 }
.flatMap { $0.isFile ? [$0] : self.recursivePathsByPattern(fromDirectory: $0) }
.filter { $0.exists && $0.isFile && $0.extension == "swift" })

inputPaths.subtract(try ignoredPathStrings
.lazy
.map { self.projectPath + $0 }
.flatMap { $0.isFile ? [$0] : recursive ? try $0.recursiveChildren() : try $0.children() }
.flatMap { $0.isFile ? [$0] : try paths(fromDirectory: $0) }
.filter { $0.extension == "swift" })

return inputPaths.sorted()
}

private func recursivePathsByPattern(fromDirectory directory: Path) -> [Path] {
let grepArguments = [
"-lR",
"-e", Configuration.annotationRegex,
"-e", Configuration.propertyWrapperRegex,
directory.absolute().string
]
// if there are no files matching the pattern
// command grep return exit 1, and ShellOut throws an exception with empty message
guard let grepResult = try? shellOut(to: "grep", arguments: grepArguments) else {
return []
}

return grepResult
.split(separator: "\n")
.map { Path(String($0)) }
}

private func paths(fromDirectory directory: Path) throws -> [Path] {
recursive ? try directory.recursiveChildren() : try directory.children()
}
}