-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow relative path with swift package add-dependency
command
#7871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import SwiftSyntaxBuilder | |
import struct TSCUtility.Version | ||
|
||
/// Add a target to a manifest's source code. | ||
public struct AddTarget { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swiftformat made this change |
||
public enum AddTarget { | ||
/// The set of argument labels that can occur after the "targets" | ||
/// argument in the Package initializers. | ||
/// | ||
|
@@ -27,7 +27,7 @@ public struct AddTarget { | |
private static let argumentLabelsAfterTargets: Set<String> = [ | ||
"swiftLanguageVersions", | ||
"cLanguageStandard", | ||
"cxxLanguageStandard" | ||
"cxxLanguageStandard", | ||
] | ||
|
||
/// The kind of test harness to use. This isn't part of the manifest | ||
|
@@ -85,7 +85,7 @@ public struct AddTarget { | |
target.dependencies.append(contentsOf: macroTargetDependencies) | ||
|
||
default: | ||
break; | ||
break | ||
} | ||
|
||
var newPackageCall = try packageCall.appendingToArrayArgument( | ||
|
@@ -103,7 +103,7 @@ public struct AddTarget { | |
guard let outerDirectory else { | ||
return PackageEditResult( | ||
manifestEdits: [ | ||
.replace(packageCall, with: newPackageCall.description) | ||
.replace(packageCall, with: newPackageCall.description), | ||
] | ||
) | ||
} | ||
|
@@ -114,7 +114,7 @@ public struct AddTarget { | |
var auxiliaryFiles: AuxiliaryFiles = [] | ||
|
||
// Add the primary source file. Every target type has this. | ||
addPrimarySourceFile( | ||
self.addPrimarySourceFile( | ||
outerPath: outerPath, | ||
target: target, | ||
configuration: configuration, | ||
|
@@ -125,7 +125,7 @@ public struct AddTarget { | |
var extraManifestEdits: [SourceEdit] = [] | ||
switch target.type { | ||
case .macro: | ||
addProvidedMacrosSourceFile( | ||
self.addProvidedMacrosSourceFile( | ||
outerPath: outerPath, | ||
target: target, | ||
to: &auxiliaryFiles | ||
|
@@ -135,7 +135,7 @@ public struct AddTarget { | |
newPackageCall = try AddPackageDependency | ||
.addPackageDependencyLocal( | ||
.swiftSyntax( | ||
configuration: installedSwiftPMConfiguration | ||
configuration: installedSwiftPMConfiguration | ||
), | ||
to: newPackageCall | ||
) | ||
|
@@ -149,7 +149,7 @@ public struct AddTarget { | |
.positionAfterSkippingLeadingTrivia | ||
extraManifestEdits.append( | ||
SourceEdit( | ||
range: insertPos..<insertPos, | ||
range: insertPos ..< insertPos, | ||
replacement: newImport | ||
) | ||
) | ||
|
@@ -158,12 +158,12 @@ public struct AddTarget { | |
} | ||
} | ||
|
||
default: break; | ||
default: break | ||
} | ||
|
||
return PackageEditResult( | ||
manifestEdits: [ | ||
.replace(packageCall, with: newPackageCall.description) | ||
.replace(packageCall, with: newPackageCall.description), | ||
] + extraManifestEdits, | ||
auxiliaryFiles: auxiliaryFiles | ||
) | ||
|
@@ -182,20 +182,18 @@ public struct AddTarget { | |
) | ||
|
||
// Introduce imports for each of the dependencies that were specified. | ||
var importModuleNames = target.dependencies.map { | ||
$0.name | ||
} | ||
var importModuleNames = target.dependencies.map(\.name) | ||
|
||
// Add appropriate test module dependencies. | ||
if target.type == .test { | ||
switch configuration.testHarness { | ||
case .none: | ||
case .none: | ||
break | ||
|
||
case .xctest: | ||
importModuleNames.append("XCTest") | ||
|
||
case .swiftTesting: | ||
case .swiftTesting: | ||
importModuleNames.append("Testing") | ||
} | ||
} | ||
|
@@ -306,25 +304,25 @@ public struct AddTarget { | |
} | ||
} | ||
|
||
fileprivate extension TargetDescription.Dependency { | ||
extension TargetDescription.Dependency { | ||
/// Retrieve the name of the dependency | ||
var name: String { | ||
fileprivate var name: String { | ||
switch self { | ||
case .target(name: let name, condition: _), | ||
.byName(name: let name, condition: _), | ||
.product(name: let name, package: _, moduleAliases: _, condition: _): | ||
.byName(name: let name, condition: _), | ||
.product(name: let name, package: _, moduleAliases: _, condition: _): | ||
name | ||
} | ||
} | ||
} | ||
|
||
/// The array of auxiliary files that can be added by a package editing | ||
/// operation. | ||
fileprivate typealias AuxiliaryFiles = [(RelativePath, SourceFileSyntax)] | ||
private typealias AuxiliaryFiles = [(RelativePath, SourceFileSyntax)] | ||
|
||
fileprivate extension AuxiliaryFiles { | ||
extension AuxiliaryFiles { | ||
/// Add a source file to the list of auxiliary files. | ||
mutating func addSourceFile( | ||
fileprivate mutating func addSourceFile( | ||
path: RelativePath, | ||
sourceCode: SourceFileSyntax | ||
) { | ||
|
@@ -334,45 +332,42 @@ fileprivate extension AuxiliaryFiles { | |
|
||
/// The set of dependencies we need to introduce to a newly-created macro | ||
/// target. | ||
fileprivate let macroTargetDependencies: [TargetDescription.Dependency] = [ | ||
private let macroTargetDependencies: [TargetDescription.Dependency] = [ | ||
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"), | ||
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"), | ||
] | ||
|
||
/// The package dependency for swift-syntax, for use in macros. | ||
fileprivate extension PackageDependency { | ||
extension MappablePackageDependency.Kind { | ||
/// Source control URL for the swift-syntax package. | ||
static var swiftSyntaxURL: SourceControlURL { | ||
fileprivate static var swiftSyntaxURL: SourceControlURL { | ||
"https://github.com/swiftlang/swift-syntax.git" | ||
} | ||
|
||
/// Package dependency on the swift-syntax package. | ||
static func swiftSyntax( | ||
configuration: InstalledSwiftPMConfiguration | ||
) -> PackageDependency { | ||
fileprivate static func swiftSyntax( | ||
configuration: InstalledSwiftPMConfiguration | ||
) -> MappablePackageDependency.Kind { | ||
let swiftSyntaxVersionDefault = configuration | ||
.swiftSyntaxVersionForMacroTemplate | ||
let swiftSyntaxVersion = Version(swiftSyntaxVersionDefault.description)! | ||
|
||
return .sourceControl( | ||
identity: PackageIdentity(url: swiftSyntaxURL), | ||
nameForTargetDependencyResolutionOnly: nil, | ||
location: .remote(swiftSyntaxURL), | ||
requirement: .range(.upToNextMajor(from: swiftSyntaxVersion)), | ||
productFilter: .everything, | ||
traits: [] | ||
name: nil, | ||
location: self.swiftSyntaxURL.absoluteString, | ||
requirement: .range(.upToNextMajor(from: swiftSyntaxVersion)) | ||
) | ||
} | ||
} | ||
|
||
fileprivate extension TargetDescription { | ||
var sanitizedName: String { | ||
name | ||
extension TargetDescription { | ||
fileprivate var sanitizedName: String { | ||
self.name | ||
.spm_mangledToC99ExtendedIdentifier() | ||
.localizedFirstWordCapitalized() | ||
} | ||
} | ||
|
||
fileprivate extension String { | ||
func localizedFirstWordCapitalized() -> String { prefix(1).localizedCapitalized + dropFirst() } | ||
extension String { | ||
fileprivate func localizedFirstWordCapitalized() -> String { prefix(1).localizedCapitalized + dropFirst() } | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swiftformat made this change