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

New parameter to control automatic assembly exclusion #1392

Conversation

daveMueller
Copy link
Collaborator

@daveMueller daveMueller commented Oct 16, 2022

closes #1164

There are two things I wasn't really sure about.

I aligned the parameter description to the description in the feature #1164. But in the rest of the documentation the
values for the other parameters are always lowercased. So I would suggest to also describe them in the documentation
as missingall,missingany,none.
In the actual code it doesn't matter because it is compared case insensitive.

The second thing is that in the feature description it says that MissingAnyshould be the current behavior. Personally I
think that after changing the default behavior of the heuristic to MissingAll, the exclusion of generated document names
and the exclusion of the unknown F-sharp module don't make much sense anymore. Thus I removed the functions IsGeneratedDocumentName and IsUnknownModuleInFSharpAssembly from the InstrumentationHelper.
But I can also add them back again?

Copy link
Collaborator

@petli petli left a comment

Choose a reason for hiding this comment

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

Thanks for having a go at this, @daveMueller! Sorry I didn't have time to review it until now.

It looks good, and I agree with changing the default behaviour and removing the old heuristics for generated code. Might that require a major version bump, since it might change the behaviour of instrumentation for existing projects?

I only have some minor suggestions for code and logging tweaks, and the documentation seems inverted.

Comment on lines 239 to 240
| MissingAny | Includes the assembly if at least one document is matching. In case the `ExcludeAssembliesWithoutSources` parameter is not specified the default value is `MissingAny`. |
| MissingAll | Includes the assembly only if all documents can be matched to corresponding source files. |
Copy link
Collaborator

Choose a reason for hiding this comment

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

The parameters got mixed up in the documentation, this seems to be the intended meaning:

Suggested change
| MissingAny | Includes the assembly if at least one document is matching. In case the `ExcludeAssembliesWithoutSources` parameter is not specified the default value is `MissingAny`. |
| MissingAll | Includes the assembly only if all documents can be matched to corresponding source files. |
| MissingAll | Includes the assembly if at least one document is matching. In case the `ExcludeAssembliesWithoutSources` parameter is not specified the default value is `MissingAll`. |
| MissingAny | Includes the assembly only if all documents can be matched to corresponding source files. |

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

{
return (false, docName);
_logger.LogVerbose($"Unable to instrument module: {module}, pdb without any local source files");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
_logger.LogVerbose($"Unable to instrument module: {module}, pdb without any local source files");
_logger.LogVerbose($"Excluding module from instrumentation: {module}, pdb without any local source files");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

if (!allDocumentsMatch)
{
_logger.LogVerbose(
$"Unable to instrument module: {module}, pdb without local source files, [{FileSystem.EscapeFileName(notFoundDocument)}]");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$"Unable to instrument module: {module}, pdb without local source files, [{FileSystem.EscapeFileName(notFoundDocument)}]");
$"Excluding module from instrumentation: {module}, pdb without local source files, [{FileSystem.EscapeFileName(notFoundDocument)}]");

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 225 to 226
var documentSourceMap = DocumentSourceMap(metadataReader).ToList();
return documentSourceMap.Any(x => x.documentExists.Equals(true));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor detail, this could work on the enumeration directly, but at the price of making debugging harder:

Suggested change
var documentSourceMap = DocumentSourceMap(metadataReader).ToList();
return documentSourceMap.Any(x => x.documentExists.Equals(true));
return DocumentSourceMap(metadataReader).Any(x => x.documentExists);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


