Skip to content

Commit 5c451c0

Browse files
authored
Fix --manifest-path to point to Cargo.toml instead of a directory (#20)
Currently `cargo-subcommand` expects this argument to be a path to the directory containing project(s), whereas it should actually point to a file specifically named `Cargo.toml`. Note that this path doesn't appear to be very strict in `cargo`: even if pointing to a manifest file within a workspace, packages in the surrounding workspace are still built, and are reachable through `-p`. However, there's a strict requirement on the specified manifest to be part of the workspace, which is not enforced in `cargo-subcommand` yet.
1 parent 28f5e91 commit 5c451c0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub enum Error {
99
InvalidArgs,
1010
ManifestNotFound,
1111
RustcNotFound,
12+
ManifestPathNotFound,
1213
GlobPatternError(&'static str),
1314
Glob(GlobError),
1415
Io(PathBuf, IoError),
@@ -20,6 +21,7 @@ impl Display for Error {
2021
f.write_str(match self {
2122
Self::InvalidArgs => "Invalid args.",
2223
Self::ManifestNotFound => "Didn't find Cargo.toml.",
24+
Self::ManifestPathNotFound => "The manifest-path must be a path to a Cargo.toml file",
2325
Self::RustcNotFound => "Didn't find rustc.",
2426
Self::GlobPatternError(error) => error,
2527
Self::Glob(error) => return error.fmt(f),

src/subcommand.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::artifact::{Artifact, CrateType};
33
use crate::error::Error;
44
use crate::profile::Profile;
55
use crate::{utils, LocalizedConfig};
6+
use std::ffi::OsStr;
67
use std::io::BufRead;
78
use std::path::{Path, PathBuf};
89
use std::process::Command;
@@ -34,11 +35,21 @@ impl Subcommand {
3435
args.exclude.is_empty(),
3536
"`--exclude` is not supported yet by `cargo-subcommand`"
3637
);
38+
39+
let manifest_path = args
40+
.manifest_path
41+
.clone()
42+
.map(|path| {
43+
if path.file_name() != Some(OsStr::new("Cargo.toml")) || !path.is_file() {
44+
Err(Error::ManifestPathNotFound)
45+
} else {
46+
Ok(path)
47+
}
48+
})
49+
.transpose()?;
50+
3751
let (manifest_path, package) = utils::find_package(
38-
&args
39-
.manifest_path
40-
.clone()
41-
.unwrap_or_else(|| std::env::current_dir().unwrap()),
52+
&manifest_path.unwrap_or_else(|| std::env::current_dir().unwrap()),
4253
args.package.get(0).map(|s| s.as_str()),
4354
)?;
4455
let root_dir = manifest_path.parent().unwrap();

0 commit comments

Comments
 (0)