Skip to content

Commit f99cb3f

Browse files
authored
Merge pull request #16396 from tamasvajk/buildless/opt-out-feed-check
C#: Change nuget feed responsiveness checking to be opt-out
2 parents dfdd79d + d909f2b commit f99cb3f

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public static DirectoryInfo[] GetOrderedPackageVersionSubDirectories(string pack
9494
public HashSet<AssemblyLookupLocation> Restore()
9595
{
9696
var assemblyLookupLocations = new HashSet<AssemblyLookupLocation>();
97-
var checkNugetFeedResponsiveness = EnvironmentVariables.GetBoolean(EnvironmentVariableNames.CheckNugetFeedResponsiveness);
97+
var checkNugetFeedResponsiveness = EnvironmentVariables.GetBooleanOptOut(EnvironmentVariableNames.CheckNugetFeedResponsiveness);
98+
logger.LogInfo($"Checking NuGet feed responsiveness: {checkNugetFeedResponsiveness}");
99+
compilationInfoContainer.CompilationInfos.Add(("NuGet feed responsiveness checked", checkNugetFeedResponsiveness ? "1" : "0"));
100+
98101
try
99102
{
100103
if (checkNugetFeedResponsiveness && !CheckFeeds())

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/SourceGenerators/RazorGenerator.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,9 @@ public RazorGenerator(
2020

2121
protected override bool IsEnabled()
2222
{
23-
var webViewExtractionOption = Environment.GetEnvironmentVariable(EnvironmentVariableNames.WebViewGeneration);
24-
if (webViewExtractionOption == null ||
25-
bool.TryParse(webViewExtractionOption, out var shouldExtractWebViews) &&
26-
shouldExtractWebViews)
27-
{
28-
compilationInfoContainer.CompilationInfos.Add(("WebView extraction enabled", "1"));
29-
return true;
30-
}
31-
32-
compilationInfoContainer.CompilationInfos.Add(("WebView extraction enabled", "0"));
33-
return false;
23+
var webViewExtractionOption = EnvironmentVariables.GetBooleanOptOut(EnvironmentVariableNames.WebViewGeneration);
24+
compilationInfoContainer.CompilationInfos.Add(("WebView extraction enabled", webViewExtractionOption ? "1" : "0"));
25+
return webViewExtractionOption;
3426
}
3527

3628
protected override ICollection<string> AdditionalFiles => fileProvider.RazorViews;

csharp/extractor/Semmle.Util/EnvironmentVariables.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ public static int GetDefaultNumberOfThreads()
2929
return threads;
3030
}
3131

32+
public static bool GetBooleanOptOut(string name)
33+
{
34+
var env = Environment.GetEnvironmentVariable(name);
35+
if (env == null ||
36+
bool.TryParse(env, out var value) &&
37+
value)
38+
{
39+
return true;
40+
}
41+
42+
return false;
43+
}
44+
3245
public static bool GetBoolean(string name)
3346
{
3447
var env = Environment.GetEnvironmentVariable(name);

csharp/ql/integration-tests/all-platforms/standalone_resx/CompilationInfo.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
| All Nuget feeds reachable | 1.0 |
12
| Failed project restore with package source error | 0.0 |
23
| Failed solution restore with package source error | 0.0 |
4+
| NuGet feed responsiveness checked | 1.0 |
35
| Project files on filesystem | 1.0 |
46
| Resource extraction enabled | 1.0 |
57
| Restored .NET framework variants | 1.0 |

csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error/CompilationInfo.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
| All Nuget feeds reachable | 1.0 |
12
| Failed project restore with package source error | 1.0 |
23
| Failed solution restore with package source error | 0.0 |
34
| Fallback nuget restore | 1.0 |
5+
| NuGet feed responsiveness checked | 1.0 |
46
| Project files on filesystem | 1.0 |
57
| Resolved assembly conflicts | 7.0 |
68
| Resource extraction enabled | 0.0 |

csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error_timeout/CompilationInfo.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| All Nuget feeds reachable | 0.0 |
22
| Fallback nuget restore | 1.0 |
33
| Inherited Nuget feed count | 1.0 |
4+
| NuGet feed responsiveness checked | 1.0 |
45
| Project files on filesystem | 1.0 |
56
| Resolved assembly conflicts | 7.0 |
67
| Resource extraction enabled | 0.0 |

csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error_timeout/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from diagnostics_test_utils import *
33
import os
44

5-
os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK"] = "true" # Enable NuGet feed check
5+
# os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK"] = "true" # Nuget feed check is enabled by default
66
os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_TIMEOUT"] = "1" # 1ms, the GET request should fail with such short timeout
77
os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_LIMIT"] = "1" # Limit the count of checks to 1
88
os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_EXCLUDED"] = "https://abc.de:8000/packages/" # Exclude this feed from check

0 commit comments

Comments
 (0)