@@ -12,6 +12,9 @@ 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
15
18
16
19
extension Manifest {
17
20
public init ( path pathComponents: String ... , baseURL: String ) throws {
@@ -49,27 +52,36 @@ extension Manifest {
49
52
50
53
private func parse( manifestPath: String ) throws -> String ? {
51
54
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.
55
+ // For now, we load the manifest by having Swift interpret it directly.
56
+ // Eventually, we should have two loading processes, one that loads only
57
+ // the the declarative package specification using the Swift compiler
58
+ // directly and validates it.
62
59
63
60
let libdir = Resources . runtimeLibPath
64
61
65
62
var cmd = [ Resources . path. swiftc]
66
63
cmd += [ " --driver-mode=swift " ]
67
64
cmd += [ " -I " , libdir]
68
- cmd += [ " -L " , libdir, " -lPackageDescription " ]
65
+ cmd += [ " -L " , libdir, " -lPackageDescription " , " -llibc " , " -lPOSIX " ]
69
66
#if os(OSX)
70
67
cmd += [ " -target " , " x86_64-apple-macosx10.10 " ]
71
68
#endif
72
69
cmd += [ manifestPath]
73
70
74
- return try popen ( cmd, environment: [ " SWIFT_DUMP_PACKAGE " : " 1 " ] ) . chuzzle ( )
71
+ //Create and open a temporary file to write toml to
72
+ let filePath = Path . join ( manifestPath. parentDirectory, " .Package.toml " )
73
+ print ( " PATH: \( filePath) " )
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
+ fclose ( fp)
82
+
83
+ let toml = try File ( path: filePath) . enumerate ( ) . reduce ( " " ) { $0 + " \n " + $1 }
84
+ unlink ( filePath) //Delete the temp file after reading it
85
+
86
+ return toml
75
87
}
0 commit comments