-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathPluginContext.swift
More file actions
65 lines (61 loc) · 2.81 KB
/
Copy pathPluginContext.swift
File metadata and controls
65 lines (61 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Foundation
import PackagePlugin
/// Provides information about the package for which the plugin is invoked,
/// as well as contextual information based on the plugin's stated intent
/// and requirements.
///
/// Build systems can provide their own conformance implementations.
protocol MetaProtocolCodablePluginContext {
/// The source code module type associated with this context.
///
/// Build can customize target type based on build context.
associatedtype Target: MetaProtocolCodableSourceTarget
/// The path of a writable directory into which the plugin or the build
/// commands it constructs can write anything it wants. This could include
/// any generated source files that should be processed further, and it
/// could include any caches used by the build tool or the plugin itself.
///
/// The plugin is in complete control of what is written under this
/// directory, and the contents are preserved between builds.
///
/// A plugin would usually create a separate subdirectory of this directory
/// for each command it creates, and the command would be configured to
/// write its outputs to that directory. The plugin may also create other
/// directories for cache files and other file system content that either
/// it or the command will need.
var pluginWorkDirectoryURL: URL { get }
/// The targets which are local to current context.
///
/// These targets are included in the same package/project as this context.
/// These targets are scanned if `local` scan mode provided in config.
var localTargets: [Target] { get }
/// Looks up and returns the path of a named command line executable tool.
///
/// The executable must be provided by an executable target or a binary
/// target on which the package plugin target depends. This function throws
/// an error if the tool cannot be found. The lookup is case sensitive.
///
/// - Parameter name: The executable tool name.
/// - Returns: The executable tool.
func tool(named name: String) throws -> PluginContext.Tool
}
extension PluginContext: MetaProtocolCodablePluginContext {
/// The targets which are local to current context.
///
/// Includes all the source code targets of the package.
var localTargets: [SwiftPackageTarget] {
`package`.targets.compactMap { target in
guard let sourceModule = target.sourceModule else { return nil }
return SwiftPackageTarget(module: sourceModule)
}
}
}
#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin
extension XcodePluginContext: MetaProtocolCodablePluginContext {
/// The targets which are local to current context.
///
/// Includes all the targets of the Xcode project.
var localTargets: [XcodeTarget] { xcodeProject.targets }
}
#endif