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

Add some notes about running Cargo's tests on Windows. #4609

Closed
wants to merge 1 commit into from

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Oct 11, 2017

Fixes #4591 and #4601.

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

and optional Unix tools from the Windows Command Prompt` to use the shell
that is bundled with Git, or place the path `C:\Program Files\Git\usr\bin`
towards the top of your PATH list.
* Avoid using a `~/.cargo/config` file. Some tests run in a temp directory
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a bug I think we should be able to fix, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have any ideas how to fix it, I could try to make a PR. I don't know of a way to prevent cargo from recursing up the directory structure. And I don't know of a way to get a Temp directory in Windows that is not under %USERPROFILE%. (See #4601)

Copy link
Member

Choose a reason for hiding this comment

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

We can just override the env var, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could override TMP, I just don't know of a safe path to use. It needs be to outside of the cargo repo, and outside of the user's home directory. We could create a random directory in the root of a drive (I think), but that doesn't sound good to me.

Copy link
Member

Choose a reason for hiding this comment

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

Cargo creates a home/tmp folder for each test, I think that can be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is using tempdir, that's the problem. tempdir uses the temp directory on Windows which is ~/AppData/Local/Temp/. Unfortunately since that is under the user's home directory, cargo will read ~/.cargo/config, and if you have [cargo-new] entries, the test will fail since those take priority. The only fixes I know of are:

  • Create a temp directory somewhere safe. But where?
  • Somehow prevent cargo from recursing up the directory structure.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like we should add a way for Cargo to avoid traversing upwards in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I just discovered #3869 which added __CARGO_TEST_ROOT as a hack to prevent this very issue. I will investigate if this can be leveraged to make this work, it should be simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, opened #4630 with a proposed fix.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

verify with your environment. Besides having a normal Rust development
environment (with CMake installed), check the following:

* `sh` from MSYS should be in your PATH (ahead of any other `sh` installations
Copy link
Member

Choose a reason for hiding this comment

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

Something about this isn't correct I think because AppVeyor doesn't have this in PATH, yet tests pass on AppVeyor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I actually ran a test in AppVeyor that printed the environment because I was confused about that too. They include C:\Program Files\Git\usr\bin in PATH. Here is the list.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, can you gist again the error that comes about from not having sh in PATH?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error is at the top of #4591.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One workaround for this would be to change git2 to only use sh if the helper contains shell-like characters. I'd be happy to try a PR for that, it's just a bigger change.

Copy link
Member

Choose a reason for hiding this comment

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

The test can test something else then which doesn't fail when sh isn't available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there is anything else the test can do. As it is, credential helpers need sh or they just don't work.

Copy link
Member

Choose a reason for hiding this comment

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

So... prefix the test with?

if Command::new("sh").arg("--version").output().is_err() {
    return 
}

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 wouldn't be my preference (I don't like tests that are silently ignored). If it were to do something like that, I was thinking it would probably need to run sh -c path/to/script. I don't think --version wouldn't be completely safe (for example, I don't think BSD sh handles that). Also, the path would need to use forward slashes on windows to not mysteriously fail with Cygwin. This is a pretty obscure issue, I was just trying to make it a little less frustrating for future Windows developers to get going. I'm a little concerned adding all this may make it more brittle.

Copy link
Member

Choose a reason for hiding this comment

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

Note that we're not looking for a successful execution of sh, just if the program exists.

@Eh2406
Copy link
Contributor

Eh2406 commented Jan 19, 2018

How much of this is still relevant?

@alexcrichton
Copy link
Member

I believe one was fixed through a PR and the other was fixed through an update of libgit2, so closing!

@ehuss
Copy link
Contributor Author

ehuss commented Jan 19, 2018

Sorry, I forgot to close this. However, I don't think libgit2 was ever updated (see alexcrichton/git2-rs#274).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants