Skip to content

Commit e6eddf5

Browse files
committed
teach lockstep to recognize rust-lang/cargo#12233
1 parent 8fa236d commit e6eddf5

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ reqwest = { version = "0.11.10", features = ["default", "blocking" ] }
1414
omicron-zone-package = { git = "https://github.com/oxidecomputer/omicron-package", branch = "main" }
1515
glob = "0.3"
1616
cargo-lock = "9"
17+
url = "2"

src/main.rs

+75-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ if nothing is required, lockstep won't print anything.
3434
opte support is missing
3535
*/
3636

37+
use std::cmp::Ordering;
3738
use std::collections::BTreeMap;
3839
use std::collections::HashSet;
40+
use std::hash;
41+
use std::hash::Hash;
3942
use std::path::Path;
43+
use url::Url;
4044

4145
use anyhow::{anyhow, bail, Result};
46+
use cargo_lock::package::SourceKind;
4247
use cargo_toml::Manifest;
4348
use glob::glob;
4449
use reqwest::blocking::Client;
@@ -175,6 +180,46 @@ fn get_explicit_dependencies(
175180
Ok(())
176181
}
177182

183+
// Implement SourceID like rust-lang/Cargo, not like in rustsec/rustsec (read:
184+
// with manual impls)
185+
#[derive(Clone, Debug, Eq)]
186+
struct MySourceId {
187+
pub url: Url,
188+
pub kind: SourceKind,
189+
pub precise: Option<String>,
190+
}
191+
192+
impl PartialEq for MySourceId {
193+
fn eq(&self, other: &MySourceId) -> bool {
194+
self.cmp(other) == Ordering::Equal
195+
}
196+
}
197+
198+
impl PartialOrd for MySourceId {
199+
fn partial_cmp(&self, other: &MySourceId) -> Option<Ordering> {
200+
Some(self.cmp(other))
201+
}
202+
}
203+
204+
impl Ord for MySourceId {
205+
fn cmp(&self, other: &MySourceId) -> Ordering {
206+
// Ignore precise and name
207+
match self.kind.cmp(&other.kind) {
208+
Ordering::Equal => {}
209+
other => return other,
210+
};
211+
212+
self.url.cmp(&other.url)
213+
}
214+
}
215+
216+
impl Hash for MySourceId {
217+
fn hash<S: hash::Hasher>(&self, into: &mut S) {
218+
self.url.hash(into);
219+
self.kind.hash(into);
220+
}
221+
}
222+
178223
fn check_cargo_lock_revisions(
179224
sub_directory: &str,
180225
latest_revs: &BTreeMap<String, String>,
@@ -189,6 +234,9 @@ fn check_cargo_lock_revisions(
189234
dependencies
190235
};
191236

237+
// Check for conflicting SourceId
238+
let mut sources: HashSet<MySourceId> = HashSet::new();
239+
192240
for package in &cargo_lockfile.packages {
193241
if let Some(source) = &package.source {
194242
let path = source.url().path();
@@ -204,8 +252,8 @@ fn check_cargo_lock_revisions(
204252
// for packages in a Cargo.toml
205253
if dependencies.contains(&package.name.to_string()) {
206254
println!(
207-
"{}/Cargo.lock has old rev for {} {}!",
208-
sub_directory, repo, package.name,
255+
"{}/Cargo.lock has old rev for {} {}! update {} to {}",
256+
sub_directory, repo, package.name, precise, latest_rev,
209257
);
210258
}
211259
}
@@ -216,9 +264,32 @@ fn check_cargo_lock_revisions(
216264
}
217265
}
218266
}
267+
268+
let my_source_id = MySourceId {
269+
url: source.url().clone(),
270+
kind: source.kind().clone(),
271+
precise: source.precise().map(|x| x.to_string()).clone(),
272+
};
273+
274+
if let Some(existing_source) = sources.get(&my_source_id) {
275+
if existing_source.precise == my_source_id.precise {
276+
sources.insert(my_source_id);
277+
} else {
278+
panic!(
279+
"{}/Cargo.lock has a mismatch for {:?} != {:?}!",
280+
sub_directory, existing_source, my_source_id,
281+
);
282+
}
283+
} else {
284+
sources.insert(my_source_id);
285+
}
219286
}
220287
}
221288

289+
for source in sources {
290+
println!("{}/Cargo.lock has source {:?}", sub_directory, source);
291+
}
292+
222293
Ok(())
223294
}
224295

@@ -284,6 +355,8 @@ fn main() -> Result<()> {
284355
// - update crucible cargo revs
285356
// - update propolis cargo revs
286357

358+
check_cargo_lock_revisions("omicron", &latest_revs)?;
359+
287360
update_required |= compare_cargo_toml_revisions(
288361
"omicron",
289362
&Manifest::from_path("./omicron/Cargo.toml")?,

0 commit comments

Comments
 (0)