Skip to content

Commit

Permalink
Scheme-first search for shared scheme targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Feb 19, 2024
1 parent 346971d commit 1d4c541
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
37 changes: 0 additions & 37 deletions Sources/XCLinting/Rules/HasSharedSchemeRule.swift

This file was deleted.

48 changes: 48 additions & 0 deletions Sources/XCLinting/Rules/SharedSchemesRule.swift
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)")
}
}
}
2 changes: 1 addition & 1 deletion Tests/XCLintTests/SharedSchemesRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class SharedSchemesRuleTests: XCTestCase {
}

func testProjectWithMissingSharedSchemes() throws {
let url = try Bundle.module.testDataURL(named: "SchemeSkipsTests.xcodeproj")
let url = try Bundle.module.testDataURL(named: "BuildFilesOutOfOrder.xcodeproj")

let project = try XcodeProj(pathString: url.path)

Expand Down

0 comments on commit 1d4c541

Please sign in to comment.