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

Vs insertion Sbom generation (Roslyn,fSharp) #9629

Merged
merged 11 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,15 @@
<_StubFiles Include="$(VisualStudioSetupIntermediateOutputPath)**\*.stub"/>
<_StubDirs Include="@(_StubFiles->'%(RecursiveDir)')"/>
</ItemGroup>
<!--
Before pack create the SBOM here
-->
<PropertyGroup>
<GenerateSbom Condition="'$(GenerateSbom)' == ''">false</GenerateSbom>
</PropertyGroup>

<Target Name ="GenerateSbomForVSInsertion"
Condition="'$(GenerateSbom)' != 'false'">
<Message Text="Generating SBOM manifest" Importance="high"/>
<ItemGroup>
<VsixFile Include="$(ArtifactsDir)VSSetup\$(Configuration)\Insertion\*.vsix"></VsixFile>
<VsixFile Include="$(ArtifactsDir)VSSetup\$(Configuration)\Insertion\*.exe"></VsixFile>
</ItemGroup>
<MakeDir Directories="$(ArtifactsDir)sbom;$(ArtifactsDir)sbom\%(VsixFile.Filename);$(ArtifactsDir)Vsix;$(ArtifactsDir)Vsix\Unpacked\%(VsixFile.Filename)"/>

<Unzip
SourceFiles="@(VsixFile)"
DestinationFolder="$(ArtifactsDir)Vsix\Unpacked\%(VsixFile.Filename)"
OverwriteReadOnlyFiles="true"/>

<Exec Command = "$(DotNetTool) $(NUGET_PACKAGES)microsoft.manifesttool.crossplatform\$(MicrosoftManifestToolCrossPlatformVersion)\Content\Microsoft.ManifestTool.dll generate -b $(ArtifactsDir)Vsix\Unpacked\%(VsixFile.Filename) -m $(ArtifactsDir)sbom\%(VsixFile.Filename) -pn VsInsertion -V Verbose"/>
<Message Text="Completed generating SBOM manifest for %(VsixFile.Filename)." Importance="high"/>
</Target>

<!---
This target is invoked in a separate phase after all input VSIX files are signed.
This is important since the manifest contain hashes of the VSIX files.
-->
<Target Name="GenerateVisualStudioInsertionManifests"
BeforeTargets="AfterPack"
Outputs="%(_StubDirs.Identity)"
Condition="'@(_StubDirs)' != ''"
DependsOnTargets="GenerateSbomForVSInsertion">
Condition="'@(_StubDirs)' != ''">
<PropertyGroup>
<_ComponentDir>%(_StubDirs.Identity)</_ComponentDir>
<_ComponentName>$(_ComponentDir.TrimEnd('\'))</_ComponentName>
Expand All @@ -54,8 +30,8 @@
<_Args Include="ComponentIntermediateOutputPath=$(VisualStudioSetupIntermediateOutputPath)$(_ComponentName)\"/>
<_Args Include="SwixBuildPath=$(NuGetPackageRoot)microsoft.visualstudioeng.microbuild.plugins.swixbuild\$(MicrosoftVisualStudioEngMicroBuildPluginsSwixBuildVersion)\"/>
<_Args Include="VisualStudioDropName=$(VisualStudioDropName)" />
<_Args Include="ArtifactsDir=$(ArtifactsDir)" />
<_Args Include="GenerateSbom=$(GenerateSbom)" />
<_Args Include="DotNetTool=$(DotNetTool)" />
<_Args Include="ManifestTool=$(NUGET_PACKAGES)microsoft.manifesttool.crossplatform\$(MicrosoftManifestToolCrossPlatformVersion)\Content\Microsoft.ManifestTool.dll"/>
</ItemGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"Products/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildNumber)"
The manifest will be published with URI
https://vsdrop.corp.microsoft.com/file/v1/$(VisualStudioDropName)
DotNetTool Path to dotnet.exe.
ManifestTool Path to Microsoft.ManifestTool.dll
-->

<PropertyGroup>
Expand All @@ -30,8 +32,6 @@
<TargetName>$(ComponentName)</TargetName>
<OutputPath>$(SetupOutputPath)</OutputPath>
<IntermediateOutputPath>$(ComponentIntermediateOutputPath)</IntermediateOutputPath>
<ArtifactsDir>$(ArtifactsDir)</ArtifactsDir>
<GenerateSbom>$(GenerateSbom)</GenerateSbom>

<!-- Note that the url is expected to end with ';' (%3B) -->
<ManifestPublishUrl Condition="'$(VisualStudioDropName)' != ''">https://vsdrop.corp.microsoft.com/file/v1/$(VisualStudioDropName)%3B</ManifestPublishUrl>
Expand All @@ -42,50 +42,66 @@
<_PackageStubFiles Include="$(ComponentIntermediateOutputPath)*.stub"/>
</ItemGroup>

<ItemGroup Condition="'$(GenerateSbom)' == 'false'">
<MergeManifest Include="@(_PackageStubFiles->'$(SetupOutputPath)%(Filename).json')"/>
</ItemGroup>

<Import Project="$(SwixBuildPath)build\Microsoft.VisualStudioEng.MicroBuild.Plugins.SwixBuild.targets" />

<Target Name="_BuildManifest" DependsOnTargets="_SetManifestBuildVersion;GenerateSetupManifest" />

<!--
Each stub file contains VSIX version of the respective VSIX file.
We require that all VSIXes included in a single VS insertion component have the same version.
This version will be set to ManifestBuildVersion.
-->
<Target Name="_SetManifestBuildVersion">
<Target Name="_BuildManifest" DependsOnTargets="_GetVsixFileInfo;_GenerateSbomForVsixAndAddManifestItem;GenerateSetupManifest" />

<Target Name="_GetVsixFileInfo">
<ReadLinesFromFile File="%(_PackageStubFiles.Identity)">
<Output TaskParameter="Lines" ItemName="_StubLine"/>
</ReadLinesFromFile>

<ItemGroup>
<_StubLineSplit Include="@(_StubLine)"
Name="$([MSBuild]::ValueOrDefault('%(_StubLine.Identity)', '').Split('/')[0])"
Version="$([MSBuild]::ValueOrDefault('%(_StubLine.Identity)', '').Split('/')[1])" />
<_ParsedLine Include="@(_StubLine)"
riarenas marked this conversation as resolved.
Show resolved Hide resolved
VsixId="$([MSBuild]::ValueOrDefault('%(_StubLine.Identity)', '').Split('/')[0])"
VsixFileName="$([MSBuild]::ValueOrDefault('%(_StubLine.Identity)', '').Split('/')[1])"
VsixVersion="$([MSBuild]::ValueOrDefault('%(_StubLine.Identity)', '').Split('/')[2])" />

<_VsixFileInfo Include="@(_ParsedLine->'%(VsixFileName)')">
<ManifestJsonPath>$(SetupOutputPath)%(VsixId).json</ManifestJsonPath>
<VsixPath>$(SetupOutputPath)%(VsixFileName)</VsixPath>
<UnpackDir>$(ComponentIntermediateOutputPath)%(VsixFileName)\unpack</UnpackDir>
<SbomDir>$(ComponentIntermediateOutputPath)%(VsixFileName)\sbom</SbomDir>
<SbomJsonPath>$(ComponentIntermediateOutputPath)%(VsixFileName)\sbom\spdx_2.2\manifest.spdx.json</SbomJsonPath>
</_VsixFileInfo>
</ItemGroup>

<ItemGroup>
<_VsixVersion Include="%(_StubLineSplit.Version)" Name="%(_StubLineSplit.Name)" />
<_VsixVersion Include="%(_VsixFileInfo.VsixVersion)" VsixFileName="%(_VsixFileInfo.Identity)" />
</ItemGroup>

<RemoveDuplicates Inputs="@(_VsixVersion)">
<Output TaskParameter="Filtered" ItemName="_VsixVersionNoDuplicates"/>
</RemoveDuplicates>

<Error Text="Visual Studio component '$(ComponentName)' contains multiple VSIX files with different versions: @(_VsixVersionNoDuplicates->'%(Name) (version %(Identity))', ', ')"
<!--
Each stub file contains VSIX version of the respective VSIX file.
We require that all VSIXes included in a single VS insertion component have the same version.
This version will be set to ManifestBuildVersion.
-->
<Error Text="Visual Studio component '$(ComponentName)' contains multiple VSIX files with different versions: @(_VsixVersionNoDuplicates->'%(VsixFileName) (version %(Identity))', ', ')"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the error message should mention that all versions need to match for sbom generation? if I got this error I wouldn't understand what's wrong about having different versions in my components, which doesn't seem that strange (if a new vsix is added it doesn't seem weird to me that it would have a different version than existing ones)

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually for sbom generation we are just using the Vsix version. This error msg is specifically for VS manifest generation. So I am going to add something like

"Cannot generate VS manifest because Visual Studio Component '$(ComponentName)' contains multiple VSIX files with different versions: @(_VsixVersionNoDuplicates->'%(VsixFileName) (version %(Identity))', ', ')" 

This way we will know that vs manifest is not generated cos of version error.

Condition="@(_VsixVersionNoDuplicates->Count()) != 1"/>

<PropertyGroup>
<ManifestBuildVersion>@(_VsixVersionNoDuplicates)</ManifestBuildVersion>
<ManifestVsixName>@(_VsixVersionNoDuplicates->'%(Name)')</ManifestVsixName>
</PropertyGroup>
<ItemGroup Condition= "'$(GenerateSbom)' == 'true'">
<MergeManifest Include="$(SetupOutputPath)$(ComponentName).json">
<SBOMFileLocation>$(ArtifactsDir)sbom\$(ManifestVsixName.Substring(0, $(ManifestVsixName.LastIndexOf('.'))))\spdx_2.2\manifest.spdx.json</SBOMFileLocation>
</MergeManifest>
</ItemGroup>
</Target>

<Target Name="_GenerateSbomForVsixAndAddManifestItem"
Inputs="@(_VsixFileInfo->'%(VsixPath)')"
Outputs="@(_VsixFileInfo->'%(SbomJsonPath)')"
DependsOnTargets="_GetVsixFileInfo">
<Message Text="Generating SBOM manifest for '%(_VsixFileInfo.Identity)'" Importance="high"/>

<MakeDir Directories="%(_VsixFileInfo.SbomDir);%(_VsixFileInfo.UnpackDir)"/>
<Unzip SourceFiles="%(_VsixFileInfo.VsixPath)" DestinationFolder="%(_VsixFileInfo.UnpackDir)"/>

<Exec Command='"$(DotNetTool)" "$(ManifestTool)" generate -BuildDropPath "%(_VsixFileInfo.UnpackDir)" -ManifestDirPath "%(_VsixFileInfo.SbomDir)" -PackageName "%(_VsixFileInfo.VsixFileName)" -PackageVersion "%(_VsixFileInfo.VsixVersion)" -Verbosity Verbose'/>

<ItemGroup>
<MergeManifest Include="%(_VsixFileInfo.ManifestJsonPath)" SBOMFileLocation="%(_VsixFileInfo.SbomJsonPath)" />
</ItemGroup>

<Message Text="Completed generating SBOM manifest for %(_VsixFileInfo.Identity)." Importance="high"/>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<Error Text="VisualStudioInsertionComponent property must only be set for projects with extension.vsixmanifest or SWR files." Condition="'$(_PackageStubFile)' == ''"/>

<MakeDir Directories="$(_ComponentIntermediateDir)" />
<WriteLinesToFile File="$(_PackageStubFile)" Lines="$(TargetVsixContainerName)/$(VsixVersion)" Overwrite="true" />
<WriteLinesToFile File="$(_PackageStubFile)" Lines="$(_VsixPackageId)/$(TargetVsixContainerName)/$(VsixVersion)" Overwrite="true" />

<ItemGroup>
<FileWrites Include="$(_PackageStubFile)"/>
Expand Down