Skip to content

Commit 3045cba

Browse files
committed
Extract SupportedLanguageExtension into separate file
1 parent 010e7dc commit 3045cba

File tree

3 files changed

+73
-63
lines changed

3 files changed

+73
-63
lines changed

Sources/PackageModel/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(PackageModel
1717
Resource.swift
1818
Sources.swift
1919
Target.swift
20+
SupportedLanguageExtension.swift
2021
SwiftLanguageVersion.swift
2122
ToolsVersion.swift)
2223
target_link_libraries(PackageModel PUBLIC

Sources/PackageModel/Sources.swift

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -50,66 +50,3 @@ public struct Sources: Codable {
5050
})
5151
}
5252
}
53-
54-
/// An enum representing supported source file extensions.
55-
public enum SupportedLanguageExtension: String {
56-
/// Swift
57-
case swift
58-
/// C
59-
case c
60-
/// Objective C
61-
case m
62-
/// Objective-C++
63-
case mm
64-
/// C++
65-
case cc
66-
case cpp
67-
case cxx
68-
/// Assembly
69-
case s
70-
case S
71-
72-
/// Returns a set of valid swift extensions.
73-
public static var swiftExtensions: Set<String> = {
74-
SupportedLanguageExtension.stringSet(swift)
75-
}()
76-
77-
/// Returns a set of valid c extensions.
78-
public static var cExtensions: Set<String> = {
79-
SupportedLanguageExtension.stringSet(c, m)
80-
}()
81-
82-
/// Returns a set of valid cpp extensions.
83-
public static var cppExtensions: Set<String> = {
84-
SupportedLanguageExtension.stringSet(mm, cc, cpp, cxx)
85-
}()
86-
87-
/// Returns a set of valid assembly file extensions.
88-
public static var assemblyExtensions: Set<String> = {
89-
SupportedLanguageExtension.stringSet(.s, .S)
90-
}()
91-
92-
/// Returns a set of valid extensions in clang targets.
93-
public static func clangTargetExtensions(toolsVersion: ToolsVersion) -> Set<String> {
94-
var validExts = cExtensions.union(cppExtensions)
95-
if toolsVersion >= .v5 {
96-
validExts.formUnion(assemblyExtensions)
97-
}
98-
return validExts
99-
}
100-
101-
/// Returns a set of all file extensions we support.
102-
public static func validExtensions(toolsVersion: ToolsVersion) -> Set<String> {
103-
return swiftExtensions.union(clangTargetExtensions(toolsVersion: toolsVersion))
104-
}
105-
106-
/// Converts array of LanguageExtension into a string set representation.
107-
///
108-
/// - Parameters:
109-
/// - extensions: Array of LanguageExtension to be converted to string set.
110-
///
111-
/// - Returns: Set of strings.
112-
private static func stringSet(_ extensions: SupportedLanguageExtension...) -> Set<String> {
113-
return Set(extensions.map({ $0.rawValue }))
114-
}
115-
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
/// An enum representing supported source file extensions.
12+
public enum SupportedLanguageExtension: String {
13+
/// Swift
14+
case swift
15+
/// C
16+
case c
17+
/// Objective C
18+
case m
19+
/// Objective-C++
20+
case mm
21+
/// C++
22+
case cc
23+
case cpp
24+
case cxx
25+
/// Assembly
26+
case s
27+
case S
28+
29+
/// Returns a set of valid swift extensions.
30+
public static var swiftExtensions: Set<String> = {
31+
SupportedLanguageExtension.stringSet(swift)
32+
}()
33+
34+
/// Returns a set of valid c extensions.
35+
public static var cExtensions: Set<String> = {
36+
SupportedLanguageExtension.stringSet(c, m)
37+
}()
38+
39+
/// Returns a set of valid cpp extensions.
40+
public static var cppExtensions: Set<String> = {
41+
SupportedLanguageExtension.stringSet(mm, cc, cpp, cxx)
42+
}()
43+
44+
/// Returns a set of valid assembly file extensions.
45+
public static var assemblyExtensions: Set<String> = {
46+
SupportedLanguageExtension.stringSet(.s, .S)
47+
}()
48+
49+
/// Returns a set of valid extensions in clang targets.
50+
public static func clangTargetExtensions(toolsVersion: ToolsVersion) -> Set<String> {
51+
var validExts = cExtensions.union(cppExtensions)
52+
if toolsVersion >= .v5 {
53+
validExts.formUnion(assemblyExtensions)
54+
}
55+
return validExts
56+
}
57+
58+
/// Returns a set of all file extensions we support.
59+
public static func validExtensions(toolsVersion: ToolsVersion) -> Set<String> {
60+
return swiftExtensions.union(clangTargetExtensions(toolsVersion: toolsVersion))
61+
}
62+
63+
/// Converts array of LanguageExtension into a string set representation.
64+
///
65+
/// - Parameters:
66+
/// - extensions: Array of LanguageExtension to be converted to string set.
67+
///
68+
/// - Returns: Set of strings.
69+
private static func stringSet(_ extensions: SupportedLanguageExtension...) -> Set<String> {
70+
return Set(extensions.map({ $0.rawValue }))
71+
}
72+
}

0 commit comments

Comments
 (0)