Skip to content

Commit

Permalink
[SPMLLBuild] Gracefully handle missing data
Browse files Browse the repository at this point in the history
This will throw instead of crashing if we can't form a build value.
That can happen if we add new properties to the objects that get encoded in
the database but not bump the schema. This change will cause the build
value to be out-of-date and instead force recomputation of the cached
value.

<rdar://problem/51146826>
  • Loading branch information
ankitspd committed Jan 27, 2020
1 parent f2b58c1 commit 34ae7fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
14 changes: 9 additions & 5 deletions Sources/PackageLoading/ManifestLoader.swift
Expand Up @@ -790,8 +790,12 @@ final class ManifestLoadRule: LLBuildRule {

override func isResultValid(_ priorValue: Value) -> Bool {
// Always rebuild if we had a failure.
let value = RuleKey.BuildValue(priorValue)
if value.hasErrors { return false }
do {
let value = try RuleKey.BuildValue(priorValue)
if value.hasErrors { return false }
} catch {
return false
}

return super.isResultValid(priorValue)
}
Expand Down Expand Up @@ -855,13 +859,13 @@ final class FileInfoRule: LLBuildRule {
}

override func isResultValid(_ priorValue: Value) -> Bool {
let priorValue = RuleValue(priorValue)
let priorValue = try? RuleValue(priorValue)

// Always rebuild if we had a failure.
if case .failure = priorValue.result {
if case .failure = priorValue?.result {
return false
}
return getFileInfo(key.path).result == priorValue.result
return getFileInfo(key.path).result == priorValue?.result
}

override func inputsAvailable(_ engine: LLTaskBuildEngine) {
Expand Down
16 changes: 3 additions & 13 deletions Sources/SPMLLBuild/llbuild.swift
Expand Up @@ -92,7 +92,7 @@ public final class LLBuildEngine {
throw Error.failed(errors: delegate.errors)
}

return T.BuildValue(value)
return try T.BuildValue(value)
}

public func attachDB(path: String, schemaVersion: Int = 2) throws {
Expand Down Expand Up @@ -219,18 +219,8 @@ public extension LLBuildKey {
}

public extension LLBuildValue {
init(_ value: Value) {
do {
self = try fromBytes(value.data)
} catch {
let stringValue: String
if let str = String(bytes: value.data, encoding: .utf8) {
stringValue = str
} else {
stringValue = String(describing: value.data)
}
fatalError("Please file a bug at https://bugs.swift.org with this info -- LLBuildValue: ###\(error)### ----- ###\(stringValue)###")
}
init(_ value: Value) throws {
self = try fromBytes(value.data)
}

func toValue() -> Value {
Expand Down

0 comments on commit 34ae7fd

Please sign in to comment.