Skip to content

Commit

Permalink
Remove importPaths option
Browse files Browse the repository at this point in the history
# Motivation
In #1373 (comment), we added a new option to the SPM plugin config file that allows passing custom import paths (aka search paths) to protoc. Recently, I wanted to try this out but found out that this was not working as expected.

1. The option is configured "globally" across invocations. That doesn't really compose with the way we have structured the other settings
2. The option expects absolute paths right now which makes it almost impossible to use.

I propose to remove this option again from the main branch so we are not shipping it with the 2.0 release. In the PR, I asked the adopter if he is actually using that and confirmed that it isn't working like he expected it to work and wasn't using it.

# Modification
Remove the `importPaths` option again.
  • Loading branch information
FranzBusch authored and thomasvl committed Mar 29, 2023
1 parent 604e01a commit 7a5782e
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions Plugins/SwiftProtobufPlugin/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ struct SwiftProtobufPlugin: BuildToolPlugin {
var fileNaming: FileNaming?
}

/// Specify the directory in which to search for
/// imports. May be specified multiple times;
/// directories will be searched in order.
/// The target source directory is always appended
/// to the import paths.
var importPaths: [String]?

/// The path to the `protoc` binary.
///
/// If this is not set, SPM will try to find the tool itself.
Expand All @@ -95,11 +88,6 @@ struct SwiftProtobufPlugin: BuildToolPlugin {

try validateConfiguration(configuration)

var importPaths: [Path] = [target.directory]
if let configuredImportPaths = configuration.importPaths {
importPaths.append(contentsOf: configuredImportPaths.map { Path($0) })
}

// We need to find the path of protoc and protoc-gen-swift
let protocPath: Path
if let configuredProtocPath = configuration.protocPath {
Expand All @@ -123,8 +111,7 @@ struct SwiftProtobufPlugin: BuildToolPlugin {
invocation: invocation,
protocPath: protocPath,
protocGenSwiftPath: protocGenSwiftPath,
outputDirectory: outputDirectory,
importPaths: importPaths
outputDirectory: outputDirectory
)
}
}
Expand All @@ -137,26 +124,24 @@ struct SwiftProtobufPlugin: BuildToolPlugin {
/// - protocPath: The path to the `protoc` binary.
/// - protocGenSwiftPath: The path to the `protoc-gen-swift` binary.
/// - outputDirectory: The output directory for the generated files.
/// - importPaths: List of paths to pass with "-I <path>" to `protoc`
/// - Returns: The build command.
private func invokeProtoc(
target: Target,
invocation: Configuration.Invocation,
protocPath: Path,
protocGenSwiftPath: Path,
outputDirectory: Path,
importPaths: [Path]
outputDirectory: Path
) -> Command {
// Construct the `protoc` arguments.
var protocArgs = [
"--plugin=protoc-gen-swift=\(protocGenSwiftPath)",
"--swift_out=\(outputDirectory)",
]

importPaths.forEach { path in
protocArgs.append("-I")
protocArgs.append("\(path)")
}
// We need to add the target directory as a search path since we require the user to specify
// the proto files relative to it.
protocArgs.append("-I")
protocArgs.append("\(target.directory)")

// Add the visibility if it was set
if let visibility = invocation.visibility {
Expand Down

0 comments on commit 7a5782e

Please sign in to comment.