diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f541ff..7d1567d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [PR#251](https://github.com/EmbarkStudios/cargo-about/pull/251) updated crates and directly depend on `semver`.
+### Fixed
+- [PR#253](https://github.com/EmbarkStudios/cargo-about/pull/253) resolved [#250](https://github.com/EmbarkStudios/cargo-about/issues/250) by changing the example template to emit unique anchors.
+- [PR#253](https://github.com/EmbarkStudios/cargo-about/pull/253) resolved [#252](https://github.com/EmbarkStudios/cargo-about/issues/252) by ignoring `SIGPIPE`.
+
## [0.6.2] - 2024-05-31
### Changed
- [PR#248](https://github.com/EmbarkStudios/cargo-about/pull/248) updated crates.
diff --git a/about.hbs b/about.hbs
index eab1b82..a78e4bd 100644
--- a/about.hbs
+++ b/about.hbs
@@ -48,23 +48,27 @@
Overview of licenses:
All license text:
{{#each licenses}}
- -
-
{{name}}
- Used by:
-
- {{text}}
-
+
+ {{#if first_of_kind}}
+ {{name}}
+ {{/if}}
+ -
+
{{name}}
+ Used by:
+
+ {{text}}
+
{{/each}}
diff --git a/src/cargo-about/generate.rs b/src/cargo-about/generate.rs
index c860931..c56362e 100644
--- a/src/cargo-about/generate.rs
+++ b/src/cargo-about/generate.rs
@@ -285,7 +285,9 @@ struct License<'a> {
/// The full name of the license
name: String,
/// The SPDX short identifier for the license
- id: String,
+ short_id: String,
+ /// True if this is the first license of its kind in the flat array
+ first_of_kind: bool,
/// The full license text
text: String,
/// The path where the license text was sourced from
@@ -298,7 +300,7 @@ struct License<'a> {
struct LicenseSet {
count: usize,
name: String,
- id: String,
+ short_id: String,
indices: Vec,
text: String,
}
@@ -322,7 +324,7 @@ fn generate<'kl>(
let diag_cfg = term::Config::default();
- let licenses = {
+ let mut licenses = {
let mut licenses = BTreeMap::new();
for (krate_license, resolved) in nfos
.iter()
@@ -365,10 +367,11 @@ fn generate<'kl>(
| licenses::LicenseFileKind::AddendumText(text, _) => {
let license = License {
name: id.full_name.to_owned(),
- id: id.name.to_owned(),
+ short_id: id.name.to_owned(),
text: text.clone(),
source_path: Some(lf.path.clone()),
used_by: Vec::new(),
+ first_of_kind: false,
};
Some(license)
}
@@ -386,10 +389,11 @@ fn generate<'kl>(
// fallback to the canonical license text and emit a warning
license_texts.push(License {
name: id.full_name.to_owned(),
- id: id.name.to_owned(),
+ short_id: id.name.to_owned(),
text: id.text().to_owned(),
source_path: None,
used_by: Vec::new(),
+ first_of_kind: false,
});
}
}
@@ -427,7 +431,7 @@ fn generate<'kl>(
lic.used_by.sort_by(|a, b| a.krate.id.cmp(&b.krate.id));
}
- licenses.sort_by(|a, b| a.id.cmp(&b.id));
+ licenses.sort_by(|a, b| a.short_id.cmp(&b.short_id));
licenses
};
@@ -439,8 +443,8 @@ fn generate<'kl>(
let mut overview: Vec = Vec::with_capacity(256);
- for (ndx, lic) in licenses.iter().enumerate() {
- match overview.binary_search_by(|i| i.id.cmp(&lic.id)) {
+ for (ndx, lic) in licenses.iter_mut().enumerate() {
+ match overview.binary_search_by(|i| i.short_id.cmp(&lic.short_id)) {
Ok(i) => {
let ov = &mut overview[i];
ov.indices.push(ndx);
@@ -450,13 +454,14 @@ fn generate<'kl>(
let mut ls = LicenseSet {
count: lic.used_by.len(),
name: lic.name.clone(),
- id: lic.id.clone(),
+ short_id: lic.short_id.clone(),
indices: Vec::with_capacity(10),
text: lic.text.clone(),
};
ls.indices.push(ndx);
overview.insert(i, ls);
+ lic.first_of_kind = true;
}
}
}
diff --git a/src/cargo-about/main.rs b/src/cargo-about/main.rs
index 603ac59..1fba9a3 100644
--- a/src/cargo-about/main.rs
+++ b/src/cargo-about/main.rs
@@ -119,7 +119,23 @@ fn real_main() -> anyhow::Result<()> {
}
}
+/// Ignore SIGPIPE due to std library deficiency
+#[cfg(unix)]
+fn ignore_sigpipe() {
+ extern "C" {
+ fn signal(signum: i32, handler: usize) -> usize;
+ }
+
+ #[allow(unsafe_code)]
+ unsafe {
+ signal(13 /*SIGPIPE*/, 0 /*SIG_DFL*/);
+ }
+}
+
fn main() {
+ #[cfg(unix)]
+ ignore_sigpipe();
+
match real_main() {
Ok(_) => {}
Err(e) => {