@@ -54,8 +54,7 @@ extension PluginTarget {
54
54
workingDirectory: AbsolutePath ,
55
55
outputDirectory: AbsolutePath ,
56
56
toolSearchDirectories: [ AbsolutePath ] ,
57
- toolNamesToPaths: [ String : AbsolutePath ] ,
58
- toolNamesToTriples: [ String : [ String ] ] ,
57
+ accessibleTools: [ String : ( path: AbsolutePath , triples: [ String ] ? ) ] ,
59
58
writableDirectories: [ AbsolutePath ] ,
60
59
readOnlyDirectories: [ AbsolutePath ] ,
61
60
fileSystem: FileSystem ,
@@ -78,8 +77,10 @@ extension PluginTarget {
78
77
var serializer = PluginContextSerializer ( fileSystem: fileSystem, buildEnvironment: buildEnvironment)
79
78
let pluginWorkDirId = try serializer. serialize ( path: outputDirectory)
80
79
let toolSearchDirIds = try toolSearchDirectories. map { try serializer. serialize ( path: $0) }
81
- let toolNamesToPathIds = try toolNamesToPaths. mapValues { try serializer. serialize ( path: $0) }
82
- let toolNamesToTriplesDict = toolNamesToTriples
80
+ let accessibleTools = try accessibleTools. mapValues { ( tool: ( AbsolutePath , [ String ] ? ) ) -> HostToPluginMessage . InputContext . Tool in
81
+ let path = try serializer. serialize ( path: tool. 0 )
82
+ return . init( path: path, triples: tool. 1 )
83
+ }
83
84
let actionMessage : HostToPluginMessage
84
85
switch action {
85
86
@@ -95,8 +96,7 @@ extension PluginTarget {
95
96
packages: serializer. packages,
96
97
pluginWorkDirId: pluginWorkDirId,
97
98
toolSearchDirIds: toolSearchDirIds,
98
- toolNamesToPathIds: toolNamesToPathIds,
99
- toolNamesToTriples: toolNamesToTriplesDict)
99
+ accessibleTools: accessibleTools)
100
100
actionMessage = . createBuildToolCommands(
101
101
context: wireInput,
102
102
rootPackageId: rootPackageId,
@@ -110,8 +110,7 @@ extension PluginTarget {
110
110
packages: serializer. packages,
111
111
pluginWorkDirId: pluginWorkDirId,
112
112
toolSearchDirIds: toolSearchDirIds,
113
- toolNamesToPathIds: toolNamesToPathIds,
114
- toolNamesToTriples: toolNamesToTriples)
113
+ accessibleTools: accessibleTools)
115
114
actionMessage = . performCommand(
116
115
context: wireInput,
117
116
rootPackageId: rootPackageId,
@@ -365,13 +364,13 @@ extension PackageGraph {
365
364
// Determine the tools to which this plugin has access, and create a name-to-path mapping from tool
366
365
// names to the corresponding paths. Built tools are assumed to be in the build tools directory.
367
366
var builtToolNames : [ String ] = [ ]
368
- let ( toolNamesToPaths , toolNamesToTriples ) = try pluginTarget. processAccessibleTools ( packageGraph: self , fileSystem: fileSystem, environment: buildEnvironment, for: try pluginScriptRunner. hostTriple) { name, path in
367
+ let accessibleTools = try pluginTarget. processAccessibleTools ( packageGraph: self , fileSystem: fileSystem, environment: buildEnvironment, for: try pluginScriptRunner. hostTriple) { name, path in
369
368
builtToolNames. append ( name)
370
369
return builtToolsDir. appending ( path)
371
370
}
372
371
373
372
// Determine additional input dependencies for any plugin commands, based on any executables the plugin target depends on.
374
- let toolPaths = toolNamesToPaths . values. sorted ( )
373
+ let toolPaths = accessibleTools . values. map { $0 . path } . sorted ( )
375
374
376
375
// Assign a plugin working directory based on the package, target, and plugin.
377
376
let pluginOutputDir = outputDir. appending ( components: package . identity. description, target. name, pluginTarget. name)
@@ -462,8 +461,7 @@ extension PackageGraph {
462
461
workingDirectory: package . path,
463
462
outputDirectory: pluginOutputDir,
464
463
toolSearchDirectories: toolSearchDirectories,
465
- toolNamesToPaths: toolNamesToPaths,
466
- toolNamesToTriples: toolNamesToTriples,
464
+ accessibleTools: accessibleTools,
467
465
writableDirectories: writableDirectories,
468
466
readOnlyDirectories: readOnlyDirectories,
469
467
fileSystem: fileSystem,
@@ -543,29 +541,26 @@ public extension PluginTarget {
543
541
} )
544
542
}
545
543
546
- func processAccessibleTools( packageGraph: PackageGraph , fileSystem: FileSystem , environment: BuildEnvironment , for hostTriple: Triple , builtToolHandler: ( _ name: String , _ path: RelativePath ) throws -> AbsolutePath ? ) throws -> ( toolNamesToPaths: [ String : AbsolutePath ] , toolNamesToTriples: [ String : [ String ] ] ) {
547
- var toolNamesToPaths : [ String : AbsolutePath ] = [ : ]
548
- // Add supported triples info per tool so they can be looked up when running the tool
549
- var toolNamesToTriples : [ String : [ String ] ] = [ : ]
544
+ func processAccessibleTools( packageGraph: PackageGraph , fileSystem: FileSystem , environment: BuildEnvironment , for hostTriple: Triple , builtToolHandler: ( _ name: String , _ path: RelativePath ) throws -> AbsolutePath ? ) throws -> [ String : ( path: AbsolutePath , triples: [ String ] ? ) ] {
545
+ var pluginAccessibleTools : [ String : ( path: AbsolutePath , triples: [ String ] ? ) ] = [ : ]
550
546
551
547
for dep in try accessibleTools ( packageGraph: packageGraph, fileSystem: fileSystem, environment: environment, for: hostTriple) {
552
548
switch dep {
553
549
case . builtTool( let name, let path) :
554
550
if let path = try builtToolHandler ( name, path) {
555
- toolNamesToPaths [ name] = path
551
+ pluginAccessibleTools [ name] = ( path, nil )
556
552
}
557
553
case . vendedTool( let name, let path, let triples) :
558
554
// Avoid having the path of an unsupported tool overwrite a supported one.
559
- guard !triples. isEmpty || toolNamesToPaths [ name] == nil else {
555
+ guard !triples. isEmpty || pluginAccessibleTools [ name] == nil else {
560
556
continue
561
557
}
562
- toolNamesToPaths [ name] = path
563
- // Need triples info for .vendedTool
564
- toolNamesToTriples [ name, default: [ ] ] . append ( contentsOf: triples)
558
+ let priorTriples = pluginAccessibleTools [ name] ? . triples ?? [ ]
559
+ pluginAccessibleTools [ name] = ( path, priorTriples + triples)
565
560
}
566
561
}
567
562
568
- return ( toolNamesToPaths , toolNamesToTriples )
563
+ return pluginAccessibleTools
569
564
}
570
565
}
571
566
0 commit comments