5
5
using System . Linq ;
6
6
using Microsoft . Build . Construction ;
7
7
using System . Xml ;
8
+ using System . IO ;
8
9
9
10
namespace Semmle . Autobuild . Cpp . Tests
10
11
{
@@ -43,6 +44,8 @@ bool IBuildActions.FileExists(string file)
43
44
public IDictionary < string , int > RunProcess = new Dictionary < string , int > ( ) ;
44
45
public IDictionary < string , string > RunProcessOut = new Dictionary < string , string > ( ) ;
45
46
public IDictionary < string , string > RunProcessWorkingDirectory = new Dictionary < string , string > ( ) ;
47
+ public HashSet < string > CreateDirectories { get ; } = new HashSet < string > ( ) ;
48
+ public HashSet < ( string , string ) > DownloadFiles { get ; } = new HashSet < ( string , string ) > ( ) ;
46
49
47
50
int IBuildActions . RunProcess ( string cmd , string args , string ? workingDirectory , IDictionary < string , string > ? env , out IList < string > stdOut )
48
51
{
@@ -135,6 +138,14 @@ string IBuildActions.PathCombine(params string[] parts)
135
138
136
139
string IBuildActions . GetFullPath ( string path ) => path ;
137
140
141
+ string ? IBuildActions . GetFileName ( string ? path ) => Path . GetFileName ( path ? . Replace ( '\\ ' , '/' ) ) ;
142
+
143
+ public string ? GetDirectoryName ( string ? path )
144
+ {
145
+ var dir = Path . GetDirectoryName ( path ? . Replace ( '\\ ' , '/' ) ) ;
146
+ return dir is null ? path : path ? . Substring ( 0 , dir . Length ) ;
147
+ }
148
+
138
149
void IBuildActions . WriteAllText ( string filename , string contents )
139
150
{
140
151
}
@@ -153,6 +164,18 @@ public string EnvironmentExpandEnvironmentVariables(string s)
153
164
s = s . Replace ( $ "%{ kvp . Key } %", kvp . Value ) ;
154
165
return s ;
155
166
}
167
+
168
+ public void CreateDirectory ( string path )
169
+ {
170
+ if ( ! CreateDirectories . Contains ( path ) )
171
+ throw new ArgumentException ( $ "Missing CreateDirectory, { path } ") ;
172
+ }
173
+
174
+ public void DownloadFile ( string address , string fileName )
175
+ {
176
+ if ( ! DownloadFiles . Contains ( ( address , fileName ) ) )
177
+ throw new ArgumentException ( $ "Missing DownloadFile, { address } , { fileName } ") ;
178
+ }
156
179
}
157
180
158
181
/// <summary>
@@ -213,6 +236,7 @@ CppAutobuilder CreateAutoBuilder(bool isWindows,
213
236
Actions . GetEnvironmentVariable [ $ "CODEQL_EXTRACTOR_{ codeqlUpperLanguage } _SOURCE_ARCHIVE_DIR"] = "" ;
214
237
Actions . GetEnvironmentVariable [ $ "CODEQL_EXTRACTOR_{ codeqlUpperLanguage } _ROOT"] = $@ "C:\codeql\{ codeqlUpperLanguage . ToLowerInvariant ( ) } ";
215
238
Actions . GetEnvironmentVariable [ "CODEQL_JAVA_HOME" ] = @"C:\codeql\tools\java" ;
239
+ Actions . GetEnvironmentVariable [ "CODEQL_PLATFORM" ] = "win64" ;
216
240
Actions . GetEnvironmentVariable [ "SEMMLE_DIST" ] = @"C:\odasa" ;
217
241
Actions . GetEnvironmentVariable [ "SEMMLE_JAVA_HOME" ] = @"C:\odasa\tools\java" ;
218
242
Actions . GetEnvironmentVariable [ "SEMMLE_PLATFORM_TOOLS" ] = @"C:\odasa\tools" ;
@@ -273,7 +297,8 @@ public void TestDefaultCppAutobuilder()
273
297
[ Fact ]
274
298
public void TestCppAutobuilderSuccess ( )
275
299
{
276
- Actions . RunProcess [ @"cmd.exe /C C:\odasa\tools\csharp\nuget\nuget.exe restore C:\Project\test.sln" ] = 1 ;
300
+ Actions . RunProcess [ @"cmd.exe /C nuget restore C:\Project\test.sln -DisableParallelProcessing" ] = 1 ;
301
+ Actions . RunProcess [ @"cmd.exe /C C:\Project\.nuget\nuget.exe restore C:\Project\test.sln -DisableParallelProcessing" ] = 0 ;
277
302
Actions . RunProcess [ @"cmd.exe /C CALL ^""C:\Program Files ^(x86^)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat^"" && set Platform=&& type NUL && C:\odasa\tools\odasa index --auto msbuild C:\Project\test.sln /p:UseSharedCompilation=false /t:rebuild /p:Platform=""x86"" /p:Configuration=""Release"" /p:MvcBuildViews=true" ] = 0 ;
278
303
Actions . RunProcessOut [ @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe -prerelease -legacy -property installationPath" ] = "" ;
279
304
Actions . RunProcess [ @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe -prerelease -legacy -property installationPath" ] = 1 ;
@@ -286,11 +311,13 @@ public void TestCppAutobuilderSuccess()
286
311
Actions . FileExists [ @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" ] = true ;
287
312
Actions . EnumerateFiles [ @"C:\Project" ] = "foo.cs\n test.slx" ;
288
313
Actions . EnumerateDirectories [ @"C:\Project" ] = "" ;
314
+ Actions . CreateDirectories . Add ( @"C:\Project\.nuget" ) ;
315
+ Actions . DownloadFiles . Add ( ( "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" , @"C:\Project\.nuget\nuget.exe" ) ) ;
289
316
290
317
var autobuilder = CreateAutoBuilder ( true ) ;
291
318
var solution = new TestSolution ( @"C:\Project\test.sln" ) ;
292
319
autobuilder . ProjectsOrSolutionsToBuild . Add ( solution ) ;
293
- TestAutobuilderScript ( autobuilder , 0 , 2 ) ;
320
+ TestAutobuilderScript ( autobuilder , 0 , 3 ) ;
294
321
}
295
322
}
296
323
}
0 commit comments