Skip to content

Lock RO #10716

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

Closed
wants to merge 4 commits into from
Closed

Lock RO #10716

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benches/benchsuite/benches/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn make_config(ws_root: &Path) -> Config {
false,
false,
false,
false,
&Some(target_dir()),
&[],
&[],
Expand Down
2 changes: 2 additions & 0 deletions crates/resolver-tests/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ proptest! {
false,
false,
false,
false,
&None,
&["minimal-versions".to_string()],
&[],
Expand Down Expand Up @@ -576,6 +577,7 @@ fn test_resolving_minimum_version_with_transitive_deps() {
false,
false,
false,
false,
&None,
&["minimal-versions".to_string()],
&[],
Expand Down
5 changes: 5 additions & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ fn config_configure(
let color = args.value_of("color").or_else(|| global_color.as_deref());
let frozen = args.is_present("frozen") || global_args.frozen;
let locked = args.is_present("locked") || global_args.locked;
let lock_ro = args.is_present("lock-ro") || global_args.lock_ro;
let offline = args.is_present("offline") || global_args.offline;
let mut unstable_flags = global_args.unstable_flags;
if let Some(values) = args.values_of("unstable-features") {
Expand All @@ -356,6 +357,7 @@ fn config_configure(
color,
frozen,
locked,
lock_ro,
offline,
arg_target_dir,
&unstable_flags,
Expand All @@ -381,6 +383,7 @@ struct GlobalArgs {
color: Option<String>,
frozen: bool,
locked: bool,
lock_ro: bool,
offline: bool,
unstable_flags: Vec<String>,
config_args: Vec<String>,
Expand All @@ -394,6 +397,7 @@ impl GlobalArgs {
color: args.value_of("color").map(|s| s.to_string()),
frozen: args.is_present("frozen"),
locked: args.is_present("locked"),
lock_ro: args.is_present("lock-ro"),
offline: args.is_present("offline"),
unstable_flags: args
.values_of_lossy("unstable-features")
Expand Down Expand Up @@ -470,6 +474,7 @@ See 'cargo help <command>' for more information on a specific command.\n",
)
.arg(opt("frozen", "Require Cargo.lock and cache are up to date").global(true))
.arg(opt("locked", "Require Cargo.lock is up to date").global(true))
.arg(opt("lock-ro", "Assume Cargo.lock is read only").global(true))
.arg(opt("offline", "Run without accessing the network").global(true))
.arg(
multi_opt(
Expand Down
9 changes: 9 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub struct Workspace<'cfg> {

/// Workspace-level custom metadata
custom_metadata: Option<toml::Value>,

// If `true`, then the resolver will not write to `Cargo.lock` files.
// This is set by the `--lock-ro` command line flag.
is_prevent_lock_write: bool,
}

// Separate structure for tracking loaded packages (to avoid loading anything
Expand Down Expand Up @@ -197,6 +201,7 @@ impl<'cfg> Workspace<'cfg> {
ignore_lock: false,
resolve_behavior: ResolveBehavior::V1,
custom_metadata: None,
is_prevent_lock_write: config.lock_ro(),
}
}

Expand Down Expand Up @@ -562,6 +567,10 @@ impl<'cfg> Workspace<'cfg> {
self.custom_metadata.as_ref()
}

pub fn is_prevent_lock_write(&self) -> bool {
self.is_prevent_lock_write
}

pub fn load_workspace_config(&mut self) -> CargoResult<Option<WorkspaceRootConfig>> {
// If we didn't find a root, it must mean there is no [workspace] section, and thus no
// metadata.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn resolve_with_registry<'cfg>(
true,
)?;

if !ws.is_ephemeral() && ws.require_optional_deps() {
if !ws.is_ephemeral() && ws.require_optional_deps() && !ws.is_prevent_lock_write() {
ops::write_pkg_lockfile(ws, &mut resolve)?;
}
Ok(resolve)
Expand Down
11 changes: 11 additions & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ pub struct Config {
/// `locked` is set if we should not update lock files. If the lock file
/// is missing, or needs to be updated, an error is produced.
locked: bool,
/// `lock_ro` is set if we should not update lock files. It behaves like
/// `locked`, but does not produce an error and silently discards lock
/// file changes. Intended for read-only file systems.
lock_ro: bool,
/// `offline` is set if we should never access the network, but otherwise
/// continue operating if possible.
offline: bool,
Expand Down Expand Up @@ -257,6 +261,7 @@ impl Config {
extra_verbose: false,
frozen: false,
locked: false,
lock_ro: false,
offline: false,
jobserver: unsafe {
if GLOBAL_JOBSERVER.is_null() {
Expand Down Expand Up @@ -875,6 +880,7 @@ impl Config {
color: Option<&str>,
frozen: bool,
locked: bool,
lock_ro: bool,
offline: bool,
target_dir: &Option<PathBuf>,
unstable_flags: &[String],
Expand Down Expand Up @@ -938,6 +944,7 @@ impl Config {
self.extra_verbose = extra_verbose;
self.frozen = frozen;
self.locked = locked;
self.lock_ro = lock_ro;
self.offline = offline
|| self
.net_config()
Expand Down Expand Up @@ -994,6 +1001,10 @@ impl Config {
self.locked
}

pub fn lock_ro(&self) -> bool {
self.lock_ro
}

pub fn lock_update_allowed(&self) -> bool {
!self.frozen && !self.locked
}
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-clean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-fetch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-generate-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-package.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-pkgid.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-publish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-rustdoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ OPTIONS
Cargo.lock file is up-to-date (such as a CI build) or want to avoid
network access.

--lock-ro
Prevents Cargo from updating the Cargo.lock file. Unlike the
--frozen and --locked flags, this flag does not produce an error
when the lock file needs to be updated. Instead, the lock file
update is transparently discarded. This is intended to allow Cargo
to handle read only file systems.

--offline
Prevents Cargo from accessing the network for any reason. Without
this flag, Cargo will stop with an error if it needs to access the
Expand Down
Loading