-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scheme-first search for shared scheme targets
- Loading branch information
1 parent
346971d
commit 1d4c541
Showing
3 changed files
with
49 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
|
||
import XcodeProj | ||
import XCConfig | ||
|
||
/// Ensure that targets have a shared scheme on disk. | ||
struct SharedSchemesRule { | ||
func run(_ environment: XCLinter.Environment) throws -> [Violation] { | ||
let sharedSchemesURL = environment | ||
.projectRootURL | ||
.appendingPathComponent("xcshareddata/xcschemes", isDirectory: true) | ||
.standardizedFileURL | ||
|
||
let fileManager = FileManager.default | ||
|
||
guard fileManager.isReadableFile(atPath: sharedSchemesURL.path) else { | ||
return [.init("Shared scheme directory not found")] | ||
} | ||
|
||
let targetNames = environment.project.pbxproj.projects.flatMap { $0.targets }.map { $0.name } | ||
var targetNameSet = Set(targetNames) | ||
|
||
for entry in try fileManager.contentsOfDirectory(atPath: sharedSchemesURL.path) { | ||
let entryPath = sharedSchemesURL | ||
.appendingPathComponent(entry, isDirectory: false) | ||
.standardizedFileURL | ||
.path | ||
|
||
let scheme = try XCScheme(pathString: entryPath) | ||
|
||
for entry in scheme.buildAction?.buildActionEntries ?? [] { | ||
let name = entry.buildableReference.blueprintName | ||
|
||
targetNameSet.remove(name) | ||
} | ||
|
||
for entry in scheme.testAction?.testables ?? [] { | ||
let name = entry.buildableReference.blueprintName | ||
|
||
targetNameSet.remove(name) | ||
} | ||
} | ||
|
||
return targetNameSet.map { name in | ||
Violation("No shared scheme found that references \(name)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters