Skip to content

Commit 2a0bb65

Browse files
committed
Switch SerializedTarget::src_path to None instead of using fake path.
1 parent 9a7fadf commit 2a0bb65

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/cargo/core/manifest.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ struct SerializedTarget<'a> {
268268
/// See https://doc.rust-lang.org/reference/linkage.html
269269
crate_types: Vec<&'a str>,
270270
name: &'a str,
271-
src_path: &'a PathBuf,
271+
src_path: Option<&'a PathBuf>,
272272
edition: &'a str,
273273
#[serde(rename = "required-features", skip_serializing_if = "Option::is_none")]
274274
required_features: Option<Vec<&'a str>>,
@@ -277,17 +277,16 @@ struct SerializedTarget<'a> {
277277
impl ser::Serialize for Target {
278278
fn serialize<S: ser::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
279279
let src_path = match &self.src_path {
280-
TargetSourcePath::Path(p) => p.to_path_buf(),
281-
// This is a lie, to avoid changing the format of SerializedTarget.
282-
// The target dir is unknown here, so the path cannot be determined.
283-
// A better solution eludes me at this time.
284-
TargetSourcePath::Metabuild => PathBuf::from("metabuild.rs"),
280+
TargetSourcePath::Path(p) => Some(p),
281+
// Unfortunately getting the correct path would require access to
282+
// target_dir, which is not available here.
283+
TargetSourcePath::Metabuild => None,
285284
};
286285
SerializedTarget {
287286
kind: &self.kind,
288287
crate_types: self.rustc_crate_types(),
289288
name: &self.name,
290-
src_path: &src_path,
289+
src_path: src_path,
291290
edition: &self.edition.to_string(),
292291
required_features: self
293292
.required_features

tests/testsuite/metabuild.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ fn metabuild_failed_build_json() {
767767
"custom-build"
768768
],
769769
"name": "metabuild-foo",
770-
"src_path": "metabuild.rs"
770+
"src_path": null
771771
}
772772
}
773773
"#,

0 commit comments

Comments
 (0)