Skip to content

Commit

Permalink
Fix --manifest-path to point to Cargo.toml instead of a directory (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
MarijnS95 authored Mar 29, 2022
1 parent 28f5e91 commit 5c451c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum Error {
InvalidArgs,
ManifestNotFound,
RustcNotFound,
ManifestPathNotFound,
GlobPatternError(&'static str),
Glob(GlobError),
Io(PathBuf, IoError),
Expand All @@ -20,6 +21,7 @@ impl Display for Error {
f.write_str(match self {
Self::InvalidArgs => "Invalid args.",
Self::ManifestNotFound => "Didn't find Cargo.toml.",
Self::ManifestPathNotFound => "The manifest-path must be a path to a Cargo.toml file",
Self::RustcNotFound => "Didn't find rustc.",
Self::GlobPatternError(error) => error,
Self::Glob(error) => return error.fmt(f),
Expand Down
19 changes: 15 additions & 4 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::artifact::{Artifact, CrateType};
use crate::error::Error;
use crate::profile::Profile;
use crate::{utils, LocalizedConfig};
use std::ffi::OsStr;
use std::io::BufRead;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -34,11 +35,21 @@ impl Subcommand {
args.exclude.is_empty(),
"`--exclude` is not supported yet by `cargo-subcommand`"
);

let manifest_path = args
.manifest_path
.clone()
.map(|path| {
if path.file_name() != Some(OsStr::new("Cargo.toml")) || !path.is_file() {
Err(Error::ManifestPathNotFound)
} else {
Ok(path)
}
})
.transpose()?;

let (manifest_path, package) = utils::find_package(
&args
.manifest_path
.clone()
.unwrap_or_else(|| std::env::current_dir().unwrap()),
&manifest_path.unwrap_or_else(|| std::env::current_dir().unwrap()),
args.package.get(0).map(|s| s.as_str()),
)?;
let root_dir = manifest_path.parent().unwrap();
Expand Down

0 comments on commit 5c451c0

Please sign in to comment.