55using System . Linq ;
66using Microsoft . Build . Construction ;
77using System . Xml ;
8+ using System . IO ;
89
910namespace Semmle . Autobuild . Cpp . Tests
1011{
@@ -43,6 +44,8 @@ bool IBuildActions.FileExists(string file)
4344 public IDictionary < string , int > RunProcess = new Dictionary < string , int > ( ) ;
4445 public IDictionary < string , string > RunProcessOut = new Dictionary < string , string > ( ) ;
4546 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 ) > ( ) ;
4649
4750 int IBuildActions . RunProcess ( string cmd , string args , string ? workingDirectory , IDictionary < string , string > ? env , out IList < string > stdOut )
4851 {
@@ -135,6 +138,14 @@ string IBuildActions.PathCombine(params string[] parts)
135138
136139 string IBuildActions . GetFullPath ( string path ) => path ;
137140
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+
138149 void IBuildActions . WriteAllText ( string filename , string contents )
139150 {
140151 }
@@ -153,6 +164,18 @@ public string EnvironmentExpandEnvironmentVariables(string s)
153164 s = s . Replace ( $ "%{ kvp . Key } %", kvp . Value ) ;
154165 return s ;
155166 }
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+ }
156179 }
157180
158181 /// <summary>
@@ -213,6 +236,7 @@ CppAutobuilder CreateAutoBuilder(bool isWindows,
213236 Actions . GetEnvironmentVariable [ $ "CODEQL_EXTRACTOR_{ codeqlUpperLanguage } _SOURCE_ARCHIVE_DIR"] = "" ;
214237 Actions . GetEnvironmentVariable [ $ "CODEQL_EXTRACTOR_{ codeqlUpperLanguage } _ROOT"] = $@ "C:\codeql\{ codeqlUpperLanguage . ToLowerInvariant ( ) } ";
215238 Actions . GetEnvironmentVariable [ "CODEQL_JAVA_HOME" ] = @"C:\codeql\tools\java" ;
239+ Actions . GetEnvironmentVariable [ "CODEQL_PLATFORM" ] = "win64" ;
216240 Actions . GetEnvironmentVariable [ "SEMMLE_DIST" ] = @"C:\odasa" ;
217241 Actions . GetEnvironmentVariable [ "SEMMLE_JAVA_HOME" ] = @"C:\odasa\tools\java" ;
218242 Actions . GetEnvironmentVariable [ "SEMMLE_PLATFORM_TOOLS" ] = @"C:\odasa\tools" ;
@@ -273,7 +297,8 @@ public void TestDefaultCppAutobuilder()
273297 [ Fact ]
274298 public void TestCppAutobuilderSuccess ( )
275299 {
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 ;
277302 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 ;
278303 Actions . RunProcessOut [ @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe -prerelease -legacy -property installationPath" ] = "" ;
279304 Actions . RunProcess [ @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe -prerelease -legacy -property installationPath" ] = 1 ;
@@ -286,11 +311,13 @@ public void TestCppAutobuilderSuccess()
286311 Actions . FileExists [ @"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" ] = true ;
287312 Actions . EnumerateFiles [ @"C:\Project" ] = "foo.cs\n test.slx" ;
288313 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" ) ) ;
289316
290317 var autobuilder = CreateAutoBuilder ( true ) ;
291318 var solution = new TestSolution ( @"C:\Project\test.sln" ) ;
292319 autobuilder . ProjectsOrSolutionsToBuild . Add ( solution ) ;
293- TestAutobuilderScript ( autobuilder , 0 , 2 ) ;
320+ TestAutobuilderScript ( autobuilder , 0 , 3 ) ;
294321 }
295322 }
296323}
0 commit comments