Skip to content

Commit

Permalink
Sort dependencies before using them
Browse files Browse the repository at this point in the history
Otherwise they come out in non-reproducible order, and that order leaks into
target binaries.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
  • Loading branch information
Alexander Kanavin authored and gdesmott committed Nov 17, 2021
1 parent e470dc0 commit e076945
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,17 @@ impl Dependencies {
self.libs.get(name)
}

/// An iterator visiting all system dependencies in arbitrary order.
/// A vector listing all system dependencies in sorted (for build reproducibility) order.
/// The first element of the tuple is the name of the `toml` key defining the
/// dependency in `Cargo.toml`.
pub fn iter(&self) -> impl Iterator<Item = (&str, &Library)> {
self.libs.iter().map(|(k, v)| (k.as_str(), v))
pub fn iter(&self) -> Vec<(&str, &Library)> {
let mut v = self
.libs
.iter()
.map(|(k, v)| (k.as_str(), v))
.collect::<Vec<_>>();
v.sort_by_key(|x| x.0);
v
}

fn aggregate_str<F: Fn(&Library) -> &Vec<String>>(&self, getter: F) -> Vec<&str> {
Expand Down Expand Up @@ -384,14 +390,14 @@ impl Dependencies {
let mut flags = BuildFlags::new();
let mut include_paths = Vec::new();

for (name, lib) in self.libs.iter() {
for (name, lib) in self.iter() {
include_paths.extend(lib.include_paths.clone());

if lib.source == Source::EnvVariables
&& lib.libs.is_empty()
&& lib.frameworks.is_empty()
{
return Err(Error::MissingLib(name.clone()));
return Err(Error::MissingLib(name.to_string()));
}

lib.link_paths
Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn good() {
assert_eq!(testdata.version, "4.5.6");
assert!(libraries.get_by_name("testmore").is_none());

assert_eq!(libraries.iter().count(), 2);
assert_eq!(libraries.iter().len(), 2);

assert_flags(
flags,
Expand Down

0 comments on commit e076945

Please sign in to comment.