This repository was archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageResolution.swift
64 lines (62 loc) · 1.67 KB
/
PackageResolution.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import SymbolGraphs
import Versions
import JSON
public
struct PackageResolution
{
public
var pins:[Pin.ID: MaskedVersion]
public
init(pins:[Pin])
{
self.pins = [:]
for pin:Pin in pins
{
// these strings are slightly different from the ones we
// parse from url queries
switch pin.state.requirement
{
case .version(let version):
self.pins[pin.id] = version
case .branch(let branch):
self.pins[pin.id] =
(try? .init(parsing: branch)) ??
(try? .init(toolchain: branch))
}
}
}
public
init(from json:JSON) throws
{
let pins:[Pin] = try json.lint
{
switch try $0.remove("version", as: Int.self)
{
case 1:
return try $0.remove("object")
{
try $0.lint
{
try $0.remove("pins", as: [JSON].self)
{
try $0.map(Pin.init(from:))
}
}
}
case 2:
return try $0.remove("pins", as: [JSON].self)
{
try $0.map(Pin.init(from:))
}
default:
fatalError("unsupported Package.resolved format")
}
}
self.init(pins: pins)
}
@inlinable public
init<UTF8>(parsing utf8:UTF8) throws where UTF8:Collection<UInt8>
{
try self.init(from: try JSON.init(parsing: utf8))
}
}