Skip to content

Commit 00aa289

Browse files
committed
Extract ModuleMapType into separate file
1 parent e275b94 commit 00aa289

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

Sources/PackageModel/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_library(PackageModel
2020
Manifest/SystemPackageProviderDescription.swift
2121
Manifest/TargetBuildSettingDescription.swift
2222
Manifest/TargetDescription.swift
23+
ModuleMapType.swift
2324
Package.swift
2425
PackageReference.swift
2526
Platform.swift
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import TSCBasic
12+
import TSCUtility
13+
14+
/// A type of module map layout. Contains all the information needed to generate or use a module map for a target that can have C-style headers.
15+
public enum ModuleMapType: Equatable {
16+
/// No module map file.
17+
case none
18+
/// A custom module map file.
19+
case custom(AbsolutePath)
20+
/// An umbrella header included by a generated module map file.
21+
case umbrellaHeader(AbsolutePath)
22+
/// An umbrella directory included by a generated module map file.
23+
case umbrellaDirectory(AbsolutePath)
24+
}
25+
26+
extension ModuleMapType: Codable {
27+
private enum CodingKeys: String, CodingKey {
28+
case none, custom, umbrellaHeader, umbrellaDirectory
29+
}
30+
31+
public init(from decoder: Decoder) throws {
32+
let container = try decoder.container(keyedBy: CodingKeys.self)
33+
if let path = try container.decodeIfPresent(AbsolutePath.self, forKey: .custom) {
34+
self = .custom(path)
35+
}
36+
else if let path = try container.decodeIfPresent(AbsolutePath.self, forKey: .umbrellaHeader) {
37+
self = .umbrellaHeader(path)
38+
}
39+
else if let path = try container.decodeIfPresent(AbsolutePath.self, forKey: .umbrellaDirectory) {
40+
self = .umbrellaDirectory(path)
41+
}
42+
else {
43+
self = .none
44+
}
45+
}
46+
47+
public func encode(to encoder: Encoder) throws {
48+
var container = encoder.container(keyedBy: CodingKeys.self)
49+
switch self {
50+
case .none:
51+
break
52+
case .custom(let path):
53+
try container.encode(path, forKey: .custom)
54+
case .umbrellaHeader(let path):
55+
try container.encode(path, forKey: .umbrellaHeader)
56+
case .umbrellaDirectory(let path):
57+
try container.encode(path, forKey: .umbrellaDirectory)
58+
}
59+
}
60+
}

Sources/PackageModel/Target.swift

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -499,52 +499,6 @@ public final class BinaryTarget: Target {
499499
}
500500
}
501501

502-
/// A type of module map layout. Contains all the information needed to generate or use a module map for a target that can have C-style headers.
503-
public enum ModuleMapType: Equatable, Codable {
504-
/// No module map file.
505-
case none
506-
/// A custom module map file.
507-
case custom(AbsolutePath)
508-
/// An umbrella header included by a generated module map file.
509-
case umbrellaHeader(AbsolutePath)
510-
/// An umbrella directory included by a generated module map file.
511-
case umbrellaDirectory(AbsolutePath)
512-
513-
private enum CodingKeys: String, CodingKey {
514-
case none, custom, umbrellaHeader, umbrellaDirectory
515-
}
516-
517-
public init(from decoder: Decoder) throws {
518-
let container = try decoder.container(keyedBy: CodingKeys.self)
519-
if let path = try container.decodeIfPresent(AbsolutePath.self, forKey: .custom) {
520-
self = .custom(path)
521-
}
522-
else if let path = try container.decodeIfPresent(AbsolutePath.self, forKey: .umbrellaHeader) {
523-
self = .umbrellaHeader(path)
524-
}
525-
else if let path = try container.decodeIfPresent(AbsolutePath.self, forKey: .umbrellaDirectory) {
526-
self = .umbrellaDirectory(path)
527-
}
528-
else {
529-
self = .none
530-
}
531-
}
532-
533-
public func encode(to encoder: Encoder) throws {
534-
var container = encoder.container(keyedBy: CodingKeys.self)
535-
switch self {
536-
case .none:
537-
break
538-
case .custom(let path):
539-
try container.encode(path, forKey: .custom)
540-
case .umbrellaHeader(let path):
541-
try container.encode(path, forKey: .umbrellaHeader)
542-
case .umbrellaDirectory(let path):
543-
try container.encode(path, forKey: .umbrellaDirectory)
544-
}
545-
}
546-
}
547-
548502
extension Sources {
549503
/// Determine target type based on the sources.
550504
fileprivate func computeTargetType() -> Target.Kind {

0 commit comments

Comments
 (0)