Skip to content

Commit

Permalink
Fixup (#253)
Browse files Browse the repository at this point in the history
* Ignore SIGPIPE

* Use unique ids for each license

* Fix lint

* Update CHANGELOG
  • Loading branch information
Jake-Shadle authored Aug 12, 2024
1 parent 42b5a56 commit 41d5ca2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 15 additions & 11 deletions about.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,27 @@
<h2>Overview of licenses:</h2>
<ul class="licenses-overview">
{{#each overview}}
<li><a href="#{{id}}">{{name}}</a> ({{count}})</li>
<li><a href="#{{short_id}}">{{name}}</a> ({{count}})</li>
{{/each}}
</ul>

<h2>All license text:</h2>
<ul class="licenses-list">
{{#each licenses}}
<li class="license">
<h3 id="{{id}}">{{name}}</h3>
<h4>Used by:</h4>
<ul class="license-used-by">
{{#each used_by}}
<li><a href="{{#if crate.repository}} {{crate.repository}} {{else}} https://crates.io/crates/{{crate.name}} {{/if}}">{{crate.name}} {{crate.version}}</a></li>
{{/each}}
</ul>
<pre class="license-text">{{text}}</pre>
</li>
<!-- Write out a header for each block of the same license -->
{{#if first_of_kind}}
<h3 id="{{short_id}}">{{name}}</h3>
{{/if}}
<li class="license">
<h4 id="{{short_id}}-{{@index}}">{{name}}</h>
<h5>Used by:</h5>
<ul class="license-used-by">
{{#each used_by}}
<li><a href="{{#if crate.repository}} {{crate.repository}} {{else}} https://crates.io/crates/{{crate.name}} {{/if}}">{{crate.name}} {{crate.version}}</a></li>
{{/each}}
</ul>
<pre class="license-text">{{text}}</pre>
</li>
{{/each}}
</ul>
</main>
Expand Down
23 changes: 14 additions & 9 deletions src/cargo-about/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -298,7 +300,7 @@ struct License<'a> {
struct LicenseSet {
count: usize,
name: String,
id: String,
short_id: String,
indices: Vec<usize>,
text: String,
}
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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,
});
}
}
Expand Down Expand Up @@ -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
};

Expand All @@ -439,8 +443,8 @@ fn generate<'kl>(

let mut overview: Vec<LicenseSet> = 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);
Expand All @@ -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;
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/cargo-about/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,23 @@ fn real_main() -> anyhow::Result<()> {
}
}

/// Ignore SIGPIPE due to std library deficiency <https://github.com/rust-lang/rust/issues/46016>
#[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) => {
Expand Down

0 comments on commit 41d5ca2

Please sign in to comment.