Skip to content

Commit 37b6bcd

Browse files
authored
Update UpdateVendors tool to allow vendoring non-C# code (#8529)
## Summary of changes - Update the `UpdateVendors` tool to allow outputting to arbitrary directory - Allow opting-out of "NuGet dependabot honeypot file" - Add spdlog to the list of vendored deps ## Reason for change We want to update spdlog. The update was done manually in #4044, but using the existing infrastructure seems preferable. Note that this PR _doesn't_ bump the dependency, it just sets up the infrastructure to make it easy. ## Implementation details - Add `RelativePathToVendorDirectoryOverride` to allow vendoring to arbitrary directory - Add `IsNuGetPackage` to allow opt-out of the NuGet dependabot file - Add reference for vendored spdlog code ## Test coverage Ran the tool, and it updated spdlog, but the code was the same ## Other details We'll bump the spdlog version in a subsequent PR
1 parent 1034c3f commit 37b6bcd

5 files changed

Lines changed: 30 additions & 7 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/gabime/spdlog/archive/refs/tags/v1.11.0.zip

tracer/build/_build/Build.Utilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static Func<string, CooldownMode> BuildCooldownModeSelector(string[] includePack
381381
var vendorDirectory = Solution.GetProject(Projects.DatadogTrace).Directory / "Vendors";
382382
var downloadDirectory = TemporaryDirectory / "Downloads";
383383
EnsureCleanDirectory(downloadDirectory);
384-
await UpdateVendorsTool.UpdateVendors(downloadDirectory, vendorDirectory);
384+
await UpdateVendorsTool.UpdateVendors(downloadDirectory, RootDirectory, vendorDirectory);
385385
});
386386

387387
Target UpdateVersion => _ => _

tracer/build/_build/Honeypot/DependabotFileManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void UpdateVendors(AbsolutePath honeypotProject)
2121
{
2222
var fakeRefs = string.Empty;
2323

24-
foreach (var dependency in VendoredDependency.All)
24+
foreach (var dependency in VendoredDependency.All.Where(x => x.IsNuGetPackage))
2525
{
2626
fakeRefs += $@"{Environment.NewLine} <!-- https://www.nuget.org/packages/{dependency.LibraryName}/{dependency.Version} -->";
2727
fakeRefs += $@"{Environment.NewLine} <PackageReference Include=""{dependency.LibraryName}"" Version=""{dependency.Version}"" />{Environment.NewLine}";

tracer/build/_build/UpdateVendors/UpdateVendors.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,29 @@ public static class UpdateVendorsTool
1818
{
1919
public static async Task UpdateVendors(
2020
AbsolutePath downloadDirectory,
21-
AbsolutePath vendorDirectory)
21+
AbsolutePath rootDirectory,
22+
AbsolutePath defaultVendorDirectory)
2223
{
2324
foreach (var dependency in VendoredDependency.All)
2425
{
25-
await UpdateVendor(dependency, downloadDirectory, vendorDirectory);
26+
await UpdateVendor(dependency, downloadDirectory, rootDirectory, defaultVendorDirectory);
2627
}
2728
}
2829

29-
private static async Task UpdateVendor(VendoredDependency dependency, AbsolutePath downloadDirectory, AbsolutePath vendorDirectory)
30+
private static async Task UpdateVendor(VendoredDependency dependency, AbsolutePath downloadDirectory, AbsolutePath rootDirectory, AbsolutePath defaultVendorDirectory)
3031
{
3132
var libraryName = dependency.LibraryName;
3233
var downloadUrl = dependency.DownloadUrl;
3334
var pathToSrc = dependency.PathToSrc;
3435

3536
Console.WriteLine($"Starting {libraryName} upgrade.");
37+
var vendorDirectory = dependency.RelativePathToVendorDirectoryOverride is not null
38+
? rootDirectory / dependency.RelativePathToVendorDirectoryOverride
39+
: defaultVendorDirectory;
3640

3741
var zipLocation = Path.Combine(downloadDirectory, $"{libraryName}.zip");
3842
var extractLocation = Path.Combine(downloadDirectory, $"{libraryName}");
39-
var vendorFinalPath = Path.Combine(vendorDirectory, libraryName);
43+
var vendorFinalPath = vendorDirectory / libraryName;
4044
var sourceUrlLocation = Path.Combine(vendorFinalPath, "_last_downloaded_source_url.txt");
4145

4246
// Ensure the url has changed, or don't bother upgrading

tracer/build/_build/UpdateVendors/VendoredDependency.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using System.Text;
1010
using System.Text.RegularExpressions;
11+
using Nuke.Common.IO;
1112

1213
namespace UpdateVendors
1314
{
@@ -396,6 +397,15 @@ static VendoredDependency()
396397
"OtlpTraceExporter.cs",
397398
"OtlpTraceExporterHelperExtensions.cs"
398399
});
400+
401+
Add(
402+
libraryName: "spdlog",
403+
version: "1.11.0",
404+
downloadUrl: "https://github.com/gabime/spdlog/archive/refs/tags/v1.11.0.zip",
405+
pathToSrc: new[] {"spdlog-1.11.0", "include", "spdlog"},
406+
transform: filePath => { },
407+
relativePathToVendorDirectoryOverride: (RelativePath) "shared/src/native-lib/spdlog/include",
408+
isNuGetPackage: false);
399409
}
400410

401411
public static List<VendoredDependency> All { get; set; } = new List<VendoredDependency>();
@@ -414,14 +424,20 @@ static VendoredDependency()
414424

415425
public string[] OnlyIncludeRelativePaths { get; set; }
416426

427+
public RelativePath RelativePathToVendorDirectoryOverride { get; set; }
428+
429+
public bool IsNuGetPackage { get; set; }
430+
417431
private static void Add(
418432
string libraryName,
419433
string version,
420434
string downloadUrl,
421435
string[] pathToSrc,
422436
Action<string> transform,
423437
string[] relativePathsToExclude = null,
424-
string[] onlyIncludePaths = null)
438+
string[] onlyIncludePaths = null,
439+
RelativePath relativePathToVendorDirectoryOverride = null,
440+
bool isNuGetPackage = true)
425441
{
426442
All.Add(new VendoredDependency()
427443
{
@@ -432,6 +448,8 @@ private static void Add(
432448
Transform = transform,
433449
RelativePathsToExclude = relativePathsToExclude ?? Array.Empty<string>(),
434450
OnlyIncludeRelativePaths = onlyIncludePaths,
451+
RelativePathToVendorDirectoryOverride = relativePathToVendorDirectoryOverride,
452+
IsNuGetPackage = isNuGetPackage,
435453
});
436454
}
437455

0 commit comments

Comments
 (0)