Skip to content

Commit

Permalink
Add Cargo.lock to sdist when --locked or --frozen specified
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 19, 2021
1 parent f793063 commit a03f578
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for x86_64 Haiku in [#735](https://github.com/PyO3/maturin/pull/735)
* Fix undefined auditwheel policy panic in [#740](https://github.com/PyO3/maturin/pull/740)
* Fix sdist upload for packages where the pkgname contains multiple underscores in [#741](https://github.com/PyO3/maturin/pull/741)
* Add `Cargo.lock` to sdist when `--locked` or `--frozen` specified in [#749](https://github.com/PyO3/maturin/pull/749)

## [0.12.4] - 2021-12-06

Expand Down
5 changes: 5 additions & 0 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ impl BuildContext {
fs::create_dir_all(&self.out)
.context("Failed to create the target directory for the source distribution")?;

let include_cargo_lock = self
.cargo_extra_args
.iter()
.any(|arg| arg == "--locked" || arg == "--frozen");
match PyProjectToml::new(self.manifest_path.parent().unwrap()) {
Ok(pyproject) => {
let sdist_path = source_distribution(
Expand All @@ -238,6 +242,7 @@ impl BuildContext {
&self.manifest_path,
&self.cargo_metadata,
pyproject.sdist_include(),
include_cargo_lock,
)
.context("Failed to build source distribution")?;
Ok(Some((sdist_path, "source".to_string())))
Expand Down
6 changes: 6 additions & 0 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn source_distribution(
manifest_path: impl AsRef<Path>,
cargo_metadata: &Metadata,
sdist_include: Option<&Vec<String>>,
include_cargo_lock: bool,
) -> Result<PathBuf> {
let known_path_deps = find_path_deps(cargo_metadata)?;

Expand Down Expand Up @@ -271,6 +272,11 @@ pub fn source_distribution(
)?;

let manifest_dir = manifest_path.as_ref().parent().unwrap();
if include_cargo_lock {
let cargo_lock_path = manifest_dir.join("Cargo.lock");
let target = root_dir.join("Cargo.lock");
writer.add_file(&target, &cargo_lock_path)?;
}

if let Some(include_targets) = sdist_include {
for pattern in include_targets {
Expand Down

0 comments on commit a03f578

Please sign in to comment.