Skip to content

Manifest::new() doesn't work with relative manifest path #7596

@magmast

Description

@magmast

Problem

I'm using cargo as dependency in my project. The function Workspace::new used with relative manifest_path does return error with message invalid path url `` . The same code, but using absolute manifest_path is working correctly.

Steps

  1. Create project and add cargo as a dependency
  2. Try to load workspace using relative manifest_path

Possible Solution(s)

If it's expected behavior it should be mentioned in documentation. Otherwise Workspace::new could transform relative path to absolute before using it.

Notes

Output of cargo version: dependency is defined like that cargo = "0.40".

Example code that isn't working:

use cargo::core::Workspace;
use cargo::Config;

fn main() {
    let manifest_path = "Cargo.toml";
    let config = Config::default().unwrap();
    let workspace = Workspace::new(manifest_path.as_ref(), &config).unwrap();

    for member in workspace.members() {
        println!("{}", member.name());
    }
}

Example of working code:

use cargo::core::Workspace;
use cargo::Config;

use std::env;

fn main() {
    let manifest_path = env::current_dir().unwrap().join("Cargo.toml");
    let config = Config::default().unwrap();
    let workspace = Workspace::new(&manifest_path, &config).unwrap();

    for member in workspace.members() {
        println!("{}", member.name());
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargo-apiArea: cargo-the-library API and internal code issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions