@@ -17,48 +17,56 @@ import Foundation
17
17
struct CMakeSmokeTest : CommandPlugin {
18
18
func performCommand( context: PluginContext , arguments: [ String ] ) async throws {
19
19
var args = ArgumentExtractor ( arguments)
20
-
21
20
let hostOS = try OS . host ( )
22
21
22
+ guard args. extractFlag ( named: " disable-sandbox " ) > 0 else {
23
+ throw Errors . missingRequiredOption ( " --disable-sandbox " )
24
+ }
25
+
23
26
guard let cmakePath = args. extractOption ( named: " cmake-path " ) . last else { throw Errors . missingRequiredOption ( " --cmake-path " ) }
24
27
print ( " using cmake at \( cmakePath) " )
25
28
let cmakeURL = URL ( filePath: cmakePath)
26
29
guard let ninjaPath = args. extractOption ( named: " ninja-path " ) . last else { throw Errors . missingRequiredOption ( " --ninja-path " ) }
27
30
print ( " using ninja at \( ninjaPath) " )
28
31
let ninjaURL = URL ( filePath: ninjaPath)
29
- guard let sysrootPath = args. extractOption ( named: " sysroot-path " ) . last else { throw Errors . missingRequiredOption ( " --sysroot-path " ) }
30
- print ( " using sysroot at \( sysrootPath) " )
32
+ let sysrootPath = args. extractOption ( named: " sysroot-path " ) . last
33
+ if let sysrootPath {
34
+ print ( " using sysroot at \( sysrootPath) " )
35
+ }
31
36
32
37
let moduleCachePath = context. pluginWorkDirectoryURL. appending ( component: " module-cache " ) . path ( )
33
38
34
39
let swiftBuildURL = context. package . directoryURL
35
40
let swiftBuildBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-build " )
36
41
print ( " swift-build: \( swiftBuildURL. path ( ) ) " )
37
42
38
- let swiftToolsSupportCoreURL = try findSiblingRepository ( " swift-tools-support-core " , swiftBuildURL : swiftBuildURL )
43
+ let swiftToolsSupportCoreURL = try findDependency ( " swift-tools-support-core " , pluginContext : context )
39
44
let swiftToolsSupportCoreBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-tools-support-core " )
40
45
41
- let swiftSystemURL = try findSiblingRepository ( " swift-system " , swiftBuildURL : swiftBuildURL )
46
+ let swiftSystemURL = try findDependency ( " swift-system " , pluginContext : context )
42
47
let swiftSystemBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-system " )
43
48
44
- let llbuildURL = try findSiblingRepository ( " llbuild " , swiftBuildURL : swiftBuildURL )
49
+ let llbuildURL = try findDependency ( " swift- llbuild" , pluginContext : context )
45
50
let llbuildBuildURL = context. pluginWorkDirectoryURL. appending ( component: " llbuild " )
46
51
47
- let swiftArgumentParserURL = try findSiblingRepository ( " swift-argument-parser " , swiftBuildURL : swiftBuildURL )
52
+ let swiftArgumentParserURL = try findDependency ( " swift-argument-parser " , pluginContext : context )
48
53
let swiftArgumentParserBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-argument-parser " )
49
54
50
- let swiftDriverURL = try findSiblingRepository ( " swift-driver " , swiftBuildURL : swiftBuildURL )
55
+ let swiftDriverURL = try findDependency ( " swift-driver " , pluginContext : context )
51
56
let swiftDriverBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-driver " )
52
57
53
58
for url in [ swiftToolsSupportCoreBuildURL, swiftSystemBuildURL, llbuildBuildURL, swiftArgumentParserBuildURL, swiftDriverBuildURL, swiftBuildBuildURL] {
54
59
try FileManager . default. createDirectory ( at: url, withIntermediateDirectories: true )
55
60
}
56
61
57
- let sharedSwiftFlags = [
58
- " -sdk " , sysrootPath,
62
+ var sharedSwiftFlags = [
59
63
" -module-cache-path " , moduleCachePath
60
64
]
61
65
66
+ if let sysrootPath {
67
+ sharedSwiftFlags += [ " -sdk " , sysrootPath]
68
+ }
69
+
62
70
let cMakeProjectArgs = [
63
71
" -DArgumentParser_DIR= \( swiftArgumentParserBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) " ,
64
72
" -DLLBuild_DIR= \( llbuildBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) " ,
@@ -107,11 +115,28 @@ struct CMakeSmokeTest: CommandPlugin {
107
115
print ( " Built swift-build " )
108
116
}
109
117
110
- func findSiblingRepository( _ name: String , swiftBuildURL: URL ) throws -> URL {
111
- let url = swiftBuildURL. deletingLastPathComponent ( ) . appending ( component: name)
112
- print ( " \( name) : \( url. path ( ) ) " )
113
- guard FileManager . default. fileExists ( atPath: url. path ( ) ) else { throw Errors . missingRepository ( url. path ( ) ) }
114
- return url
118
+ func findDependency( _ name: String , pluginContext: PluginContext ) throws -> URL {
119
+ var stack : [ Package ] = pluginContext. package . dependencies. map { $0. package }
120
+ var visited = Set ( stack. map { $0. id } )
121
+ var transitiveDependencies = pluginContext. package . dependencies. map { $0. package }
122
+ while let current = stack. popLast ( ) {
123
+ for dependency in current. dependencies {
124
+ guard visited. insert ( dependency. package . id) . inserted else {
125
+ continue
126
+ }
127
+ transitiveDependencies. append ( dependency. package )
128
+ stack. append ( dependency. package )
129
+ }
130
+ }
131
+ guard let dependency = transitiveDependencies. first ( where: { $0. id == name } ) else {
132
+ throw Errors . missingRepository ( name)
133
+ }
134
+ let dependencyURL = dependency. directoryURL
135
+ print ( " \( name) : \( dependencyURL. path ( ) ) " )
136
+ guard FileManager . default. fileExists ( atPath: dependencyURL. path ( ) ) else {
137
+ throw Errors . missingRepository ( dependencyURL. path ( ) )
138
+ }
139
+ return dependencyURL
115
140
}
116
141
}
117
142
0 commit comments