Skip to content

Commit a1415e2

Browse files
authored
Merge pull request github#16661 from tamasvajk/buildless/nuget-path-space
C#: Quote packages.config paths
2 parents c06df55 + 9af6cb8 commit a1415e2

File tree

9 files changed

+53
-8
lines changed

9 files changed

+53
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ private string DownloadNugetExe(string sourceDir)
153153
private bool RunWithMono => !Win32.IsWindows() && !string.IsNullOrEmpty(Path.GetExtension(nugetExe));
154154

155155
/// <summary>
156-
/// Restore all files in a specified package.
156+
/// Restore all packages in the specified packages.config file.
157157
/// </summary>
158-
/// <param name="package">The package file.</param>
159-
private bool TryRestoreNugetPackage(string package)
158+
/// <param name="packagesConfig">The packages.config file.</param>
159+
private bool TryRestoreNugetPackage(string packagesConfig)
160160
{
161-
logger.LogInfo($"Restoring file {package}...");
161+
logger.LogInfo($"Restoring file \"{packagesConfig}\"...");
162162

163163
/* Use nuget.exe to install a package.
164164
* Note that there is a clutch of NuGet assemblies which could be used to
@@ -170,12 +170,12 @@ private bool TryRestoreNugetPackage(string package)
170170
if (RunWithMono)
171171
{
172172
exe = "mono";
173-
args = $"{nugetExe} install -OutputDirectory {packageDirectory} {package}";
173+
args = $"{nugetExe} install -OutputDirectory \"{packageDirectory}\" \"{packagesConfig}\"";
174174
}
175175
else
176176
{
177177
exe = nugetExe!;
178-
args = $"install -OutputDirectory {packageDirectory} {package}";
178+
args = $"install -OutputDirectory \"{packageDirectory}\" \"{packagesConfig}\"";
179179
}
180180

181181
var pi = new ProcessStartInfo(exe, args)
@@ -196,7 +196,7 @@ private bool TryRestoreNugetPackage(string package)
196196
}
197197
else
198198
{
199-
logger.LogInfo($"Restored file {package}");
199+
logger.LogInfo($"Restored file \"{packagesConfig}\"");
200200
return true;
201201
}
202202
}
@@ -206,7 +206,7 @@ private bool TryRestoreNugetPackage(string package)
206206
/// </summary>
207207
public int InstallPackages()
208208
{
209-
return fileProvider.PackagesConfigs.Count(package => TryRestoreNugetPackage(package));
209+
return fileProvider.PackagesConfigs.Count(TryRestoreNugetPackage);
210210
}
211211

212212
private bool HasNoPackageSource()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| [...]/Newtonsoft.Json.6.0.4/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import csharp
2+
3+
private string getPath(Assembly a) {
4+
not a.getCompilation().getOutputAssembly() = a and
5+
exists(string s | s = a.getFile().getAbsolutePath() |
6+
result =
7+
"[...]" +
8+
s.substring(s.indexOf("test-db/working/") + "test-db/working/".length() + 16 +
9+
"/legacypackages".length(), s.length())
10+
// TODO: include all other assemblies from the test results. Initially disable because mono installations were problematic on ARM runners.
11+
)
12+
}
13+
14+
from Assembly a
15+
select getPath(a)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Program
2+
{
3+
static void Main(string[] args)
4+
{
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.101"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
4+
<package id="NUnit.ConsoleRunner" version="3.12.0" />
5+
</packages>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from create_database_utils import *
2+
import os
3+
4+
# making sure we're not doing any fallback restore:
5+
os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1"
6+
os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "1"
7+
8+
run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"])

0 commit comments

Comments
 (0)