Skip to content

Commit 4cf9d90

Browse files
authored
Add uncompressed manifest generation to SOS build (#5603)
- Use file-based app to generate manifests for SOS packages - Generate both regular and uncompressed manifest formats
1 parent 297a926 commit 4cf9d90

File tree

4 files changed

+122
-54
lines changed

4 files changed

+122
-54
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
using System.Xml.Linq;
4+
using System.Xml.XPath;
5+
6+
const string ExpectedParameters = "<GalleryManifestBaseTemplate> <GalleryManifestPath> <CompressedManifestPath> <ExtensionVersion>";
7+
8+
const string FilesXpathInPackageElement = "Components/BinaryComponent/Files";
9+
const string CompressedGalleryManifestTemplate = """
10+
<?xml version="1.0" encoding="utf-8"?>
11+
<ExtensionPackages Version="1.0.0.0" Compression="none">
12+
</ExtensionPackages>
13+
""";
14+
15+
if (args is null || args.Length != 4)
16+
{
17+
Console.Error.WriteLine("Expected parameters: {0}", ExpectedParameters);
18+
return -1;
19+
}
20+
21+
string galleryManifestBaseTemplate = args[0];
22+
string galleryManifestPath = args[1];
23+
string uncompressedManifestPath = args[2];
24+
string extensionVersion = args[3];
25+
26+
// Compressed and uncompressed manifests are the same for SOS except for two main differences:
27+
// - The compressed manifest has the ExtensionPackage as a top level element, while the uncompressed manifest has ExtensionPackages as the top level element
28+
// with Compression="none" attribute. The uncompressed manifest contains a single ExtensionPackage element with the ExtensionPackage that would appear in
29+
// the compressed manifest as a child element.
30+
// - The uncompressed manifest's ExtensionPackage contains a single File element pointing to the architecture-specific extension installed by the win SDK installer.
31+
// The compressed manifest's ExtensionPackage contains a File element per architecture as the extension gallery ships all of them in one.
32+
Console.WriteLine("Generating manifests for SOS version {0}", extensionVersion);
33+
34+
XDocument galleryManifest = XDocument.Load(galleryManifestBaseTemplate);
35+
XElement extensionPackageElement = galleryManifest.Root!;
36+
extensionPackageElement.XPathSelectElement("Version")!.Value = extensionVersion;
37+
38+
// Create uncompressed manifest with the updated version.
39+
XDocument uncompressedGalleryManifest = XDocument.Parse(CompressedGalleryManifestTemplate);
40+
XElement extensionPackageInCompressedManifest = new(extensionPackageElement);
41+
uncompressedGalleryManifest.Root!.Add(extensionPackageInCompressedManifest);
42+
43+
Console.WriteLine("Generating extension gallery manifest.");
44+
// Update compressed/regular manifest to have a File element per RID since the gallery ships all architectures in one package.
45+
XElement files = extensionPackageElement.XPathSelectElement(FilesXpathInPackageElement)!;
46+
files.RemoveNodes();
47+
files.Add(
48+
new XElement("File", new XAttribute("Architecture", "amd64"), new XAttribute("Module", "win-x64\\sos.dll")),
49+
new XElement("File", new XAttribute("Architecture", "x86"), new XAttribute("Module", "win-x86\\sos.dll")),
50+
new XElement("File", new XAttribute("Architecture", "arm64"), new XAttribute("Module", "win-arm64\\sos.dll")));
51+
52+
// Create folder if it doesn't exist and save the gallery manifest.
53+
Directory.CreateDirectory(Path.GetDirectoryName(galleryManifestPath)!);
54+
galleryManifest.Save(galleryManifestPath);
55+
56+
Console.WriteLine("Generating debugger layout (uncompressed) manifest.");
57+
// Update uncompressed manifest to have a single File element pointing to the winext\sos\sos.dll path.
58+
// The installer is responsible for installing the correct architecture-specific DLL.
59+
XElement uncompressedFiles = extensionPackageInCompressedManifest.XPathSelectElement(FilesXpathInPackageElement)!;
60+
uncompressedFiles.RemoveNodes();
61+
uncompressedFiles.Add(
62+
new XElement("File", new XAttribute("Architecture", "Any"), new XAttribute("Module", "winext\\sos\\sos.dll"), new XAttribute("FilePathKind", "RepositoryRelative")));
63+
Directory.CreateDirectory(Path.GetDirectoryName(uncompressedManifestPath)!);
64+
uncompressedGalleryManifest.Save(uncompressedManifestPath);
65+
66+
Console.WriteLine("Done.");
67+
return 0;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ExtensionPackage>
3+
<Name>SOS</Name>
4+
<Version />
5+
<Description>Debugging aid for .NET Core programs and runtimes</Description>
6+
<Components>
7+
<BinaryComponent Name="sos" Type="Engine">
8+
<Files />
9+
<LoadTriggers>
10+
<TriggerSet>
11+
<ModuleTrigger Name="coreclr.dll" />
12+
</TriggerSet>
13+
<TriggerSet>
14+
<ModuleTrigger Name="libcoreclr.so" />
15+
</TriggerSet>
16+
<TriggerSet>
17+
<ExceptionTrigger ExceptionCode="0xC0000409">
18+
<Parameters>
19+
<Parameter Index="0" Value="0x48" />
20+
</Parameters>
21+
</ExceptionTrigger>
22+
</TriggerSet>
23+
<TriggerSet>
24+
<ExceptionTrigger ExceptionCode="0xC000027B" />
25+
</TriggerSet>
26+
<TriggerSet>
27+
<ExceptionTrigger ExceptionCode="0xC000027C" />
28+
</TriggerSet>
29+
</LoadTriggers>
30+
<EngineCommands>
31+
<EngineCommand Name="soshelp">
32+
<EngineCommandItem>
33+
<Syntax>!soshelp</Syntax>
34+
<Description>Displays all available SOS commands or details about the command</Description>
35+
</EngineCommandItem>
36+
</EngineCommand>
37+
</EngineCommands>
38+
</BinaryComponent>
39+
</Components>
40+
</ExtensionPackage>

src/SOS/SOS.Package/SOS.Package.csproj

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<IsPackable>true</IsPackable>
1010
<IncludeBuildOutput>false</IncludeBuildOutput>
1111
<SOSPackagePathPrefix>tools</SOSPackagePathPrefix>
12-
<GalleryManifestName>$(ArtifactsPackagesDir)\GalleryManifest.xml</GalleryManifestName>
12+
<GalleryManifestBase>$(MSBuildThisFileDirectory)ManifestBase.xml</GalleryManifestBase>
13+
<ExtensionGalleryManifestOutputFile>$(IntermediateOutputPath)sos_GalleryManifest.xml</ExtensionGalleryManifestOutputFile>
14+
<UncompressedGalleryManifestOutputFile>$(IntermediateOutputPath)GalleryManifest.xml</UncompressedGalleryManifestOutputFile>
1315
<BeforePack>GenerateGalleryManifest</BeforePack>
1416
<IsShipping>true</IsShipping>
1517
<IsShippingPackage>false</IsShippingPackage>
@@ -22,72 +24,30 @@
2224
<Target Name="Build" />
2325

2426
<ItemGroup>
25-
<None Include="$(GalleryManifestName)" Pack="true" Visible="false">
27+
<Compile Remove="**/*.cs" />
28+
<None Include="$(ExtensionGalleryManifestOutputFile)" Pack="true" Visible="false">
29+
<PackagePath>$(SOSPackagePathPrefix)</PackagePath>
30+
</None>
31+
<None Include="$(UncompressedGalleryManifestOutputFile)" Pack="true" Visible="false">
2632
<PackagePath>$(SOSPackagePathPrefix)</PackagePath>
2733
</None>
2834
<None Include="$(SOSExtensionsBinaries)" Pack="true" Visible="false">
2935
<PackagePath>$(SOSPackagePathPrefix)/lib</PackagePath>
3036
</None>
3137
</ItemGroup>
3238

39+
<!-- This target generates the gallery manifest files, both the extension gallery format and
40+
the uncompressed one used by the SDK installer. -->
3341
<Target Name="GenerateGalleryManifest"
3442
DependsOnTargets="GetAssemblyVersion;AddSourceRevisionToInformationalVersion">
35-
<PropertyGroup>
36-
<GalleryManifestLines>
37-
<![CDATA[
38-
<?xml version="1.0" encoding="utf-8"?>
39-
<ExtensionPackage>
40-
<Name>SOS</Name>
41-
<Version>$(FileVersion)</Version>
42-
<Description>Debugging aid for .NET Core programs and runtimes</Description>
43-
<Components>
44-
<BinaryComponent Name="sos" Type="Engine">
45-
<Files>
46-
<File Architecture="amd64" Module="win-x64\sos.dll" />
47-
<File Architecture="x86" Module="win-x86\sos.dll" />
48-
<File Architecture="arm64" Module="win-arm64\sos.dll" />
49-
</Files>
50-
<LoadTriggers>
51-
<TriggerSet>
52-
<ModuleTrigger Name="coreclr.dll" />
53-
</TriggerSet>
54-
<TriggerSet>
55-
<ModuleTrigger Name="libcoreclr.so" />
56-
</TriggerSet>
57-
<TriggerSet>
58-
<ExceptionTrigger ExceptionCode="0xC0000409">
59-
<Parameters>
60-
<Parameter Index="0" Value="0x48" />
61-
</Parameters>
62-
</ExceptionTrigger>
63-
</TriggerSet>
64-
<TriggerSet>
65-
<ExceptionTrigger ExceptionCode="0xC000027B" />
66-
</TriggerSet>
67-
<TriggerSet>
68-
<ExceptionTrigger ExceptionCode="0xC000027C" />
69-
</TriggerSet>
70-
</LoadTriggers>
71-
<EngineCommands>
72-
<EngineCommand Name="soshelp">
73-
<EngineCommandItem>
74-
<Syntax>!soshelp</Syntax>
75-
<Description>Displays all available SOS commands or details about the command</Description>
76-
</EngineCommandItem>
77-
</EngineCommand>
78-
</EngineCommands>
79-
</BinaryComponent>
80-
</Components>
81-
</ExtensionPackage>
82-
]]>
83-
</GalleryManifestLines>
84-
</PropertyGroup>
8543

86-
<WriteLinesToFile File="$(GalleryManifestName)" Lines="$(GalleryManifestLines)" Overwrite="true" />
44+
<Exec Command="$(DotNetTool) run --file $(MSBuildThisFileDirectory)GenerateManifest\GenerateManifest.cs &quot;$(GalleryManifestBase)&quot; &quot;$(ExtensionGalleryManifestOutputFile)&quot; &quot;$(UncompressedGalleryManifestOutputFile)&quot; &quot;$(FileVersion)&quot;" />
8745

8846
<ItemGroup>
89-
<FileWrites Include="$(GalleryManifestName)" />
47+
<FileWrites Include="$(ExtensionGalleryManifestOutputFile)" />
48+
<FileWrites Include="$(UncompressedGalleryManifestOutputFile)" />
9049
</ItemGroup>
50+
9151
</Target>
9252

9353
</Project>

src/SOS/SOS.Package/SOS.Symbol.Package.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17+
<Compile Remove="**/*.cs" />
1718
<None Include="$(ArtifactsBinDir)\SOS.Extensions\$(Configuration)\netstandard2.0\publish\*.pdb" Pack="true" Visible="false">
1819
<PackagePath>$(SOSPackagePathPrefix)/lib</PackagePath>
1920
</None>

0 commit comments

Comments
 (0)