Skip to content

Commit d564529

Browse files
committed
C#: Change RestoreSettings to have general extraArgs parameter
This allows the string of package feeds to be constructed once and used repeatedly in the parallel restore loop as well.
1 parent 7a92a72 commit d564529

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,6 @@ private string GetRestoreArgs(RestoreSettings restoreSettings)
6767
args += $" --configfile \"{restoreSettings.PathToNugetConfig}\"";
6868
}
6969

70-
// Add package sources. If any are present, they override all sources specified in
71-
// the configuration file(s).
72-
if (restoreSettings.Sources != null)
73-
{
74-
var feedArgs = new StringBuilder();
75-
foreach (string source in restoreSettings.Sources)
76-
{
77-
feedArgs.Append($" -s {source}");
78-
}
79-
80-
args += feedArgs.ToString();
81-
}
82-
8370
if (restoreSettings.ForceReevaluation)
8471
{
8572
args += " --force";
@@ -90,6 +77,11 @@ private string GetRestoreArgs(RestoreSettings restoreSettings)
9077
args += " /p:EnableWindowsTargeting=true";
9178
}
9279

80+
if (restoreSettings.ExtraArgs != null)
81+
{
82+
args += $" {restoreSettings.ExtraArgs}";
83+
}
84+
9385
return args;
9486
}
9587

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDotNet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IDotNet
1717
IList<string> GetNugetFeedsFromFolder(string folderPath);
1818
}
1919

20-
public record class RestoreSettings(string File, string PackageDirectory, bool ForceDotnetRefAssemblyFetching, IList<string>? Sources = null, string? PathToNugetConfig = null, bool ForceReevaluation = false, bool TargetWindows = false);
20+
public record class RestoreSettings(string File, string PackageDirectory, bool ForceDotnetRefAssemblyFetching, string? ExtraArgs = null, string? PathToNugetConfig = null, bool ForceReevaluation = false, bool TargetWindows = false);
2121

2222
public partial record class RestoreResult(bool Success, IList<string> Output)
2323
{

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,27 @@ private void RestoreProjects(IEnumerable<string> projects, HashSet<string>? conf
265265
// Conservatively, we only set this to a non-null value if a Dependabot proxy is enabled.
266266
// This ensures that we continue to get the old behaviour where feeds are taken from
267267
// `nuget.config` files instead of the command-line arguments.
268-
HashSet<string>? sources = null;
268+
string? extraArgs = null;
269269

270270
if (this.dependabotProxy is not null)
271271
{
272272
// If the Dependabot proxy is configured, then our main goal is to make `dotnet` aware
273273
// of the private registry feeds. However, since providing them as command-line arguments
274274
// to `dotnet` ignores other feeds that may be configured, we also need to add the feeds
275275
// we have discovered from analysing `nuget.config` files.
276-
sources = configuredSources ?? new();
276+
var sources = configuredSources ?? new();
277277
sources.Add(PublicNugetOrgFeed);
278278
this.dependabotProxy.RegistryURLs.ForEach(url => sources.Add(url));
279+
280+
// Add package sources. If any are present, they override all sources specified in
281+
// the configuration file(s).
282+
var feedArgs = new StringBuilder();
283+
foreach (string source in sources)
284+
{
285+
feedArgs.Append($" -s {source}");
286+
}
287+
288+
extraArgs = feedArgs.ToString();
279289
}
280290

281291
var successCount = 0;
@@ -292,7 +302,7 @@ private void RestoreProjects(IEnumerable<string> projects, HashSet<string>? conf
292302
foreach (var project in projectGroup)
293303
{
294304
logger.LogInfo($"Restoring project {project}...");
295-
var res = dotnet.Restore(new(project, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true, sources?.ToList(), TargetWindows: isWindows));
305+
var res = dotnet.Restore(new(project, PackageDirectory.DirInfo.FullName, ForceDotnetRefAssemblyFetching: true, extraArgs, TargetWindows: isWindows));
296306
assets.AddDependenciesRange(res.AssetsFilePaths);
297307
lock (sync)
298308
{

0 commit comments

Comments
 (0)