@@ -54,8 +54,7 @@ extension PluginTarget {
5454 workingDirectory: AbsolutePath ,
5555 outputDirectory: AbsolutePath ,
5656 toolSearchDirectories: [ AbsolutePath ] ,
57- toolNamesToPaths: [ String : AbsolutePath ] ,
58- toolNamesToTriples: [ String : [ String ] ] ,
57+ accessibleTools: [ String : ( path: AbsolutePath , triples: [ String ] ? ) ] ,
5958 writableDirectories: [ AbsolutePath ] ,
6059 readOnlyDirectories: [ AbsolutePath ] ,
6160 fileSystem: FileSystem ,
@@ -78,8 +77,10 @@ extension PluginTarget {
7877 var serializer = PluginContextSerializer ( fileSystem: fileSystem, buildEnvironment: buildEnvironment)
7978 let pluginWorkDirId = try serializer. serialize ( path: outputDirectory)
8079 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+ }
8384 let actionMessage : HostToPluginMessage
8485 switch action {
8586
@@ -95,8 +96,7 @@ extension PluginTarget {
9596 packages: serializer. packages,
9697 pluginWorkDirId: pluginWorkDirId,
9798 toolSearchDirIds: toolSearchDirIds,
98- toolNamesToPathIds: toolNamesToPathIds,
99- toolNamesToTriples: toolNamesToTriplesDict)
99+ accessibleTools: accessibleTools)
100100 actionMessage = . createBuildToolCommands(
101101 context: wireInput,
102102 rootPackageId: rootPackageId,
@@ -110,8 +110,7 @@ extension PluginTarget {
110110 packages: serializer. packages,
111111 pluginWorkDirId: pluginWorkDirId,
112112 toolSearchDirIds: toolSearchDirIds,
113- toolNamesToPathIds: toolNamesToPathIds,
114- toolNamesToTriples: toolNamesToTriples)
113+ accessibleTools: accessibleTools)
115114 actionMessage = . performCommand(
116115 context: wireInput,
117116 rootPackageId: rootPackageId,
@@ -365,13 +364,13 @@ extension PackageGraph {
365364 // Determine the tools to which this plugin has access, and create a name-to-path mapping from tool
366365 // names to the corresponding paths. Built tools are assumed to be in the build tools directory.
367366 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
369368 builtToolNames. append ( name)
370369 return builtToolsDir. appending ( path)
371370 }
372371
373372 // 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 ( )
375374
376375 // Assign a plugin working directory based on the package, target, and plugin.
377376 let pluginOutputDir = outputDir. appending ( components: package . identity. description, target. name, pluginTarget. name)
@@ -462,8 +461,7 @@ extension PackageGraph {
462461 workingDirectory: package . path,
463462 outputDirectory: pluginOutputDir,
464463 toolSearchDirectories: toolSearchDirectories,
465- toolNamesToPaths: toolNamesToPaths,
466- toolNamesToTriples: toolNamesToTriples,
464+ accessibleTools: accessibleTools,
467465 writableDirectories: writableDirectories,
468466 readOnlyDirectories: readOnlyDirectories,
469467 fileSystem: fileSystem,
@@ -543,29 +541,26 @@ public extension PluginTarget {
543541 } )
544542 }
545543
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 ] ? ) ] = [ : ]
550546
551547 for dep in try accessibleTools ( packageGraph: packageGraph, fileSystem: fileSystem, environment: environment, for: hostTriple) {
552548 switch dep {
553549 case . builtTool( let name, let path) :
554550 if let path = try builtToolHandler ( name, path) {
555- toolNamesToPaths [ name] = path
551+ pluginAccessibleTools [ name] = ( path, nil )
556552 }
557553 case . vendedTool( let name, let path, let triples) :
558554 // 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 {
560556 continue
561557 }
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)
565560 }
566561 }
567562
568- return ( toolNamesToPaths , toolNamesToTriples )
563+ return pluginAccessibleTools
569564 }
570565}
571566
0 commit comments