@@ -12,6 +12,10 @@ import struct PackageType.Manifest
12
12
import func POSIX. realpath
13
13
import PackageDescription
14
14
import Utility
15
+ import func POSIX. fopen
16
+ import func libc. fileno
17
+ import func libc. unlink
18
+ import func libc. fclose
15
19
16
20
extension Manifest {
17
21
public init ( path pathComponents: String ... , baseURL: String ) throws {
@@ -49,16 +53,10 @@ extension Manifest {
49
53
50
54
private func parse( manifestPath: String ) throws -> String ? {
51
55
52
- // For now, we load the manifest by having Swift interpret it directly
53
- // and using a special environment variable to trigger the PackageDescription
54
- // library to dump the package (as TOML) at exit. Eventually, we should
55
- // have two loading processes, one that loads only the the declarative
56
- // package specification using the Swift compiler directly and validates
57
- // it.
58
- //
59
- // FIXME: We also should make the mechanism for communicating the
60
- // package between the PackageDescription module more robust, for example by passing
61
- // in the id of another file descriptor to write the output onto.
56
+ // For now, we load the manifest by having Swift interpret it directly.
57
+ // Eventually, we should have two loading processes, one that loads only
58
+ // the the declarative package specification using the Swift compiler
59
+ // directly and validates it.
62
60
63
61
let libdir = Resources . runtimeLibPath
64
62
@@ -71,5 +69,17 @@ private func parse(manifestPath: String) throws -> String? {
71
69
#endif
72
70
cmd += [ manifestPath]
73
71
74
- return try popen ( cmd, environment: [ " SWIFT_DUMP_PACKAGE " : " 1 " ] ) . chuzzle ( )
72
+ //Create and open a temporary file to write toml to
73
+ let filePath = Path . join ( manifestPath. parentDirectory, " .Package.toml " )
74
+ let fp = try fopen ( filePath, mode: . Write)
75
+ defer { fclose ( fp) }
76
+
77
+ //Pass the fd in arguments
78
+ cmd += [ " -fileno " , " \( fileno ( fp) ) " ]
79
+ try system ( cmd)
80
+
81
+ let toml = try File ( path: filePath) . enumerate ( ) . reduce ( " " ) { $0 + " \n " + $1 }
82
+ unlink ( filePath) //Delete the temp file after reading it
83
+
84
+ return toml != " " ? toml : nil
75
85
}
0 commit comments