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

Out of tree #109

Closed
wants to merge 2 commits into from
Closed

Out of tree #109

wants to merge 2 commits into from

Conversation

ijackson
Copy link

Hi. I like to do builds out of tree, with the actual source code not writeable by the build process. This is achieved with cargo --manifest-path=..../Cargo.toml --target-dir=target. This does not work right now if one of the parents of the source code directory has its own cargo config: the cargo run by the cargo_metadata tests picks up the wrong cargo config.

In this MR I propose to fix this by changing directory to $CARGO_HOME. This is not ideal: it would be better to change back to the invocation directory, but the invocation directory is not currently available (rust-lang/cargo#8148)

I have checked that "cargo test" still works in both in-tree and out-of-tree builds.

We are going to want to do something more sophisticated than hardcode
"Cargo.toml" and use of current_dir().  So:

 * builder_interface, metadata_deps: Replace hardcoded "Cargo.toml"
   with manifest_path.
 * metadata, builder_interface: Replace open-coded
   current_dir().unwrap() with manifest_dir.
 * metadata: Add call to .manifest_path(manifest_path).

Currently manifest_path and manifest_dir are just "Cargo.toml" and
current_dir().unwrap(), so there is no functional change.  Splitting
this out as a separate commit will make the actual functional change
less full of noise.
These tests are invoked in the source directory.  In an out of tree
build, that may be totally different to the invocation directory.

We really want to chdir back to the cargo invocation directory.
Otherwise we risk (for example) picking up inappropriate cargo
configuration somewhere in the parents of the source directory.

This is not possible because cargo doesn't tell us what it is.

For now, the best guess is to change to CARGO_HOME.  That means
at least that we will pick up the right cargo configuration.

A consequence is that we must no longer use current_dir(), but rather
the directory containing the manifest, which cargo supplies in
CARGO_MANIFEST_DIR.
@oli-obk
Copy link
Owner

oli-obk commented Apr 24, 2020

So this doesn't require any actual changes, you just want to make sure we don't regress this by adding a test?

@ijackson
Copy link
Author

ijackson commented Apr 24, 2020 via email

@oli-obk
Copy link
Owner

oli-obk commented Apr 24, 2020

Ah wonderful. Can you add something to CI that will fail if we ever brick this? I feel like it's easy to break testing again for you in the future.

@ijackson
Copy link
Author

ijackson commented Apr 24, 2020 via email

@ijackson ijackson closed this Apr 24, 2020
@ijackson
Copy link
Author

ijackson commented Apr 24, 2020 via email

@oli-obk
Copy link
Owner

oli-obk commented Apr 24, 2020

phew... I'm not sure, and don't have the time to really dig into this. Do you think it will become better if your cargo issue is resolved?

@ijackson
Copy link
Author

ijackson commented Apr 24, 2020 via email

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.

2 participants