Skip to content

Commit

Permalink
Support facebook's cinder.3.8 Python fork (#631)
Browse files Browse the repository at this point in the history
* Capture build metadata in version struct

Also include the build metada in the version struct.

* Support facebook's cinder.3.8 Python fork

Facebook's cinder.3.8 Python fork uses a different offset for the
current tstate.  Use the buildmetadata to detect and special case this
(https://github.com/facebookincubator/cinder/blob/cinder/3.8/Include/patchlevel.h#L26).
  • Loading branch information
andrewjcg authored Nov 10, 2023
1 parent 4e69e83 commit bb0e7e8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/coredump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ mod test {
minor: 9,
patch: 13,
release_flags: "".to_owned(),
build_metadata: None,
};
let python_core = PythonCoreDump {
core,
Expand Down
5 changes: 4 additions & 1 deletion src/python_bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ pub mod pyruntime {
},
Version {
major: 3, minor: 8, ..
} => Some(1368),
} => match version.build_metadata.as_deref() {
Some("cinder") => Some(1384),
_ => Some(1368),
},
Version {
major: 3,
minor: 9..=10,
Expand Down
1 change: 1 addition & 0 deletions src/python_process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ where
minor,
patch: 0,
release_flags: "".to_owned(),
build_metadata: None,
});
}
}
Expand Down
46 changes: 38 additions & 8 deletions src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Version {
pub minor: u64,
pub patch: u64,
pub release_flags: String,
pub build_metadata: Option<String>,
}

impl Version {
Expand All @@ -28,6 +29,11 @@ impl Version {
let major = std::str::from_utf8(&cap[2])?.parse::<u64>()?;
let minor = std::str::from_utf8(&cap[3])?.parse::<u64>()?;
let patch = std::str::from_utf8(&cap[4])?.parse::<u64>()?;
let build_metadata = if let Some(s) = cap.get(7) {
Some(std::str::from_utf8(&s.as_bytes()[1..])?.to_owned())
} else {
None
};

let version = std::str::from_utf8(&cap[0])?;
info!("Found matching version string '{}'", version);
Expand All @@ -47,6 +53,7 @@ impl Version {
minor,
patch,
release_flags: release.to_owned(),
build_metadata,
});
}
Err(format_err!("failed to find version string"))
Expand All @@ -59,7 +66,11 @@ impl std::fmt::Display for Version {
f,
"{}.{}.{}{}",
self.major, self.minor, self.patch, self.release_flags
)
)?;
if let Some(build_metadata) = &self.build_metadata {
write!(f, "+{}", build_metadata,)?
}
Ok(())
}
}

Expand All @@ -75,7 +86,8 @@ mod tests {
major: 2,
minor: 7,
patch: 10,
release_flags: "".to_owned()
release_flags: "".to_owned(),
build_metadata: None,
}
);

Expand All @@ -89,7 +101,8 @@ mod tests {
major: 3,
minor: 6,
patch: 3,
release_flags: "".to_owned()
release_flags: "".to_owned(),
build_metadata: None,
}
);

Expand All @@ -102,7 +115,8 @@ mod tests {
major: 3,
minor: 7,
patch: 0,
release_flags: "rc1".to_owned()
release_flags: "rc1".to_owned(),
build_metadata: None,
}
);

Expand All @@ -115,7 +129,8 @@ mod tests {
major: 3,
minor: 10,
patch: 0,
release_flags: "rc1".to_owned()
release_flags: "rc1".to_owned(),
build_metadata: None,
}
);

Expand All @@ -137,7 +152,8 @@ mod tests {
major: 2,
minor: 7,
patch: 15,
release_flags: "".to_owned()
release_flags: "".to_owned(),
build_metadata: Some("".to_owned()),
}
);

Expand All @@ -148,7 +164,8 @@ mod tests {
major: 2,
minor: 7,
patch: 10,
release_flags: "".to_owned()
release_flags: "".to_owned(),
build_metadata: Some("dcba".to_owned()),
}
);

Expand All @@ -159,7 +176,20 @@ mod tests {
major: 2,
minor: 7,
patch: 10,
release_flags: "".to_owned()
release_flags: "".to_owned(),
build_metadata: Some("5-4.abcd".to_owned()),
}
);

let version = Version::scan_bytes(b"2.8.5+cinder (default)").unwrap();
assert_eq!(
version,
Version {
major: 2,
minor: 8,
patch: 5,
release_flags: "".to_owned(),
build_metadata: Some("cinder".to_owned()),
}
);
}
Expand Down

0 comments on commit bb0e7e8

Please sign in to comment.