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

feat: make package, manifest and virtualManfest sync by using Arc not Rc #14837

Closed
wants to merge 6 commits into from
Closed
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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ cargo-credential-macos-keychain.workspace = true

[target.'cfg(not(windows))'.dependencies]
openssl = { workspace = true, optional = true }
openssl-sys = { workspace = true, optional = true } # HACK: for pinning to openssl v1.

[target.'cfg(windows)'.dependencies]
cargo-credential-wincred.workspace = true
Expand Down
33 changes: 16 additions & 17 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;

use anyhow::Context as _;
Expand Down Expand Up @@ -62,10 +61,10 @@ impl EitherManifest {
#[derive(Clone, Debug)]
pub struct Manifest {
// alternate forms of manifests:
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,
summary: Summary,

// this form of manifest:
Expand Down Expand Up @@ -108,10 +107,10 @@ pub struct Warnings(Vec<DelayedWarning>);
#[derive(Clone, Debug)]
pub struct VirtualManifest {
// alternate forms of manifests:
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,

// this form of manifest:
replace: Vec<(PackageIdSpec, Dependency)>,
Expand Down Expand Up @@ -484,10 +483,10 @@ compact_debug! {

impl Manifest {
pub fn new(
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,
summary: Summary,

default_kind: Option<CompileKind>,
Expand Down Expand Up @@ -726,10 +725,10 @@ impl Manifest {

impl VirtualManifest {
pub fn new(
contents: Rc<String>,
document: Rc<toml_edit::ImDocument<String>>,
original_toml: Rc<TomlManifest>,
normalized_toml: Rc<TomlManifest>,
contents: Arc<String>,
document: Arc<toml_edit::ImDocument<String>>,
original_toml: Arc<TomlManifest>,
normalized_toml: Arc<TomlManifest>,
replace: Vec<(PackageIdSpec, Dependency)>,
patch: HashMap<Url, Vec<Dependency>>,
workspace: WorkspaceConfig,
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;
use std::hash;
use std::mem;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
use std::time::{Duration, Instant};

use anyhow::Context as _;
Expand Down Expand Up @@ -42,7 +42,7 @@ use crate::util::{self, internal, GlobalContext, Progress, ProgressStyle};
/// A package is a `Cargo.toml` file plus all the files that are part of it.
#[derive(Clone)]
pub struct Package {
inner: Rc<PackageInner>,
inner: Arc<PackageInner>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Package {
/// Creates a package from a manifest and its location.
pub fn new(manifest: Manifest, manifest_path: &Path) -> Package {
Package {
inner: Rc::new(PackageInner {
inner: Arc::new(PackageInner {
manifest,
manifest_path: manifest_path.to_path_buf(),
}),
Expand All @@ -118,7 +118,7 @@ impl Package {
}
/// Gets the manifest.
pub fn manifest_mut(&mut self) -> &mut Manifest {
&mut Rc::make_mut(&mut self.inner).manifest
&mut Arc::make_mut(&mut self.inner).manifest
}
/// Gets the path to the manifest.
pub fn manifest_path(&self) -> &Path {
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Package {

pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Package {
Package {
inner: Rc::new(PackageInner {
inner: Arc::new(PackageInner {
manifest: self.manifest().clone().map_source(to_replace, replace_with),
manifest_path: self.manifest_path().to_owned(),
}),
Expand Down
23 changes: 12 additions & 11 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str::{self, FromStr};
use std::sync::Arc;

use crate::core::summary::MissingDependencyError;
use crate::AlreadyPrintedError;
Expand Down Expand Up @@ -45,9 +45,10 @@ pub use embedded::ScriptSource;
/// See also `bin/cargo/commands/run.rs`s `is_manifest_command`
pub fn is_embedded(path: &Path) -> bool {
let ext = path.extension();
ext == Some(OsStr::new("rs")) ||
(ext == Some(OsStr::new("rs")) ||
// Provide better errors by not considering directories to be embedded manifests
(ext.is_none() && path.is_file())
ext.is_none())
&& path.is_file()
}

/// Loads a `Cargo.toml` from a file on disk.
Expand Down Expand Up @@ -1750,10 +1751,10 @@ pub fn to_real_manifest(
let default_run = normalized_package.default_run.clone();
let metabuild = normalized_package.metabuild.clone().map(|sov| sov.0);
let manifest = Manifest::new(
Rc::new(contents),
Rc::new(document),
Rc::new(original_toml),
Rc::new(normalized_toml),
Arc::new(contents),
Arc::new(document),
Arc::new(original_toml),
Arc::new(normalized_toml),
summary,
default_kind,
forced_kind,
Expand Down Expand Up @@ -1929,10 +1930,10 @@ fn to_virtual_manifest(
bail!("virtual manifests must be configured with [workspace]");
}
let manifest = VirtualManifest::new(
Rc::new(contents),
Rc::new(document),
Rc::new(original_toml),
Rc::new(normalized_toml),
Arc::new(contents),
Arc::new(document),
Arc::new(original_toml),
Arc::new(normalized_toml),
replace,
patch,
workspace_config,
Expand Down
16 changes: 2 additions & 14 deletions tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,16 +2004,7 @@ fn compatible_with_older_cargo() {
assert_eq!(get_registry_names("src"), ["middle-1.0.0", "new-1.0.0"]);
assert_eq!(
get_registry_names("cache"),
// Duplicate crates from two different cache location
// because we're changing how SourceId is hashed.
// This change should be reverted once rust-lang/cargo#14917 lands.
[
"middle-1.0.0.crate",
"middle-1.0.0.crate",
"new-1.0.0.crate",
"new-1.0.0.crate",
"old-1.0.0.crate"
]
["middle-1.0.0.crate", "new-1.0.0.crate", "old-1.0.0.crate"]
);

// T-0 months: Current version, make sure it can read data from stable,
Expand All @@ -2036,10 +2027,7 @@ fn compatible_with_older_cargo() {
assert_eq!(get_registry_names("src"), ["new-1.0.0"]);
assert_eq!(
get_registry_names("cache"),
// Duplicate crates from two different cache location
// because we're changing how SourceId is hashed.
// This change should be reverted once rust-lang/cargo#14917 lands.
["middle-1.0.0.crate", "new-1.0.0.crate", "new-1.0.0.crate"]
["middle-1.0.0.crate", "new-1.0.0.crate"]
);
}

Expand Down
72 changes: 72 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6430,6 +6430,78 @@ fn workspace_with_local_and_remote_deps() {
.run();
}

#[cargo_test]
fn workspace_with_dot_rs_dir() {
let reg = registry::init();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["crates/*"]
"#,
)
.file(
"crates/foo.rs/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.16.2"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"

[dependencies]
"#,
)
.file("crates/foo.rs/src/lib.rs", "pub fn foo() {}")
.file(
"crates/bar.rs/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.16.2"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"

[dependencies]
foo = { path = "../foo.rs", version = "0.16.2" }
"#,
)
.file("crates/bar.rs/src/lib.rs", "pub fn foo() {}")
.build();

p.cargo("package -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.replace_crates_io(reg.index_url())
.with_stderr_data(
str![[r#"
[PACKAGING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs)
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs)
[UPDATING] crates.io index
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[VERIFYING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs)
[COMPILING] foo v0.16.2 ([ROOT]/foo/target/package/foo-0.16.2)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[VERIFYING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs)
[UNPACKING] foo v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
[COMPILING] foo v0.16.2
[COMPILING] bar v0.16.2 ([ROOT]/foo/target/package/bar-0.16.2)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
.unordered(),
)
.run();
}

#[cargo_test]
fn registry_not_in_publish_list() {
let p = project()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ fn cmd_check_with_missing_script_rs() {
.with_status(101)
.with_stdout_data("")
.with_stderr_data(str![[r#"
[ERROR] manifest path `script.rs` does not exist
[ERROR] the manifest-path must be a path to a Cargo.toml file

"#]])
.run();
Expand Down