@@ -34,6 +34,34 @@ import struct TSCBasic.ByteString
34
34
@available ( * , deprecated, renamed: " SwiftModuleBuildDescription " )
35
35
public typealias SwiftTargetBuildDescription = SwiftModuleBuildDescription
36
36
37
+ // looking into the file content to see if it is using the @main annotation
38
+ // this is not bullet-proof since theoretically the file can contain the @main string for other reasons
39
+ // but it is the closest to accurate we can do at this point
40
+ package func containsAtMain( fileSystem: FileSystem , path: AbsolutePath ) throws -> Bool {
41
+ let content : String = try fileSystem. readFileContents ( path)
42
+ let lines = content. split ( whereSeparator: { $0. isNewline } ) . map { $0. trimmingCharacters ( in: . whitespaces) }
43
+
44
+ var multilineComment = false
45
+ for line in lines {
46
+ if line. hasPrefix ( " // " ) {
47
+ continue
48
+ }
49
+ if line. hasPrefix ( " /*") {
50
+ multilineComment = true
51
+ }
52
+ if line.hasSuffix("*/" ) {
53
+ multilineComment = false
54
+ }
55
+ if multilineComment {
56
+ continue
57
+ }
58
+ if line. hasPrefix ( " @main " ) {
59
+ return true
60
+ }
61
+ }
62
+ return false
63
+ }
64
+
37
65
/// Build description for a Swift module.
38
66
public final class SwiftModuleBuildDescription {
39
67
/// The package this target belongs to.
@@ -216,40 +244,12 @@ public final class SwiftModuleBuildDescription {
216
244
return false
217
245
}
218
246
// looking into the file content to see if it is using the @main annotation which requires parse-as-library
219
- return ( try ? self . containsAtMain ( fileSystem: self . fileSystem, path: self . sources [ 0 ] ) ) ?? false
247
+ return ( try ? containsAtMain ( fileSystem: self . fileSystem, path: self . sources [ 0 ] ) ) ?? false
220
248
default :
221
249
return false
222
250
}
223
251
}
224
252
225
- // looking into the file content to see if it is using the @main annotation
226
- // this is not bullet-proof since theoretically the file can contain the @main string for other reasons
227
- // but it is the closest to accurate we can do at this point
228
- func containsAtMain( fileSystem: FileSystem , path: AbsolutePath ) throws -> Bool {
229
- let content : String = try self . fileSystem. readFileContents ( path)
230
- let lines = content. split ( whereSeparator: { $0. isNewline } ) . map { $0. trimmingCharacters ( in: . whitespaces) }
231
-
232
- var multilineComment = false
233
- for line in lines {
234
- if line. hasPrefix ( " // " ) {
235
- continue
236
- }
237
- if line. hasPrefix ( " /*") {
238
- multilineComment = true
239
- }
240
- if line.hasSuffix("*/" ) {
241
- multilineComment = false
242
- }
243
- if multilineComment {
244
- continue
245
- }
246
- if line. hasPrefix ( " @main " ) {
247
- return true
248
- }
249
- }
250
- return false
251
- }
252
-
253
253
/// The filesystem to operate on.
254
254
let fileSystem : FileSystem
255
255
0 commit comments