-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow relative path with swift package add-dependency
command
#7871
base: main
Are you sure you want to change the base?
Conversation
swift package add-dependency
swift package add-dependency
command
c9073bd
to
3925579
Compare
@bnbarham Just wanted to bump this. |
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.
Thanks @hi2gage! Definitely valuable to support relative paths here.
Due to access level and not wanting to make certain enums public, I opted to use MappablePackageDependency instead of Package.Dependency to represent the values coming from the CLI command.
Which enums would those be? Ideally MappablePackageDependency
would not be public, it really shouldn't be visible to commands.
@bnbarham No problem! I thought I would need to make // intentionally private to hide enum detail
private static func package(
name: String? = nil,
url: String,
requirement: Package.Dependency.SourceControlRequirement
) -> Package.Dependency {
return .init(name: name, location: url, requirement: requirement, traits: nil)
} but looking back over this again I realized this was written prior to the It would really simplify this PR to not use |
Aren't they already 🤔? I assume the issue was that there's no way to create a
If they need to be (depending on the above) - they just can't be public as this is the package manifest API. |
3925579
to
fbca3e6
Compare
fa8e2a3
to
153aa99
Compare
Hey @bnbarham I just pushed up the changes to use
Yes they are public 🤦I meant to say:
Technically I could call the existing initializers, but it requires some funky switching. The changes I just pushed uses the existing initializers. So let me know what you think about that. This being said if I made those initializers let packageDependency: PackageDescription.Package.Dependency
switch (firstRequirement, to) {
case (let .exact(version), nil):
packageDependency = .package(url: self.dependency, exact: version)
case (let .range(range), let to?):
packageDependency = .package(url: self.dependency, (range.lowerBound ..< to))
case (let .range(range), nil):
packageDependency = .package(url: self.dependency, range)
case (let .revision(revision), nil):
packageDependency = .package(url: self.dependency, revision: revision)
case (let .branch(branch), nil):
packageDependency = .package(url: self.dependency, branch: branch)
case (.branch, _?), (.revision, _?), (.exact, _?):
throw StringError("--to can only be specified with --from or --up-to-next-minor-from")
case (_, _):
throw StringError("unknown requirement")
} -> let packageDependency2: PackageDescription.Package.Dependency = .package(
url: self.dependency,
requirement: requirement,
traits: []
)
Agreed, they can't be public, making them package would be helpful but we can get around it if you want to keep those initializers locked down. |
I'd be fine making them |
153aa99
to
6aae1fd
Compare
Great! I just pushed up changes making those |
@bnbarham Just wanted to bump this, let me know if there is anything I can to help move this PR along. |
@swift-ci please test |
@swift-ci please test windows |
@hi2gage that did the trick. Running the tests now. I'm a little worried about adding the PackageDescription dependency since it was really only intended for the package manifest processing, but it actually makes sense how you're using it. This is actually pretty timely. We've been working at improving support for monorepos where relative packages are common. This will help setting them up. |
Hmm, the toolchain build in the smoke tests and the Windows builds are failing. Look like the new dependency on SwiftSyntax requires a change to the CMake files (which are used to build swiftpm in these environments). |
It's just that |
58f2416
to
1842725
Compare
Just pushed the changes to the cmake build |
Yup, we have a monorepo at work so that's why I was motivated to fix this problem. I'm glad that I'm able to help out. If there are other issues / chunks of work in this realm let me know, I've really enjoyed contributing to SPM. |
@swift-ci please test |
@swift-ci please test windows |
@swift-ci please test |
@swift-ci please test windows |
I'm not sure why the Windows build is breaking. It uses the CMakeLists file. |
Yeah me neither I thought that bc39a72 would have fixed this error.
Is there a windows VM image or sorts to run this locally? |
Looks like a missing dependency in the CMakeLists.txt file. |
I'm trying on my Windows machine. There is a Utilities/bootstrap utility that builds using CMake. I couldn't reproduce it on my Mac, which is surprising. |
@@ -24,6 +24,7 @@ target_link_libraries(PackageModelSyntax PUBLIC | |||
Basics | |||
PackageLoading | |||
PackageModel | |||
ProductDescription |
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.
I'm confused by this. There is no library called ProductDescription. Did you mean PackageDescription here?
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.
Yeah not sure what I was thinking here, I mixed these up. Just pushed change to PackageDescription
bc39a72
to
094ffe0
Compare
094ffe0
to
9615510
Compare
@swift-ci please test |
@swift-ci please test windows |
Enable passing relative path into
swift package add-dependency
Motivation:
Currently only
AbsolutePath
s are supported with--type path
flagThere is a need to support
RelativePath
because it's not uncommon to have a package structure inside of an xcodeproj as shown below.If we want to open
ParentPackage
by itself, it will not be able to resolve that package.This pr allows for the user to add a package with a
RelativePath
path via theswift package add-dependency --type path
command.Access level for
.package(name:url:requirement:traits:)
.package(name:url:requirement:)
.package(id:requirement:traits:)
were upgraded from
private
topackage
allowing access to these functions from thePackageCommands
module.Modifications:
swift package add-dependency
Result:
Both of the following commands are valid