Skip to content
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 for .package(url: , branch:) syntax #3292

Merged
merged 6 commits into from
Feb 26, 2021
Merged

Conversation

miggs597
Copy link
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
Copy link
Contributor

@abertelrud abertelrud left a comment

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
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
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
Copy link
Contributor

tomerd commented Feb 19, 2021

@swift-ci please smoke test

@miggs597
Copy link
Contributor Author

@swift-ci please smoke test

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

Adding a dependency requirement can now be done with the convenience initializer .package(url: , branch:)
Copy link
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")
Copy link
Contributor

@abertelrud abertelrud Feb 19, 2021

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
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
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
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
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
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?

Copy link
Contributor

@abertelrud abertelrud Feb 24, 2021

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
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
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
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
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
Copy link
Member

@friedbunny friedbunny left a comment

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.

CHANGELOG.md Outdated Show resolved Hide resolved
Refactoring instances of 'master' into 'main'
Copy link
Contributor

@abertelrud abertelrud left a comment

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
Contributor

@swift-ci please smoke test

@neonichu
Copy link
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
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