Skip to content

Commit

Permalink
Version 0.0.18
Browse files Browse the repository at this point in the history
* Minor stylistic improvements in Swift Package parser.
* Removes double dispatch to the `DispatchGroup` when parsing source
files in all parsers, as it was freezing the interface temporarily.
  • Loading branch information
stelabouras committed Apr 18, 2024
1 parent 083c6c3 commit 587b03e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 68 deletions.
37 changes: 17 additions & 20 deletions Sources/PrivacyManifest/DirectoryProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,25 @@ class DirectoryProjectParser: ProjectParser {
let targetName = projectPath.lastComponent
let spinner = concurrentStream.createSilentSpinner(with: "Parsing \(CliSyntaxColor.GREEN)\(targetName)'s\(CliSyntaxColor.END) source files...")
concurrentStream.start(spinner: spinner)
queue.async(group: group,
execute: DispatchWorkItem(block: {
do {
var filePathsForParsing: [Path] = []
try self.projectPath.recursiveChildren().forEach { path in
guard let ext = path.extension,
ALLOWED_EXTENSIONS.contains(ext) else {
return
}
filePathsForParsing.append(path)
do {
var filePathsForParsing: [Path] = []
try self.projectPath.recursiveChildren().forEach { path in
guard let ext = path.extension,
ALLOWED_EXTENSIONS.contains(ext) else {
return
}
try self.parseFiles(filePathsForParsing: filePathsForParsing,
targetName: targetName,
spinner: spinner)
self.concurrentStream.success(spinner: spinner,
"Parsed \(CliSyntaxColor.GREEN)\(targetName)'s\(CliSyntaxColor.END) source files")
filePathsForParsing.append(path)
}
catch {
self.concurrentStream.error(spinner: spinner,
"Error parsing \(CliSyntaxColor.GREEN)\(targetName)'s\(CliSyntaxColor.END) source files: \(CliSyntaxColor.RED)\(error)\(CliSyntaxColor.END)")
}
}))
try self.parseFiles(filePathsForParsing: filePathsForParsing,
targetName: targetName,
spinner: spinner)
self.concurrentStream.success(spinner: spinner,
"Parsed \(CliSyntaxColor.GREEN)\(targetName)'s\(CliSyntaxColor.END) source files")
}
catch {
self.concurrentStream.error(spinner: spinner,
"Error parsing \(CliSyntaxColor.GREEN)\(targetName)'s\(CliSyntaxColor.END) source files: \(CliSyntaxColor.RED)\(error)\(CliSyntaxColor.END)")
}

_ = group.wait(timeout: .distantFuture)
concurrentStream.waitAndShowCursor()
Expand Down
45 changes: 23 additions & 22 deletions Sources/PrivacyManifest/SwiftPackageProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ extension UserToolchain {
// Parses all the Swift Package's supported source files and dependencies.
class SwiftPackageProjectParser : ProjectParser {
override func parse() throws {
print("---")

let spinner = Spinner(.dots8Bit,
"Resolving graph...")
spinner.start()
Expand Down Expand Up @@ -112,33 +114,32 @@ class SwiftPackageProjectParser : ProjectParser {

let spinner = concurrentStream.createSilentSpinner(with: "Parsing \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files...")
concurrentStream.start(spinner: spinner)
queue.async(group: group,
execute: DispatchWorkItem(block: {
var filePathsForParsing: [Path] = []
let rootDirectory = target.sources.root
target.sources.relativePaths.forEach { relativePath in
guard let ext = relativePath.extension,
ALLOWED_EXTENSIONS.contains(ext) else {
return
}
filePathsForParsing.append(Path(rootDirectory.pathString) + relativePath.pathString)
}
do {
try self.parseFiles(filePathsForParsing: filePathsForParsing,
targetName: target.name,
spinner: spinner)
self.concurrentStream.success(spinner: spinner,
"Parsed \(filePathsForParsing.count) \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files")
}
catch {
self.concurrentStream.error(spinner: spinner,
"Error parsing \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files: \(CliSyntaxColor.RED)\(error)\(CliSyntaxColor.END)")
var filePathsForParsing: [Path] = []
let rootDirectory = target.sources.root
target.sources.relativePaths.forEach { relativePath in
guard let ext = relativePath.extension,
ALLOWED_EXTENSIONS.contains(ext) else {
return
}
}))
filePathsForParsing.append(Path(rootDirectory.pathString) + relativePath.pathString)
}
do {
try self.parseFiles(filePathsForParsing: filePathsForParsing,
targetName: target.name,
spinner: spinner)
self.concurrentStream.success(spinner: spinner,
"Parsed \(filePathsForParsing.count) \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files")
}
catch {
self.concurrentStream.error(spinner: spinner,
"Error parsing \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files: \(CliSyntaxColor.RED)\(error)\(CliSyntaxColor.END)")
}
}
}

_ = group.wait(timeout: .distantFuture)
concurrentStream.waitAndShowCursor()

print("---")
}
}
47 changes: 22 additions & 25 deletions Sources/PrivacyManifest/XcodeProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,30 @@ class XcodeProjectParser: ProjectParser {

let spinner = concurrentStream.createSilentSpinner(with: "Parsing \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files...")
concurrentStream.start(spinner: spinner)
queue.async(group: group,
execute: DispatchWorkItem(block: {
do {
var filePathsForParsing: [Path] = []
try sourceFiles.forEach { file in
guard let filePath = file.path,
let ext = Path(filePath).extension,
ALLOWED_EXTENSIONS.contains(ext)
else {
return
}
guard let fullPath = try file.fullPath(sourceRoot: path.parent()) else {
return
}
filePathsForParsing.append(fullPath)
do {
var filePathsForParsing: [Path] = []
try sourceFiles.forEach { file in
guard let filePath = file.path,
let ext = Path(filePath).extension,
ALLOWED_EXTENSIONS.contains(ext)
else {
return
}
try self.parseFiles(filePathsForParsing: filePathsForParsing,
targetName: target.name,
spinner: spinner)
self.concurrentStream.success(spinner: spinner,
"Parsed \(filePathsForParsing.count) \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files")
}
catch {
self.concurrentStream.error(spinner: spinner,
"Error parsing \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files: \(CliSyntaxColor.RED)\(error)\(CliSyntaxColor.END)")
guard let fullPath = try file.fullPath(sourceRoot: path.parent()) else {
return
}
filePathsForParsing.append(fullPath)
}
}))
try self.parseFiles(filePathsForParsing: filePathsForParsing,
targetName: target.name,
spinner: spinner)
self.concurrentStream.success(spinner: spinner,
"Parsed \(filePathsForParsing.count) \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files")
}
catch {
self.concurrentStream.error(spinner: spinner,
"Error parsing \(CliSyntaxColor.GREEN)\(target.name)'s\(CliSyntaxColor.END) source files: \(CliSyntaxColor.RED)\(error)\(CliSyntaxColor.END)")
}
}

_ = group.wait(timeout: .distantFuture)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PrivacyManifest/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ required reason APIs
!!! Disclaimer: This tool must *not* be used as the only way to generate the privacy manifest. Do your own research !!!
""",
version: "0.0.17",
version: "0.0.18",
subcommands: [Analyze.self])
}

Expand Down

0 comments on commit 587b03e

Please sign in to comment.