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 target directory parameter --target-dir #5393

Merged
merged 2 commits into from Apr 24, 2018
Merged

Add target directory parameter --target-dir #5393

merged 2 commits into from Apr 24, 2018

Conversation

smithsps
Copy link
Contributor

Implements: #5308

Adds a target directory parameter, that acts in the same manner as the environment variable CARGO_TARGET_DIR, to the following subcommands:

  • bench
  • build
  • check
  • clean
  • doc
  • package
  • publish
  • run
  • rustc
  • rustdoc
  • test

@alexcrichton
Copy link
Member

r? @matklad

@@ -70,6 +70,8 @@ pub struct Config {
cache_rustc_info: bool,
/// Creation time of this config, used to output the total build time
creation_time: Instant,
/// Target Directory via resolved Cli parameter
cli_target_dir: Option<Filesystem>,
Copy link
Member

Choose a reason for hiding this comment

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

I think that instead of cli_target_dir, we can store computed target_dir. That is, we can change fn target_dir() to

fn target_dir(&self) -> Option<FileSystem> { self.target_dir.clone() }

and instead move all logic from it to configure method. I think that would be slightly more clear, because we'll only store something, instead of both storing and computing on the fly. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed!

I had some problems having the logic in configure as it would change some error messages with bad configs. But I was able to minimize it to just a bad_config::invalid_global_config situation, so it should be good.

let exe_name = format!("foo{}", env::consts::EXE_SUFFIX);

assert_that(
p.cargo("build").arg("--target-dir").arg("foo/target"),
Copy link
Member

Choose a reason for hiding this comment

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

We've recently added a nicer API for this: p.cargo("build --target-dir foo/target").

@matklad matklad self-assigned this Apr 21, 2018
@matklad matklad added the relnotes Release-note worthy label Apr 21, 2018
@bors
Copy link
Collaborator

bors commented Apr 22, 2018

☔ The latest upstream changes (presumably #5404) made this pull request unmergeable. Please resolve the merge conflicts.

@matklad
Copy link
Member

matklad commented Apr 24, 2018

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Apr 24, 2018

📌 Commit 0b530c3 has been approved by matklad

@bors
Copy link
Collaborator

bors commented Apr 24, 2018

⌛ Testing commit 0b530c3 with merge 7debd81...

bors added a commit that referenced this pull request Apr 24, 2018
Add target directory parameter --target-dir

Implements: #5308

Adds a target directory parameter, that acts in the same manner as the environment variable `CARGO_TARGET_DIR`, to the following subcommands:
- `bench`
- `build`
- `check`
- `clean`
- `doc`
- `package`
- `publish`
- `run`
- `rustc`
- `rustdoc`
- `test`
@bors
Copy link
Collaborator

bors commented Apr 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: matklad
Pushing 7debd81 to master...

@bors bors merged commit 0b530c3 into rust-lang:master Apr 24, 2018
@smithsps
Copy link
Contributor Author

@matklad Thanks for the mentoring, it was a great learning experience!

nrc added a commit to nrc/cargo that referenced this pull request May 3, 2018
Commit 0b530c3 (which this commit mostly reverts) did some refactoring around the `target_dir` function. However, it introduced a bug because it meant that where `CARGO_TARGET_DIR` was specified but `--target-dir` was not, the value from `CARGO_TARGET_DIR` was ignored.
@PSeitz
Copy link
Contributor

PSeitz commented Jun 22, 2018

was install left out intentionally?

@ignatenkobrain
Copy link
Contributor

I miss commandline option for cargo too.

@cuviper
Copy link
Member

cuviper commented Jun 22, 2018

I think install deserves an option too, but it could be confusing that install --target-dir DIR would specify the build target path, versus the installation path (which is --root).

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

Successfully merging this pull request may close these issues.

None yet

8 participants