Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd an "-Z offline" flag to Cargo, altering it's dependency resolution behavior #4770
Conversation
rust-highfive
assigned
alexcrichton
Dec 3, 2017
This comment has been minimized.
This comment has been minimized.
rust-highfive
commented
Dec 3, 2017
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
Awesome, thanks @chabapok! Mind adding some tests here as well for crates.io/git/path dependencies? The tests would go into |
This comment has been minimized.
This comment has been minimized.
|
I'll try to do this. |
This comment has been minimized.
This comment has been minimized.
|
Oh I'm mostly just thinking that you'd test things like error messages if the network is reached out to (or needs to be reached out to) and also tests for things like one project populating the cache so another can use it in offline mode (even if a more updated version is available) |
This comment has been minimized.
This comment has been minimized.
|
git repository may be remote or local. |
This comment has been minimized.
This comment has been minimized.
|
Oh right yeah we've got support in tests to set up "path" git repositories and Cargo just currently treats any remote (be it actually on the filesystem or across the network) as a network operation, so we can use path git repos in tests for this sort of functionality. |
This comment has been minimized.
This comment has been minimized.
|
How to about to not treat Let's do it like this. If git url starts with
|
This comment has been minimized.
This comment has been minimized.
|
Working with local git repositories is done as suggested. Added some tests. Pls, check. |
alexcrichton
reviewed
Dec 18, 2017
|
Thanks and sorry for the delay in reviewing! Could you be sure to add a few more tests cases like these as well?
|
|
|
||
| #[inline] | ||
| pub fn is_local_filesystem(url: &Url) -> bool { | ||
| url.scheme() == "file" |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 18, 2017
Member
Hm could we avoid this special casing? I don't think this is actually used that much in practice and treating all URLs uniformly would make writing tests much easier I think.
This comment has been minimized.
This comment has been minimized.
chabapok
Dec 19, 2017
Author
Contributor
Thanks for the review. I will improve the tests.
But i am not sure about treat all URLs uniformly.
As far, as i understand:
Now we did not distinguish between a local or network git repository.
But in offline mode, we would like to do this. We can allow to work with local repositories, but forbid to work with network repositories.
This can be useful for usual offline cases. For example, we have many projects A, B ... Z,that depends on the 'master' branch of our library LIB located in local filesystem.
We want to add some functionality to LIB without breaking many projects, and then use that functionality in some of our projects. We do not have network.
We do this in separate branch (for example, 'my_cool_feature'), as usually.
But after merge 'my_cool_feature' to 'master' branch of the LIB, projects A ... Z can not see top of the master.
There is no way to cache top of the master to the cargo cache without networking.
This will look strange: there is a local git repository - but we can not use it without network.
This code (and some other places in pr) is needed to handle this case.
If we remove this, the code and tests will be easier, but we will not be able to do this.
If we remove the pull-up from the local git repository into the cache, this will worsen usability.
It turns out that if this functionality is missing, we can develop binaries - but we can not use new changes in libraries in the offline mode.
Perhaps this case requires additional discussion?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 19, 2017
Member
Oh yeah for sure we could make this distinction but I've never in practice seen anyone using a local git repository. Instead these are just used in tests, where it's quite useful to use the local filesystem as if it were the network to be able to write tests against.
Perhaps let's not make a special distinction here and leave that to a future PR?
| @@ -160,6 +160,10 @@ impl<'cfg> Source for GitSource<'cfg> { | |||
| self.source_id.precise().is_none(); | |||
|
|
|||
| let (repo, actual_rev) = if should_update { | |||
| if self.config.cli_unstable().offline && !is_local_filesystem(self.remote.url()) { | |||
| bail!("Unable to fetch `{:?}`: you are in the offline mode", self.reference); | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 18, 2017
Member
I think this may not be quite the behavior we want to have, instead if we're in offline mode we'll want to entirely skip the update of a git repository and move straight to checking it out below (if it already exists). I think we'll only want to return an error like this in the case that the database doesn't already exist.
| @@ -506,7 +506,11 @@ impl Config { | |||
| } | |||
|
|
|||
| pub fn network_allowed(&self) -> bool { | |||
| !self.frozen | |||
| !self.frozen() && !self.cli_unstable().offline | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 18, 2017
Member
I'm a little worried about modifying this function which is already uses in a few other locations. For example I think this error message may no longer be right (or this one or this one). Perhaps these locations could use a central method to determine why the network isn't allowed?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 18, 2017
Member
Also I think that these error messages should never happen during offline mode, right? In that offline mode should divert Cargo from executing code paths like that.
| assert_that(p2.cargo("build").masquerade_as_nightly_cargo().arg("-Zoffline"), | ||
| execs().with_status(0) | ||
| .with_stderr_does_not_contain("Updating registry") | ||
| .with_stderr_does_not_contain("Downloading")); |
This comment has been minimized.
This comment has been minimized.
| assert_that(p.cargo("build").masquerade_as_nightly_cargo().arg("-Zoffline"), | ||
| execs().with_status(101) | ||
| .with_stderr_does_not_contain("Updating registry") | ||
| .with_stderr_does_not_contain("Downloading")); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 18, 2017
Member
Could this also use with_stderr to match the output and error message exactly?
|
|
||
| #[test] | ||
| fn cargo_compile_offline_not_try_update() { | ||
| use cargotest::ChannelChanger; |
This comment has been minimized.
This comment has been minimized.
| execs().with_status(101). | ||
| with_stderr_does_not_contain("[UPDATING] git repository [..]"). | ||
| with_stderr_contains("\ | ||
| [..]Unable to fetch `Branch(\"master\")`: you are in the offline mode[..]") |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 18, 2017
Member
Could this also use with_stderr to match the entire output?
Also could the output here perhaps get improved? The debug representation may not be the best thing to print out and present to users here.
| .build(); | ||
| assert_that(p.cargo("update").masquerade_as_nightly_cargo().arg("-Zoffline"), | ||
| execs().with_status(101). | ||
| with_stderr_contains("error: you can't update in the offline mode[..]")); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Depending on how new the kernel is on the Travis instances cargo gets built on, you might be able to use
|
This comment has been minimized.
This comment has been minimized.
|
@luser nice! I'd actually be totally down with implementing that today in Cargo when For kernel support we'd probably just use |
matklad
referenced this pull request
Dec 24, 2017
Closed
Initial addition of airplane mode #4686 #4864
chabapok
force-pushed the
chabapok:master
branch
from
75bce8a
to
b6ed99d
Dec 24, 2017
This comment has been minimized.
This comment has been minimized.
|
I had to rebase PR changes onto Changes (as proposed above):
Pls, check. |
alexcrichton
reviewed
Jan 3, 2018
|
This is looking fantastic @chabapok, thanks so much for the comprehensive tests! Just a few small nits but otherwise I think this is ready to merge! |
|
|
||
| assert_that(p2.cargo("build").masquerade_as_nightly_cargo().arg("-Zoffline"), | ||
| execs().with_status(0) | ||
| .with_stderr_does_not_contain("Updating registry") |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 3, 2018
Member
You're doing an exhaustive match of stderr below using with_stderr, so it's ok when using that to omit any calls to does_not_contain
| .with_stderr_does_not_contain("Downloading") | ||
| .with_stderr(format!("\ | ||
| [COMPILING] present_dep v1.2.3 | ||
| [COMPILING] bar v0.1.0 ({url}) |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 3, 2018
Member
It's ok to avoid using {url} and just use [..] here (aka don't match that part of the output)
| [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", | ||
| url = p2.url()))); | ||
|
|
||
| assert_that(process(&p2.bin("foo")), |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 3, 2018
Member
You can probably combine this assertion with the above one by using cargo run instead of cargo build, but either's fine!
| if let Some(config) = config { | ||
| if config.cli_unstable().offline { | ||
| msg.push_str("\nperhaps an error occurred because you are using \ | ||
| the offline mode"); |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 3, 2018
Member
I wonder if we can perhaps elaborate on this a bit? Maybe something like:
as a reminder, you're using offline mode (-Z offline) which
can sometimes cause surprising resolution failures, if this
error is too confusing you may with to retry without the
offline flag.
| @@ -151,6 +151,10 @@ impl<'cfg> Source for GitSource<'cfg> { | |||
|
|
|||
| let db_path = lock.parent().join("db").join(&self.ident); | |||
|
|
|||
| if self.config.cli_unstable().offline && !db_path.exists() { | |||
| bail!("can't checkout from '{}': you are in the offline mode", self.remote.url()); | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 3, 2018
Member
Could the -Z offline flag be mentioned as part of this error message as well?
This comment has been minimized.
This comment has been minimized.
|
|
chabapok
force-pushed the
chabapok:master
branch
from
0022322
to
d1b2c72
Jan 8, 2018
chabapok
force-pushed the
chabapok:master
branch
from
d1b2c72
to
3ed3497
Jan 8, 2018
This comment has been minimized.
This comment has been minimized.
|
Updates based on review. (and rebase to the current master because automerge confict) Pls, check. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 9, 2018
This comment has been minimized.
This comment has been minimized.
|
|
chabapok commentedDec 3, 2017
This PR is implementation of the #4686 (without "Populating the global cache" feature)