-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Improve support for non-master
main branches
#8364
Conversation
r? @ehuss (rust_highfive has picked a reviewer for you, use r? to override) |
Note that this builds on the internal refactorings of #8363, so the first commit of that is included here. This is also something we'll likely want to carefully approach, it's by default a breaking change to Cargo. (if a git repo has a non-default branch named |
Related to #3517 I assume |
☔ The latest upstream changes (presumably #8363) made this pull request unmergeable. Please resolve the merge conflicts. |
This commit improves Cargo's support for git repositories whose "main branch" is not called `master`. Cargo currently pretty liberally assumes that if nothing else about a git repository is specified then `master` is the branch name to use. Instead now Cargo has a fourth option as the desired reference of a repository named `DefaultBranch`. Cargo doesn't know anything about the actual name of the default branch, it just updates how git references are fetched internally. This commit is motivated by news that GitHub is likely to switch away from the default branch being named `master` in the near future. It would be a bit of a bummer if from now on everyone had to type `branch = '...'`, so this tries to improve that!
c83eb93
to
4c02977
Compare
@@ -25,7 +25,6 @@ use std::path::Path; | |||
fn enable_build_std(e: &mut Execs, arg: Option<&str>) { | |||
e.env_remove("CARGO_HOME"); | |||
e.env_remove("HOME"); | |||
e.arg("-Zno-index-update"); |
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.
Why was this removed?
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.
This ended up being a bit of an odd coincidence, but what was happening is that this test relies on the index being updated by the Cargo used to drive the tests. The cargo
run here is assumed to read that index and work with it correctly. If we ever change anything about how the index is checked out, then this breaks because the new cargo
can't read the old index.
That's basically what happened here where the new Cargo is requiring refs/remotes/origin/HEAD
to resolve the most recent commit of the index, but previous Cargo would only fill in refs/remotes/origin/master
. This meant that with -Zno-index-update
the new cargo
binary would fail to update the index and would think there were no crates.
I can't actually recall the original purpose for this argument myself, but it didn't seem to slow down too too much when adding this back in.
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.
Oh, that's a bit worrisome. I think there are a fair number of users of Zno-index-update
, and it looks like it just breaks with a pre-existing index. Would it be possible to handle that?
This was added from the original build-std tests where there were over 30 of them. In #7350 the build-std suite was improved where only 3 "full" tests were moved to build-std/main.rs
.
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 should have said, is there an easy way to handle it? If not, I guess since it is an unstable feature, might not be worth putting in the effort if it isn't easy.
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.
Oh I think this is only localized to this test suite. If you were, for example, to do:
$ cargo +nightly test --no-run
$ rm -rf $HOME/.cargo/registry
$ CARGO_RUN_BUILD_STD_TESTS=1 rustup run nightly ./target/debug/deps/build_std-*
this breaks today. The tests rely on the index already being up-to-date, and this just happens to work because the Cargo we're testing and the outer cargo (which ran cargo +nightly test
) agree on the index format, so the tests know they'll be able to use the index the outer Cargo populated.
We could perhaps handle this by fetching the HEAD
reference into refs/remotes/origin/master
and then reading that, but I'd just want to confirm that we're on the same page about the fallout we're dealing with.
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.
The fallout I'm thinking of, is if someone has the registry populated from a current version of Cargo, and then they update to a nightly with this PR, and the first command they run is cargo build -Zno-index-update
, it will fail with error: no matching package named …
, which is a bit confusing.
I'm not sure what the likelyhood is that someone runs with -Zno-index-update
as the very first command after updating. As I mentioned, only bother if it is easy to handle. It seems like it is unlikely that it would be the first command someone would run. I believe Crater does an initial fetch, so crater should be safe I would think.
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.
It's true that it's a confusing error, yeah. Do you think it's worth trying to return a better error?
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.
Eh. I'm inclined to say "no" because it is an unstable feature, and I think it is unlikely that someone will run that as the first command.
r=me if you think this is ready to go.
Does crater's support for building git repositories (other than those represented by crates.io) extend to building repositories with git dependencies? If so, we could run this through crater. I think, given appropriate announcement in advance, we could make this change. (Nit: we might wish to spell it |
Thanks for fixing this! Just ran into this bug after renaming my main branch. |
@joshtriplett that's a good point! I do believe a crater run would be possible if we'd like. |
📌 Commit 4c02977 has been approved by |
⌛ Testing commit 4c02977 with merge 16a1b0bcb3150fda94d9e47ac05f38dc0c9bc3ed... |
💔 Test failed - checks-azure |
@bors: retry |
⌛ Testing commit 4c02977 with merge 160318faac7d03267c86dd40245be0e99b4accd3... |
💔 Test failed - checks-azure |
@bors: retry |
☀️ Test successful - checks-azure |
Update cargo ## cargo 10 commits in c26576f9adddd254b3dd63aecba176434290a9f6..305eaf0dc5f5a38d6e8041319c2da95b71cf6a4a 2020-06-23 16:21:21 +0000 to 2020-06-30 14:16:08 +0000 - Update core-foundation requirement from 0.7.0 to 0.9.0 (rust-lang/cargo#8432) - Parse `# env-dep` directives in dep-info files (rust-lang/cargo#8421) - Move string interning to util (rust-lang/cargo#8419) - Expose built cdylib artifacts in the Compilation structure (rust-lang/cargo#8418) - Remove unused serde_derive dependency from the crates.io crate (rust-lang/cargo#8416) - Remove unused remove_dir_all dependency (rust-lang/cargo#8412) - Improve git error messages a bit (rust-lang/cargo#8409) - Improve the description of Config.home_path (rust-lang/cargo#8408) - Improve support for non-`master` main branches (rust-lang/cargo#8364) - Document that OUT_DIR in JSON messages is an absolute path (rust-lang/cargo#8403) ## rls 2020-06-19 15:36:00 +0200 to 2020-06-30 23:34:52 +0200 - Update cargo (rust-lang/rls#1686)
Update cargo, rls ## cargo 14 commits in c26576f9adddd254b3dd63aecba176434290a9f6..fede83ccf973457de319ba6fa0e36ead454d2e20 2020-06-23 16:21:21 +0000 to 2020-07-02 21:51:34 +0000 - Fix overflow error on 32-bit. (rust-lang/cargo#8446) - Exclude the target directory from backups using CACHEDIR.TAG (rust-lang/cargo#8378) - CONTRIBUTING.md: Link to Zulip rather than Discord (rust-lang/cargo#8436) - Update built-in help for features (rust-lang/cargo#8433) - Update core-foundation requirement from 0.7.0 to 0.9.0 (rust-lang/cargo#8432) - Parse `# env-dep` directives in dep-info files (rust-lang/cargo#8421) - Move string interning to util (rust-lang/cargo#8419) - Expose built cdylib artifacts in the Compilation structure (rust-lang/cargo#8418) - Remove unused serde_derive dependency from the crates.io crate (rust-lang/cargo#8416) - Remove unused remove_dir_all dependency (rust-lang/cargo#8412) - Improve git error messages a bit (rust-lang/cargo#8409) - Improve the description of Config.home_path (rust-lang/cargo#8408) - Improve support for non-`master` main branches (rust-lang/cargo#8364) - Document that OUT_DIR in JSON messages is an absolute path (rust-lang/cargo#8403) ## rls 2020-06-19 15:36:00 +0200 to 2020-06-30 23:34:52 +0200 - Update cargo (rust-lang/rls#1686)
Fixes rust-lang#8468 which was a regression of rust-lang#8364 .
This commit is intended to be an effective but not literal revert of rust-lang#8364. Internally Cargo will still distinguish between `DefaultBranch` and `Branch("master")` when reading `Cargo.toml` files, but for almost all purposes the two are equivalent. This will namely fix the issue we have with lock file encodings where both are encoded with no `branch` (and without a branch it's parsed from a lock file as `DefaultBranch`). This will preserve the change that `cargo vendor` will not print out `branch = "master"` annotations but that desugars to match the lock file on the other end, so it should continue to work. Tests have been added in this commit for the regressions found on rust-lang#8468.
Prepare for not defaulting to master branch for git deps This PR is the "equivalent" of #8503 for the nightly channel of Rust (the master branch of Cargo). The purpose of this change is to fix the breakage from #8364 but to still pave a path forward to enabling the feature added in #8364, namely reinterpreting dependency directives without a `branch` directive as depending on `HEAD` insead of depending on `master`. This is a series of commits which implements a few mitigation strategies, but they're all adding up into a larger plan to roll out this change with, ideally, no breaking changes for those "reasonably" keeping up with Rust. The changes here are: * Cargo still internally differentiates between `DefaultBranch` and `Branch("master")`, so it knows what you wrote in the manifest. These two, however, hash and equate together so everything in Cargo considers them equivalent. * Cargo will now issue a warning whenever it fetches a repository pinned to `DefaultBranch` and the branch's `master` branch doesn't actually match `HEAD`. This avenue of breakage didn't arise but I added it here for completionism about not having to deal with breakage from this change again. * Cargo has now implemented a new future lockfile format. Internally this is dubbed "v3". The changes in this format is that it will have a `version` marker at the top of the file as well as encoding git dependencies different. Today `DefaultBranch` and `Branch("master")` encode the same way, but in the future they will encode differently. * Cargo now has a warning where if you have a mixture of `DefaultBranch` and `Branch("master")` in your build. The intention here is to get everyone on one or the other so the transition to the new lock file format can go smoothly. With all of these pieces in place the intention is that there is no breakage from #8364 as well. Additionally projects that *would* break will receive warnings. (note that projects "broken" today, those we've got issues for, will likely not get warnings, but that's because it was accidental we broke them). The long-term plan is to let this bake for quite some time, and then as part of the same change land an update to the new lock file format as well as "fixing" `SourceId` to consider these two directives different. When this change happens we should have guaranteed, for all currently active projects, they're either only using `branch = "master"` or no directive at all. We can therefore unambiguosly read the previous `Cargo.lock` to transition it into a new `Cargo.lock` which will either have `?branch=master` or nothing. I'm not sure how long this will need to bake for because unfortunately version changes to `Cargo.lock` cannot be taken lightly. We haven't even bumped the default format for old lock files to `V2` yet, they're still on `V1`. Hopefully in getting this in early-ish, though, we can at least get the ball rolling. Closes #8468
This commit improves Cargo's support for git repositories whose "main
branch" is not called
master
. Cargo currently pretty liberally assumesthat if nothing else about a git repository is specified then
master
is the branch name to use. Instead now Cargo has a fourth option as the
desired reference of a repository named
DefaultBranch
. Cargo doesn'tknow anything about the actual name of the default branch, it just
updates how git references are fetched internally.
This commit is motivated by news that GitHub is likely to switch away
from the default branch being named
master
in the near future. Itwould be a bit of a bummer if from now on everyone had to type
branch = '...'
, so this tries to improve that!Closes #3517