private IEnumerable<(string documentName, bool documentExists)> DocumentSourceMap(MetadataReader metadataReader)
{
return metadataReader.Documents.ToList().Select(docHandle =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to do the ToList() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

Comment on lines 232 to 235
var documentSourceMap = DocumentSourceMap(metadataReader).ToList();

if (documentSourceMap.Any(x => x.documentExists.Equals(false)))
return (false, documentSourceMap.FirstOrDefault(x => x.documentExists.Equals(false)).documentName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, can work on the enumerable:

Suggested change
var documentSourceMap = DocumentSourceMap(metadataReader).ToList();
if (documentSourceMap.Any(x => x.documentExists.Equals(false)))
return (false, documentSourceMap.FirstOrDefault(x => x.documentExists.Equals(false)).documentName);
var missingDoc = DocumentSourceMap(metadataReader).FirstOrDefault(x => !x.documentExists);
if (missingDoc != null)
{
return (false, missingDoc.documentName);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not so sure about this one. FirstOrDefault isn't meant to check whether a value exists or not, although we all (ab)use it this way. In this case FirstOrDefault would return a ValueTuple<string, bool> which defaults to (documentName: null, documentExists: false).
I now could adapt it to sth. like if (missingDoc.documenName != null){...} but now it somehow reads like: "If there is a document whose name can't be resolved lets include the assembly."
Even tho' this is just because all documents have a matching source file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed the tuple data type here, so ignore this comment :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

simplified the predicate

}

[Fact]
public void EmbeddedPortablePDPHasLocalSource_AllDocumentsExist_ReturnsTrue()
public void EmbeddedPortablePDPWithAssemblySearchTypeMissingAny_AllDocumentsExist_ReturnsTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since both MissingAny and MissingAll are tested:

Suggested change
public void EmbeddedPortablePDPWithAssemblySearchTypeMissingAny_AllDocumentsExist_ReturnsTrue()
public void EmbeddedPortablePDPHasLocalSource_AllDocumentsExist_ReturnsTrue()

It would also be good with a testcase where one file is missing, to test the difference in behaviour betweeen the two cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added test with one missing document

@daveMueller
Copy link
Collaborator Author

Thanks for the review @petli 🙏 . I'll have a look in the next days.

@petli
Copy link
Collaborator

petli commented Oct 27, 2022

Just a note that we shouldn't merge this before a minor fix with #1395 has been released, so people don't have to onboard the new behaviour at the same time.

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Oct 29, 2022

@daveMueller we merged this one in past(released on 3.2.0) #1360

does this PR invalidate that one right? I think we should add a new document where we list the breaking changes between versions so we can point the user there in case of questions, wdym? We can after link to the main readme as a new section.

@daveMueller
Copy link
Collaborator Author

@daveMueller we merged this one in past(released on 3.2.0) #1360

does this PR invalidate that one right? I think we should add a new document where we list the breaking changes between versions so we can point the user there in case of questions, wdym? We can after link to the main readme as a new section.

Yes you are right. The parameter from #1360 was replaced by setting the ExcludeAssembliesWithoutSources to none.

if (_excludeAssembliesWithoutSources.Equals(AssemblySearchType.None))

Maybe we could add/mark the breaking changes in our changelog like other projects are doing it, e.g. https://github.com/cake-build/cake/releases/tag/v2.0.0. Or were you thinking about sth. like a table that lists the different versions and their breaking changes?

@daveMueller
Copy link
Collaborator Author

I personally would prefer to align the description of the parameter values and make them lower case in these two documentations? Something like missingall,missingany,none, what do you think?

<ExcludeAssembliesWithoutSources>MissingAll,MissingAny,None</ExcludeAssembliesWithoutSources>

| Parameter | Description |
|-----------|-------------|
| MissingAll | Includes the assembly if at least one document is matching. In case the `ExcludeAssembliesWithoutSources` parameter is not specified the default value is `MissingAll`. |
| MissingAny | Includes the assembly only if all documents can be matched to corresponding source files. |
| None | No assembly is excluded. |

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Nov 2, 2022

Maybe we could add/mark the breaking changes in our changelog like other projects are doing it, e.g. https://github.com/cake-build/cake/releases/tag/v2.0.0. Or were you thinking about sth. like a table that lists the different versions and their breaking changes?

It's fine to me, I was wondering if we have around other BC for the next version, pls bump the version inside the version.json and coverlet.core.csproj like here https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ReleasePlan.md#how-to-manually-release-packages-to-nugetorg in this PR.

I remember some issue with the default msbuild property like /Include etc... and the idea to change to /Coverlet[Coverage]Include /CoverletCoverage etc...to avoid clash with "standard msbuild" prop, but I cannot find the issue.

@daveMueller
Copy link
Collaborator Author

I personally would prefer to align the description of the parameter values and make them lower case in these two documentations? Something like missingall,missingany,none, what do you think?

I thought about this again and decided to leave it like it currently is (MissingAll,MissingAny,None).

@daveMueller
Copy link
Collaborator Author

I remember some issue with the default msbuild property like /Include etc... and the idea to change to /Coverlet[Coverage]Include /CoverletCoverage etc...to avoid clash with "standard msbuild" prop, but I cannot find the issue.

It's this here:
#580
#1252

Documentation/Changelog.md Outdated Show resolved Hide resolved
Co-authored-by: Peter Liljenberg <peter@klavrekod.se>
@MarcoRossignoli
Copy link
Collaborator

Thanks @petli @daveMueller going to merge!

@MarcoRossignoli MarcoRossignoli merged commit cfccd83 into coverlet-coverage:master Nov 10, 2022
@daveMueller daveMueller deleted the 1164_ExcludeAssembliesWithoutSources branch September 12, 2023 22:20
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.

New parameter ExcludeAssembliesWithoutSources to control automatic assembly exclusion
3 participants