|
| 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; |
0 commit comments