-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathPathToURLMigration.swift
More file actions
117 lines (111 loc) · 4.8 KB
/
Copy pathPathToURLMigration.swift
File metadata and controls
117 lines (111 loc) · 4.8 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import Foundation
import PackagePlugin
#if swift(<6)
extension PluginContext.Tool {
/// Full path of the built or provided tool in the file system.
var url: URL {
Config.url(forFilePath: path.string)
}
}
extension PackagePlugin.File {
/// The path of the file.
var url: URL {
Config.url(forFilePath: path.string)
}
}
extension PluginContext {
/// 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 di-
/// rectory, 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 {
Config.url(forFilePath: pluginWorkDirectory.string)
}
}
extension Command {
/// Returns a command that runs when any of its output files are needed by
/// the build, but out-of-date.
///
/// An output file is out-of-date if it doesn't exist, or if any input files
/// have changed since the command was last run.
///
/// - Note: the paths in the list of output files may depend on the list of
/// input file paths, but **must not** depend on reading the contents of
/// any input files. Such cases must be handled using a `prebuildCommand`.
///
/// - parameters:
/// - displayName: An optional string to show in build logs and other
/// status areas.
/// - executable: The absolute path to the executable to be invoked.
/// - arguments: Command-line arguments to be passed to the executable.
/// - environment: Environment variable assignments visible to the
/// executable.
/// - inputFiles: Files on which the contents of output files may depend.
/// Any paths passed as `arguments` should typically be passed here as
/// well.
/// - outputFiles: Files to be generated or updated by the executable.
/// Any files recognizable by their extension as source files
/// (e.g. `.swift`) are compiled into the target for which this command
/// was generated as if in its source directory; other files are treated
/// as resources as if explicitly listed in `Package.swift` using
/// `.process(...)`.
static func buildCommand(
displayName: String?, executable: URL, arguments: [String],
environment: [String: String] = [:], inputFiles: [URL] = [],
outputFiles: [URL] = []
) -> Self {
.buildCommand(
displayName: displayName,
executable: .init(Config.filePath(forURL: executable)),
arguments: arguments,
environment: environment,
inputFiles: inputFiles.map { .init(Config.filePath(forURL: $0)) },
outputFiles: outputFiles.map { .init(Config.filePath(forURL: $0)) }
)
}
}
#if canImport(XcodeProjectPlugin)
extension XcodePluginContext {
/// 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 di-
/// rectory, 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 {
Config.url(forFilePath: pluginWorkDirectory.string)
}
}
#endif
#endif
extension SourceModuleTarget {
/// The absolute path of the target directory in the local file system.
var directoryURL: URL {
#if swift(<6)
return Config.url(forFilePath: directory.string)
#else
switch self {
case let target as ClangSourceModuleTarget:
return target.directoryURL
case let target as SwiftSourceModuleTarget:
return target.directoryURL
default:
fatalError("Unsupported target type")
}
#endif
}
}