Skip to content

Commit

Permalink
Don't emit v2 analysisTarget if there is no v1 resultFile. (#1247)
Browse files Browse the repository at this point in the history
Don't emit v2 analysisTarget if there is no v1 resultFile.
  • Loading branch information
Larry Golding authored Jan 31, 2019
1 parent d21b906 commit ee0d5dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"message": {
"text": "Some testing occurred."
},
"analysisTarget": {
"uri": "file:///home/buildAgent/src/myFile.cpp"
},
"locations": [
{
"physicalLocation": {
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/VersionConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.CodeAnalysis.Sarif
{
public static class VersionConstants
{
public const string Prerelease = "csd.2.beta.2018-10-10.1";
public const string Prerelease = "csd.2.beta.2018-10-10.2";
public const string AssemblyVersion = "2.0.0";
public const string FileVersion = AssemblyVersion + ".0";
}
Expand Down
8 changes: 6 additions & 2 deletions src/Sarif/Visitors/SarifVersionOneToCurrentVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,12 @@ internal Result CreateResult(ResultVersionOne v1Result)
SuppressionStates = Utilities.CreateSuppressionStates(v1Result.SuppressionStates)
};

// The spec says that analysisTarget is required only if it differs from the result file.
if (v1Result.Locations?[0]?.AnalysisTarget?.Uri != v1Result.Locations?[0]?.ResultFile?.Uri)
// The v2 spec says that analysisTarget is required only if it differs from the result location.
// On the other hand, the v1 spec says that if the result is found in the file that the tool
// was instructed to scan, then analysisTarget should be present and resultFile should be
// absent -- so we should _not_ populate the v2 analysisTarget in this case.
LocationVersionOne v1Location = v1Result.Locations?[0];
if (v1Location?.ResultFile != null && v1Location.AnalysisTarget?.Uri != v1Location.ResultFile.Uri)
{
result.AnalysisTarget = CreateFileLocation(v1Result.Locations[0].AnalysisTarget);
}
Expand Down

0 comments on commit ee0d5dc

Please sign in to comment.