Skip to content

Commit 84094b1

Browse files
authored
[none] fix: Fixed a ImpactAnalysis error when Cocoapods.lock was missing (#4)
* [none] fix: Fixed a ImpactAnalysis error when Cocoapods.lock was missing * Targets are now marked as affected if a new lockfile has been added
1 parent f98540d commit 84094b1

7 files changed

Lines changed: 62 additions & 32 deletions

File tree

ImpactAnalysis/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ImpactAnalysis/Sources/ImpactAnalysis/ImpactAnalysisWorkspaceMapper.swift

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,44 +531,65 @@ extension ImpactAnalysisWorkspaceMapper {
531531

532532
// MARK: - Lockfiles diff calculation
533533

534-
private func lockfiles() throws -> (original: CocoapodsLockfile, new: CocoapodsLockfile) {
535-
let originalLockfile: Data
534+
private func lockfiles() throws -> (original: CocoapodsLockfile?, new: CocoapodsLockfile?) {
535+
let originalLockfile: Data?
536536
let originalLockfileContext: ParseYamlContext
537-
let newLockfile: Data
537+
let newLockfile: Data?
538538
let newLockfileContext: ParseYamlContext
539539

540540
let lockfilePath = try RelativePath(validating: "Geko/Dependencies/Cocoapods.lock")
541541
if environment.impactAnalysisDebug {
542542
let rootDir = fileHandler.currentPath
543543

544-
originalLockfile = try system.capture(["git", "show", "HEAD:\(lockfilePath.pathString)"]).chomp().data(using: .utf8)!
544+
originalLockfile = try? system.capture(["git", "show", "HEAD:\(lockfilePath.pathString)"]).chomp()
545+
.data(using: .utf8)
545546
originalLockfileContext = .git(path: lockfilePath, ref: "HEAD")
546547

547548
let newLockfilePath = rootDir.appending(lockfilePath)
548-
newLockfile = try fileHandler.readFile(newLockfilePath)
549+
newLockfile = try? fileHandler.readFile(newLockfilePath)
549550
newLockfileContext = .file(path: newLockfilePath)
550551
} else {
551-
originalLockfile = try system.capture(["git", "show", "\(targetRef):\(lockfilePath.pathString)"]).chomp()
552-
.data(using: .utf8)!
552+
originalLockfile = try? system.capture(["git", "show", "\(targetRef):\(lockfilePath.pathString)"]).chomp()
553+
.data(using: .utf8)
553554
originalLockfileContext = .git(path: lockfilePath, ref: "HEAD")
554555

555-
newLockfile = try system.capture(["git", "show", "\(sourceRef):\(lockfilePath.pathString)"]).chomp()
556-
.data(using: .utf8)!
556+
newLockfile = try? system.capture(["git", "show", "\(sourceRef):\(lockfilePath.pathString)"]).chomp()
557+
.data(using: .utf8)
557558
newLockfileContext = .git(path: lockfilePath, ref: "HEAD")
558559
}
559560

560-
let originalLockfileYml = try CocoapodsLockfile.from(data: originalLockfile, context: originalLockfileContext)!
561-
let newLockfileYml = try CocoapodsLockfile.from(data: newLockfile, context: newLockfileContext)!
561+
var originalLockfileYml: CocoapodsLockfile?
562+
var newLockfileYml: CocoapodsLockfile?
563+
564+
if let originalLockfile {
565+
originalLockfileYml = try CocoapodsLockfile.from(data: originalLockfile, context: originalLockfileContext)
566+
}
567+
568+
if let newLockfile {
569+
newLockfileYml = try CocoapodsLockfile.from(data: newLockfile, context: newLockfileContext)
570+
}
562571

563572
return (originalLockfileYml, newLockfileYml)
564573
}
565574

566575
private func lockfileChanges(
567576
workspace: inout WorkspaceWithProjects,
568577
externalDependenciesGraph: DependenciesGraph,
569-
originalLockfile: CocoapodsLockfile,
570-
newLockfile: CocoapodsLockfile
578+
originalLockfile: CocoapodsLockfile?,
579+
newLockfile: CocoapodsLockfile?
571580
) throws -> Set<ImpactGraphDependency> {
581+
guard let newLockfile else { return [] }
582+
583+
guard let originalLockfile else {
584+
var changedDependencies = Set<String>()
585+
586+
for (_, newSourceData) in newLockfile.podsBySource {
587+
changedDependencies.formUnion(newSourceData.pods.keys)
588+
}
589+
590+
return mapImpactDependencies(from: changedDependencies, externalDependenciesGraph: externalDependenciesGraph)
591+
}
592+
572593
var changedDependencies = Set<String>()
573594

574595
func compare(_ origLockfile: CocoapodsLockfile, _ newLockfile: CocoapodsLockfile) {
@@ -597,6 +618,13 @@ extension ImpactAnalysisWorkspaceMapper {
597618
compare(originalLockfile, newLockfile)
598619
compare(newLockfile, originalLockfile)
599620

621+
return mapImpactDependencies(from: changedDependencies, externalDependenciesGraph: externalDependenciesGraph)
622+
}
623+
624+
private func mapImpactDependencies(
625+
from changedDependencies: Set<String>,
626+
externalDependenciesGraph: DependenciesGraph
627+
) -> Set<ImpactGraphDependency> {
600628
var result = Set<ImpactGraphDependency>()
601629

602630
for dependency in changedDependencies {

PluginSupport/Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PluginSupport/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let package = Package(
2828
),
2929
],
3030
dependencies: [
31-
.package(url: "https://github.com/geko-tech/ProjectDescription", branch: "release/1.0.0"),
31+
.package(url: "https://github.com/geko-tech/project-description", branch: "release/1.0.0"),
3232
.package(url: "https://github.com/apple/swift-tools-support-core", from: "0.6.1"),
3333
.package(url: "https://github.com/apple/swift-log", from: "1.5.3"),
3434
.package(url: "https://github.com/apple/swift-crypto", from: "3.15.1"),
@@ -39,15 +39,15 @@ let package = Package(
3939
.target(
4040
name: "PluginSupport",
4141
dependencies: dependencies + [
42-
.product(name: "ProjectDescription", package: "ProjectDescription"),
42+
.product(name: "ProjectDescription", package: "project-description"),
4343
.product(name: "Crypto", package: "swift-crypto")
4444
],
4545
cSettings: [.define("_GNU_SOURCE", .when(platforms: [.linux]))]
4646
),
4747
.target(
4848
name: "PluginSupportStatic",
4949
dependencies: dependencies + [
50-
.product(name: "ProjectDescriptionStatic", package: "ProjectDescription"),
50+
.product(name: "ProjectDescriptionStatic", package: "project-description"),
5151
.product(name: "Crypto", package: "swift-crypto")
5252
],
5353
cSettings: [.define("_GNU_SOURCE", .when(platforms: [.linux]))]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
This repository contains official Geko plugins and examples of Geko plugins.
44

5-
TODO: add links to documentation
5+
# Documentation
6+
7+
Documentation is available at [geko-tech.github.io/geko/guides/features/plugins/](https://geko-tech.github.io/geko/guides/features/plugins/)

WorkspaceMapperPluginExample/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WorkspaceMapperPluginExample/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ let package = Package(
1414
),
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/geko-tech/ProjectDescription", branch: "release/1.0.0")
17+
.package(url: "https://github.com/geko-tech/project-description", branch: "release/1.0.0")
1818
],
1919
targets: [
2020
.target(
2121
name: "WorkspaceMapperExample",
2222
dependencies: [
23-
.product(name: "ProjectDescription", package: "ProjectDescription"),
23+
.product(name: "ProjectDescription", package: "project-description"),
2424
"ProjectDescriptionHelpers"
2525
],
2626
),
2727
.target(
2828
name: "ProjectDescriptionHelpers",
2929
dependencies: [
30-
.product(name: "ProjectDescription", package: "ProjectDescription"),
30+
.product(name: "ProjectDescription", package: "project-description"),
3131
],
3232
path: "ProjectDescriptionHelpers"
3333
)

0 commit comments

Comments
 (0)