Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Move sourcelinks to symbolic-common #803

Merged
merged 10 commits into from
Jul 14, 2023
Merged

ref: Move sourcelinks to symbolic-common #803

merged 10 commits into from
Jul 14, 2023

Conversation

loewenheim
Copy link
Contributor

In preparation of using sourcelinks in sourcebundles, this extracts the sourcelink functionality from symbolic-ppdb and moves it to symbolic-common. It also refactors the implementation based on serde.

The JSON representation of a SourceLinkMappings struct looks like this:

{
    "C:\\src\\*":                   "http://MyDefaultDomain.com/src/*",
    "C:\\src\\fOO\\*":              "http://MyFooDomain.com/src/*",
    "C:\\src\\foo\\specific.txt":   "http://MySpecificFoodDomain.com/src/specific.txt",
    "C:\\src\\bar\\*":              "http://MyBarDomain.com/src/*",
    "C:\\src\\file.txt": "https://example.com/file.txt",
    "/home/user/src/*": "https://linux.com/*"
}

One downside of this is that it makes the serde dependency of symbolic-common non-optional. I don't know how big a deal this really is, but it may be that this code might more appropriately live in a different place.

@loewenheim loewenheim self-assigned this Jul 11, 2023
@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #803 (e78fdf6) into master (09c291b) will decrease coverage by 0.23%.
The diff coverage is 95.23%.

❗ Current head e78fdf6 differs from pull request most recent head 3f90cb3. Consider uploading reports for the commit 3f90cb3 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #803      +/-   ##
==========================================
- Coverage   75.03%   74.80%   -0.23%     
==========================================
  Files          71       63       -8     
  Lines       15630    15603      -27     
==========================================
- Hits        11728    11672      -56     
- Misses       3902     3931      +29     

Comment on lines 112 to 129
/// Parse a `SourceLinkMapping` struct from a list of `documents` json values.
///
/// See [Source Link PPDB docs](https://github.com/dotnet/designs/blob/main/accepted/2020/diagnostics/source-link.md#source-link-json-schema).
pub fn parse_from_documents(jsons: &[&[u8]]) -> Result<Self, serde_json::Error> {
#[derive(Deserialize)]
struct Documents {
documents: BTreeMap<Pattern, String>,
}

let mut mappings = BTreeMap::new();

for &json in jsons {
let docs: Documents = serde_json::from_slice(json)?;
mappings.extend(docs.documents.into_iter());
}

Ok(Self { mappings })
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, instead of having a Deserialize and depending directly on serde, I would rather have a new(iter: impl Iterator<Item=(&str, &str)>) which consumes just pattern, value pairs. No serde involved at that point.

It would then consume the iterator and parse/build its Pattern types, sort that list and store it. The custom Ord impl is a bit overkill compared to the previous sorting code.

The serde impl is also a bit overkill compared to a simple "consume key/value pairs" code. But I do see your point that this would basically give you "parse sourcebundle manifest" functionality for free.
Though I would really want to keep this shared code as simple and possible, and also move specialized parse_from_documents to the ppdb crate, as that is very specific to ppdb.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the parse_from_documents stuff is better in symbolic-ppdb. For the rest of the implementation, would you rather have the old version? Shouldn't be too hard to implement De/Serialize for that one either.

@loewenheim loewenheim changed the title ref: Move sourcelinks to symbolic-common and serdefy them ref: Move sourcelinks to symbolic-common Jul 13, 2023
@loewenheim
Copy link
Contributor Author

The implementation has been simplified and the serde functionality removed.

symbolic-common/src/sourcelinks.rs Outdated Show resolved Hide resolved
Co-authored-by: Arpad Borsos <swatinem@swatinem.de>
@loewenheim loewenheim enabled auto-merge (squash) July 14, 2023 09:27
@loewenheim loewenheim merged commit 760f7c4 into master Jul 14, 2023
10 checks passed
@loewenheim loewenheim deleted the ref/sourcelinks branch July 14, 2023 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants