Skip to content

Allow for .package(url: , branch:) syntax#3292

Merged
tomerd merged 6 commits into
swiftlang:mainfrom
miggs597:55857600
Feb 26, 2021
Merged

Allow for .package(url: , branch:) syntax#3292
tomerd merged 6 commits into
swiftlang:mainfrom
miggs597:55857600

Conversation

@miggs597

Copy link
Copy Markdown
Contributor

Improve quality of life when using a branch for a package dependency requirement.

It feels more natural to use .package(url:, branch:) as opposed to .package(url:,.branch())

rdar://55857600

Allows for a more natural way to use a branch requirement when compared to .package(url: , .branch())

That option is still available though

@abertelrud abertelrud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change! The lack of this convenience initializer has always been annoying to me.

The implementation itself looks good apart from the availability annotation, which is noted in the code. In addition to unit tests, it would also be a good idea to update the change log and to update the PackageDescription.md file at the same time.

/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - branch: A dependency requirement. See static methods on `Package.Dependency.Requirement` for available options.
@available(_PackageDescription, introduced: 5.3)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 999.0 until the version number of the next release is announced.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, I wasn't sure so I just did the current version, I'll take care of that and the other parts in the comment

@tomerd

tomerd commented Feb 19, 2021

Copy link
Copy Markdown
Contributor

@swift-ci please smoke test

@miggs597

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

@miggs597 miggs597 requested a review from abertelrud February 19, 2021 21:21
Comment thread CHANGELOG.md Outdated
* [#2937]
* Improvements

Adding a dependency requirement can now be done with the convenience initializer .package(url: , branch:)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I suggest backticks around the code so it gets styled differently.

dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "../Foo", branch: "master")

@abertelrud abertelrud Feb 19, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be using main. Or is that baked into the test fixture? (which we should eventually fix too — not necessarily as part of this PR).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's baked into the fixture, it's just that the version of git the test uses hasn't been updated to use main instead of master

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I wonder if that means that this test might unintentionally depend on the version of git that's installed. It might make sense to do what some of the other tests do (e.g. testMirrors) which would be to add something like:

Process.checkNonZeroExit(args: "git", "-C", path.pathString, "init")
Process.checkNonZeroExit(args: "git", "-C", path.pathString, "checkout", "-b", "mybranch")

and then have the dependency use that. That would make it independent of what the default branch was named.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have two kinds of test fixtures: those that have a .zip file containing a .git with prebaked repository contents (branch names, tags, etc), and plain directories, which the fixture() function sets up to have a newly initialized repository. For the latter kind, the name of the initial repository depends on the version of Git installed.

Maybe the right thing to do is to modify the initGitRepo() to check whether there's a main in the newly created repository and if not to do a:

Process.checkNonZeroExit(args: "git", "-C", path.pathString, "branch", "-m", "main")

so that all our unit tests can start out in a known state regardless of the version of Git installed on the machine running the test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then your new unit test wouldn't have to be modified (though some others might have to be adjusted to account for it). But it seems suboptimal that these tests will start failing once versions of Git that default to main start getting deployed more widely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we add

try systemQuietly([Git.tool, "-C", dir.pathString, "checkout", "-b", "main"])

to initGitRepo() ensuring there's always a main branch?

@abertelrud abertelrud Feb 24, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would fail if there's already a main, so I suggest we do:

branch -m main

I tested that that is a no-op if the branch is already named main.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in general I agree: could you modify initGitRepo() to do the branch -m main? That would make all the tests a lot more robust. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just got it working with branch -m main!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you!

@miggs597

Copy link
Copy Markdown
Contributor Author

@swift-ci please smoke test

@tomerd tomerd added the ready Author believes the PR is ready to be merged & any feedback has been addressed label Feb 23, 2021

@friedbunny friedbunny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a nice change, thanks.

Comment thread CHANGELOG.md Outdated
Refactoring instances of 'master' into 'main'

@abertelrud abertelrud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks!

@abertelrud

Copy link
Copy Markdown
Contributor

@swift-ci please smoke test

@neonichu

Copy link
Copy Markdown
Contributor

14:25:18 Test Case 'PackageCollectionsTests.testBrokenRefresh' started at 2021-02-24 16:24:09.278
14:25:18 Exited with signal code 11

This might be one for @tomerd, https://ci.swift.org/job/swift-package-manager-Linux-smoke-test/2982/

@neonichu

Copy link
Copy Markdown
Contributor

@swift-ci please smoke test linux

@tomerd tomerd merged commit 53457c3 into swiftlang:main Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Author believes the PR is ready to be merged & any feedback has been addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants