Skip to content

Commit 43e3de3

Browse files
committed
Fix workspace manifest path detection and release 2.0.2
Backport of: 444cbcc
1 parent 555274d commit 43e3de3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "proc-macro-crate"
3-
version = "2.0.1"
3+
version = "2.0.2"
44
authors = ["Bastian Köcher <[email protected]>"]
55
edition = "2021"
66
categories = ["development-tools::procedural-macro-helpers"]

src/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ pub fn crate_name(orig_name: &str) -> Result<FoundCrate, Error> {
213213
&cache_entry.crate_names
214214
},
215215
btree_map::Entry::Vacant(entry) => {
216-
let workspace_manifest_path = workspace_manifest_path(&manifest_path)?;
216+
// If `workspace_manifest_path` returns `None`, we are probably in a vendored deps
217+
// folder and cargo complaining that we have some package inside a workspace, that isn't
218+
// part of the workspace. In this case we just use the `manifest_path` as the
219+
// `workspace_manifest_path`.
220+
let workspace_manifest_path =
221+
workspace_manifest_path(&manifest_path)?.unwrap_or_else(|| manifest_path.clone());
217222
let workspace_manifest_ts = cargo_toml_timestamp(&workspace_manifest_path)?;
218223

219224
let cache_entry = entry.insert(read_cargo_toml(
@@ -235,7 +240,7 @@ pub fn crate_name(orig_name: &str) -> Result<FoundCrate, Error> {
235240
.clone())
236241
}
237242

238-
fn workspace_manifest_path(cargo_toml_manifest: &Path) -> Result<PathBuf, Error> {
243+
fn workspace_manifest_path(cargo_toml_manifest: &Path) -> Result<Option<PathBuf>, Error> {
239244
let stdout = Command::new(env::var("CARGO").map_err(|_| Error::CargoEnvVariableNotSet)?)
240245
.arg("locate-project")
241246
.args(&["--workspace", "--message-format=plain"])
@@ -246,7 +251,15 @@ fn workspace_manifest_path(cargo_toml_manifest: &Path) -> Result<PathBuf, Error>
246251

247252
String::from_utf8(stdout)
248253
.map_err(|_| Error::FailedGettingWorkspaceManifestPath)
249-
.map(|s| s.trim().into())
254+
.map(|s| {
255+
let path = s.trim();
256+
257+
if path.is_empty() {
258+
None
259+
} else {
260+
Some(path.into())
261+
}
262+
})
250263
}
251264

252265
fn cargo_toml_timestamp(manifest_path: &Path) -> Result<SystemTime, Error> {

0 commit comments

Comments
 (0)