fn rewrite_cargo_toml(
    manifest_path: impl AsRef<Path>,
    known_path_deps: &HashMap<&String, &PathBuf>,
    is_path_dep: bool,
) -> Result<String> {
    let text = fs::read_to_string(&manifest_path).context(format!(
        "Can't read Cargo.toml at {}",
        manifest_path.as_ref().display(),
    ))?;
    let mut data = text.parse::<toml_edit::Document>().context(format!(
        "Failed to parse Cargo.toml at {}",
        manifest_path.as_ref().display()
    ))?;
    //  ˇˇˇˇˇˇˇˇˇˇˇˇ dep_category
    // [dependencies]
    // some_path_dep = { path = "../some_path_dep" }
    //                          ^^^^^^^^^^^^^^^^^^ table[&dep_name]["path"]
    // ^^^^^^^^^^^^^ dep_name
    for dep_category in &["dependencies", "dev-dependencies", "build-dependencies"] {
        if let Some(table) = data[&dep_category].as_table_mut() {
            let dep_names: Vec<_> = table.iter().map(|(key, _)| key.to_string()).collect();
            for dep_name in dep_names {
                // There should either be no value for path, or it should be a string
                if table[&dep_name]["path"].is_none() {
                    continue;
                }
                if !table[&dep_name]["path"].is_str() {
                    bail!(
                        "In {}, {} {} has a path value that is not a string",
                        manifest_path.as_ref().display(),
                        dep_category,
                        dep_name
                    )
                }
                // This is the location of the targeted crate in the source distribution
                table[&dep_name]["path"] = toml_edit::value(if is_path_dep {
                    format!("../{}", dep_name)
                } else {
                    format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name)
                });
                if !known_path_deps.contains_key(&dep_name) {
                    bail!(
                        "cargo metadata does not know about the path for {} {} present in {}, which should never happen ಠ_ಠ",
                        dep_category, dep_name, manifest_path.as_ref().display()
                    );
                }
            }
        }
    }
    Ok(data.to_string_in_original_order())
}
/// We need cargo to load the local dependencies from the location where we put them in the source
/// distribution. Since there is no cargo-backed way to replace dependencies
/// (see https://github.com/rust-lang/cargo/issues/9170), we do a simple
/// Cargo.toml rewrite ourselves.
/// A big chunk of that (including toml_edit) comes from cargo edit, and esp.
/// https://github.com/killercup/cargo-edit/blob/2a08f0311bcb61690d71d39cb9e55e69b256c8e1/src/manifest.rs
/// This method is rather frail, but unfortunately I don't know a better solution.
We need cargo to load the local dependencies from the location where we put them in the source
distribution. Since there is no cargo-backed way to replace dependencies
, we do a simple
Cargo.toml rewrite ourselves.
A big chunk of that (including toml_edit) comes from cargo edit, and esp.
We need cargo to load the local dependencies from the location where we put them in the source distribution . Since there is no cargo - backed way to replace dependencies we do a simple Cargo . toml rewrite ourselves . A big chunk of that ( including toml_edit ) comes from cargo edit and esp .
fn rewrite_cargo_toml(
    manifest_path: impl AsRef<Path>,
    known_path_deps: &HashMap<&String, &PathBuf>,
    is_path_dep: bool,
) -> Result<String> {
    let text = fs::read_to_string(&manifest_path).context(format!(
        "Can't read Cargo.toml at {}",
        manifest_path.as_ref().display(),
    ))?;
    let mut data = text.parse::<toml_edit::Document>().context(format!(
        "Failed to parse Cargo.toml at {}",
        manifest_path.as_ref().display()
    ))?;
    //  ˇˇˇˇˇˇˇˇˇˇˇˇ dep_category
    // [dependencies]
    // some_path_dep = { path = "../some_path_dep" }
    //                          ^^^^^^^^^^^^^^^^^^ table[&dep_name]["path"]
    // ^^^^^^^^^^^^^ dep_name
    for dep_category in &["dependencies", "dev-dependencies", "build-dependencies"] {
        if let Some(table) = data[&dep_category].as_table_mut() {
            let dep_names: Vec<_> = table.iter().map(|(key, _)| key.to_string()).collect();
            for dep_name in dep_names {
                // There should either be no value for path, or it should be a string
                if table[&dep_name]["path"].is_none() {
                    continue;
                }
                if !table[&dep_name]["path"].is_str() {
                    bail!(
                        "In {}, {} {} has a path value that is not a string",
                        manifest_path.as_ref().display(),
                        dep_category,
                        dep_name
                    )
                }
                // This is the location of the targeted crate in the source distribution
                table[&dep_name]["path"] = toml_edit::value(if is_path_dep {
                    format!("../{}", dep_name)
                } else {
                    format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name)
                });
                if !known_path_deps.contains_key(&dep_name) {
                    bail!(
                        "cargo metadata does not know about the path for {} {} present in {}, which should never happen ಠ_ಠ",
                        dep_category, dep_name, manifest_path.as_ref().display()
                    );
                }
            }
        }
    }
    Ok(data.to_string_in_original_order())
}
fn rewrite_cargo_toml ( manifest_path : impl AsRef < Path > , known_path_deps : & HashMap < & String , & PathBuf > , is_path_dep : bool , ) -> Result < String > { let text = fs :: read_to_string ( & manifest_path ) . context ( format ! ( " " manifest_path as_ref ( ) display ( ) ) ) ? ; let mut data = text . parse :: < toml_edit :: Document > ( ) . context ( format ! ( " " manifest_path as_ref ( ) display ( ) ) ) ? ; //  ˇˇˇˇˇˇˇˇˇˇˇˇ dep_category // [dependencies] // some_path_dep = { path = "../some_path_dep" } //                          ^^^^^^^^^^^^^^^^^^ table[&dep_name]["path"] // ^^^^^^^^^^^^^ dep_name for dep_category in & [ " " , " " , " " ] { if let Some ( table ) = data [ & dep_category ] . as_table_mut ( ) { let dep_names : Vec < _ > = table . iter ( ) . map ( | ( key , _ ) | key . to_string ( ) ) . collect ( ) ; for dep_name in dep_names { // There should either be no value for path, or it should be a string if table [ & dep_name ] [ " " ] . is_none ( ) { continue ; } if ! table [ & dep_name ] [ " " ] . is_str ( ) { bail ! ( " " manifest_path as_ref ( ) display ( ) dep_category dep_name ) } // This is the location of the targeted crate in the source distribution table [ & dep_name ] [ " " ] = toml_edit :: value ( if is_path_dep { format ! ( " " dep_name ) } else { format ! ( " " LOCAL_DEPENDENCIES_FOLDER dep_name ) } ) ; if ! known_path_deps . contains_key ( & dep_name ) { bail ! ( " dep_category dep_name manifest_path as_ref ( ) display ( ) ) ; } } } } Ok ( data . to_string_in_original_order ( ) ) }
We need cargo to load the local dependencies from the location where we put them in the source
distribution.
We need cargo to load the local dependencies from the location where we put them in the source distribution .
manifest_path
impl AsRef<Path>
known_path_deps
&HashMap<&String, &PathBuf>
is_path_dep
bool
manifest_path
impl AsRef<Path>
known_path_deps
&HashMap<&String, &PathBuf>
is_path_dep
bool