Skip to content

Commit

Permalink
Store checksums for registry deps in Scarb.lock (#912)
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Kaput <[email protected]>
  • Loading branch information
mkaput authored Nov 20, 2023
1 parent 1c3f6f7 commit 325b975
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
4 changes: 4 additions & 0 deletions scarb/src/core/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ impl Lockfile {
.filter(include_package)
.map(|dep| dep.name.clone())
.collect::<BTreeSet<_>>();

let summary = resolve.summary(package);

PackageLock::builder()
.use_package_id(package)
.dependencies(deps)
.checksum(summary.checksum.clone())
.build()
});
Self::new(packages)
Expand Down
8 changes: 7 additions & 1 deletion scarb/src/core/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use itertools::Itertools;
use petgraph::graphmap::DiGraphMap;
use petgraph::visit::{Dfs, EdgeFiltered, Walker};
use smallvec::SmallVec;
use std::collections::HashMap;

use crate::core::{PackageId, TargetKind};
use crate::core::{PackageId, Summary, TargetKind};

/// Represents a fully-resolved package dependency graph.
///
Expand All @@ -14,6 +15,7 @@ pub struct Resolve {
///
/// If package `a` depends on package `b`, then this graph will contain an edge from `a` to `b`.
pub graph: DiGraphMap<PackageId, DependencyEdge>,
pub summaries: HashMap<PackageId, Summary>,
}

impl Resolve {
Expand Down Expand Up @@ -51,6 +53,10 @@ impl Resolve {
self.graph
.neighbors_directed(package_id, petgraph::Direction::Outgoing)
}

pub fn summary(&self, package_id: PackageId) -> &Summary {
&self.summaries[&package_id]
}
}

#[derive(Debug, Default, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub async fn resolve(
"});
}

Ok(Resolve { graph })
Ok(Resolve { graph, summaries })
}

fn rewrite_locked_dependency(
Expand Down
36 changes: 35 additions & 1 deletion scarb/tests/lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#![allow(clippy::items_after_test_module)]

use std::fs;
use std::path::Path;

use assert_fs::prelude::*;
use assert_fs::TempDir;
use fs_extra::dir::{copy, CopyOptions};
use indoc::indoc;
use snapbox::cmd::Command;

use fs_extra::dir::{copy, CopyOptions};
use scarb_test_support::cargo::cargo_bin;
use scarb_test_support::command::Scarb;
use scarb_test_support::project_builder::{Dep, DepBuilder, ProjectBuilder};
use scarb_test_support::registry::local::LocalRegistry;
use test_for_each_example::test_for_each_example;

#[test_for_each_example]
Expand Down Expand Up @@ -45,3 +50,32 @@ fn create_lockfile_simple(example: &Path) {
[[package]]
"#}));
}

#[test]
fn store_checksum_for_registry_dependencies() {
let mut registry = LocalRegistry::create();
registry.publish(|t| {
ProjectBuilder::start()
.name("bar")
.version("1.0.0")
.lib_cairo(r#"fn f() -> felt252 { 0 }"#)
.build(t);
});

let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("foo")
.version("0.1.0")
.dep("bar", Dep.version("1").registry(&registry))
.lib_cairo(r#"fn f() -> felt252 { bar::f() }"#)
.build(&t);

Scarb::quick_snapbox()
.arg("fetch")
.current_dir(&t)
.assert()
.success();

t.child("Scarb.lock")
.assert(predicates::str::contains(r#"checksum = ""#));
}

0 comments on commit 325b975

Please sign in to comment.