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

RFE: add option to specify path to Cargo.lock #5707

Closed
ignatenkobrain opened this issue Jul 11, 2018 · 11 comments · Fixed by #14417
Closed

RFE: add option to specify path to Cargo.lock #5707

ignatenkobrain opened this issue Jul 11, 2018 · 11 comments · Fixed by #14417
Assignees
Labels
A-lockfile Area: Cargo.lock issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@ignatenkobrain
Copy link
Contributor

ignatenkobrain commented Jul 11, 2018

In Fedora we package all crate sources (including tests) in /usr/share/cargo/registry which is not user-writable. However, we would like to run tests for them after installation. There is already option for target-dir and it would be very nice to get option to put Cargo.lock in some other directory so that we could run cargo test from there.

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jul 11, 2018
@ignatenkobrain
Copy link
Contributor Author

@alexcrichton any idea how the option could be named? I'm thinking about making a patch.

@alexcrichton
Copy link
Member

Perhaps --lockfile-path to mirror --manifest-path?

@ehuss ehuss added the A-lockfile Area: Cargo.lock issues label Apr 6, 2020
@weihanglo weihanglo added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label May 10, 2023
@epage epage added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. labels Jul 16, 2024
@epage
Copy link
Contributor

epage commented Jul 16, 2024

We talked about this in the Cargo team meeting and are open to people experimenting with this

  • CLI flag only, no config, no manifest support
  • Name: --lockfile-path <path>
  • Behind -Zunstable-options and docs
    • The flag's docs / --help should have (unstable) in them
  • Looks like it belongs on all commands that take --manifest-path except cargo locate-project
  • cargo install should make --lockfile-path imply --locked
  • Must require the file_name be Cargo.lock (like we do for --manifest-path). We can always re-evaluate this in the future
  • Main question is how this should work if the lockfile or a parent directory is not present
    • I would lean towards "create them" rather than "error"

@Ifropc
Copy link
Contributor

Ifropc commented Jul 16, 2024

@rustbot claim

@Ifropc
Copy link
Contributor

Ifropc commented Jul 31, 2024

@epage sorry it took me some time, but the PR is ready for review.
I followed the guideline you posted in your comment (thank you very much!)
1 slight difference is I haven't added --lockfile-path on cargo install yet, as it's not one of the command that takes the --manifest-path.
I think the main usage of the lockfile-path is to enable folks to run commands on readonly folders (and adding it to almost all --manifest-path commands for consistency is a good idea). However, cargo install doesn't really fit into this category, so I doubt there's going to be any demand for that.
That being sad, adding it is very easy (and to be completely honest I just completely missed your suggestion up until I opened the PR), so if you think it'd be a nice addition it's not a problem to add it to the set of supported commands.

@weihanglo
Copy link
Member

@Ifropc No worry. As --lockfile-path is not going to be insta-stable, that seems fine to me. We can always discuss use cases later.

bors added a commit that referenced this issue Aug 16, 2024
Add `--lockfile-path` flag

This change implements a new `--lockfile-path` proposed in #5707 .

Functionality added:
- Add `--lockfile-path <PATH>` to all commands that support `manifest-path` with exception of:
   - `locate-project` (doesn't use lock file)
   - `verify-project` (is deprecated)
   - `read-manifest` (doesn't use lock file)
- Behind -Zunstable-options and docs
   - The flag's docs / `--help` has (unstable) in them
- `<PATH>` must end with `Cargo.lock`. If specified path doesn't exist (or parent director(ies), create all the parent directories and the lockfile itself

Implementation TLDR: add `requested_lockfile_path` into `Workspace` and set it on `workspace(gctx)` call (setting from the context)
Update `lockfile.lock_root()` to respect `requested_lockfile_path` (if set)
Add test cases covering all affected commands. Tested creating lockfile, reading lockfile, overriding default (`./Cargo.lock`) lockfile, symlink tests. Extra tests for package to make sure pinned versions from path's lockfile are respected (i.e. double check correct lockfile is used)
I doubt this flag will be used for any command that's not read-only, but I tried to cover all the commands.
@weihanglo
Copy link
Member

weihanglo commented Aug 16, 2024

Most major tasks in #5707 (comment) were addressed via #14326. Below are remaining tasks:

Open questions before stabilization

  • How this should work if the lockfile or a parent directory is not present
    • In #14326, missing parent directories will be created when Cargo is about to write the lockfile. This minimizes the chance of creating dangling directories.

@epage
Copy link
Contributor

epage commented Aug 16, 2024

Main question is how this should work if the lockfile or a parent directory is not present

Personally, I wouldn't make a checkbox for that. That is enough of an open question that it should be carried forward to stabilization with a call out of what was chosen for the implementation.

May have conflicts with the GSoC shell completion project.

We should not be blocking completion work on that effort. We'll likely have that start as a nightly-only opt-in so we can do acceptance testing on it.

@Ifropc
Copy link
Contributor

Ifropc commented Aug 16, 2024

Thanks for your reviews! I will do the follow ups for cargo install (sorry actually just forgot about it 😅 ) and tests in separate PRs.
As for GSoC shell completion, from my understanding it's an ongoing effort, as of now. I don't see why would it be conflicting with the new flag, but if any help needed I would be happy to be involved!

@epage
Copy link
Contributor

epage commented Aug 16, 2024

As for GSoC shell completion, from my understanding it's an ongoing effort, as of now. I don't see why would it be conflicting with the new flag, but if any help needed I would be happy to be involved!

I believe the intent was to call out the potential for it being throwaway work which it would be if it was close to being merged and stabilized. However, we do not know how close we are to stabilization until we merge and do a couple rounds of call-for-testing, so any completion work that is pending should still be done.

@weihanglo weihanglo linked a pull request Aug 18, 2024 that will close this issue
@weihanglo
Copy link
Member

Close in favor of the tracking issue #14421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lockfile Area: Cargo.lock issues C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants