24
24
using static Nuke . Common . Tools . DotNet . DotNetTasks ;
25
25
using static Nuke . Common . Tools . Xunit . XunitTasks ;
26
26
using static Nuke . Common . Tools . VSWhere . VSWhereTasks ;
27
+ using System . IO . Compression ;
27
28
28
29
/*
29
30
Before editing this file, install support plugin for your IDE,
@@ -111,8 +112,20 @@ IReadOnlyCollection<Output> MsBuildCommon(
111
112
112
113
Target Clean => _ => _ . Executes ( ( ) =>
113
114
{
114
- Parameters . BuildDirs . ForEach ( DeleteDirectory ) ;
115
- Parameters . BuildDirs . ForEach ( EnsureCleanDirectory ) ;
115
+ void safe ( Action action )
116
+ {
117
+ try
118
+ {
119
+ action ( ) ;
120
+ }
121
+ catch ( Exception e ) { Logger . Warn ( e ) ; }
122
+ }
123
+ //helps local dev builds
124
+ void deldir ( string dir ) => safe ( ( ) => DeleteDirectory ( dir ) ) ;
125
+ void cleandir ( string dir ) => safe ( ( ) => EnsureCleanDirectory ( dir ) ) ;
126
+
127
+ Parameters . BuildDirs . ForEach ( deldir ) ;
128
+ Parameters . BuildDirs . ForEach ( cleandir ) ;
116
129
EnsureCleanDirectory ( Parameters . ArtifactsDir ) ;
117
130
EnsureCleanDirectory ( Parameters . NugetIntermediateRoot ) ;
118
131
EnsureCleanDirectory ( Parameters . NugetRoot ) ;
@@ -155,6 +168,7 @@ bool IsDotnetCoreOnlyBuild()
155
168
156
169
Target Compile => _ => _
157
170
. DependsOn ( Clean , CompileNative )
171
+ . DependsOn ( DownloadAvaloniaNativeLib )
158
172
. DependsOn ( CompileHtmlPreviewer )
159
173
. Executes ( async ( ) =>
160
174
{
@@ -289,7 +303,7 @@ void RunCoreTest(string projectName)
289
303
. Executes ( ( ) =>
290
304
{
291
305
RunCoreTest ( "Avalonia.Skia.RenderTests" ) ;
292
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
306
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && Nuke . Common . CI . TeamCity . TeamCity . Instance == null ) // no direct2d tests on teamcity - they fail?
293
307
RunCoreTest ( "Avalonia.Direct2D1.RenderTests" ) ;
294
308
} ) ;
295
309
@@ -334,6 +348,46 @@ void RunCoreTest(string projectName)
334
348
Zip ( data . ZipTargetControlCatalogNetCoreDir , pathToPublish ) ;
335
349
} ) ;
336
350
351
+ Target UpdateTeamCityVersion => _ => _
352
+ . Executes ( ( ) =>
353
+ {
354
+ Nuke . Common . CI . TeamCity . TeamCity . Instance ? . SetBuildNumber ( Parameters . Version ) ;
355
+ } ) ;
356
+
357
+ Target DownloadAvaloniaNativeLib => _ => _
358
+ . After ( Clean )
359
+ . OnlyWhenStatic ( ( ) => EnvironmentInfo . IsWin )
360
+ . Executes ( ( ) =>
361
+ {
362
+ //download avalonia native osx binary, so we don't have to build it on osx
363
+ //expected to be -> Build/Products/Release/libAvalonia.Native.OSX.dylib
364
+ //Avalonia.Native.0.10.0-preview5.nupkg
365
+ string nugetversion = "0.10.12" ;
366
+
367
+ var nugetdir = RootDirectory + "/Build/Products/Release/" ;
368
+ //string nugeturl = "https://www.myget.org/F/avalonia-ci/api/v2/package/Avalonia.Native/";
369
+ string nugeturl = "https://www.nuget.org/api/v2/package/Avalonia.Native/" ;
370
+
371
+ nugeturl += nugetversion ;
372
+
373
+ //myget packages are expiring so i've made a copy here
374
+ //google drive file share https://drive.google.com/open?id=1HK-XfBZRunGpxXcGUUEC-64H9T_n9cIJ
375
+ //nugeturl = "https://drive.google.com/uc?id=1HK-XfBZRunGpxXcGUUEC-64H9T_n9cIJ&export=download";//Avalonia.Native.0.9.999-cibuild0005383-beta
376
+ //nugeturl = "https://drive.google.com/uc?id=1fNKJ-KNsPtoi_MYVJZ0l4hbgHAkLMYZZ&export=download";//Avalonia.Native.0.9.2.16.nupkg custom build
377
+ //nugeturl = "https://drive.google.com/uc?id=13ek3xvXA__GUgQFeAkemqE0lxiXiTr5s&export=download";//Avalonia.Native.0.10.0.8.nupkg custom build
378
+ //nugeturl = "https://drive.google.com/uc?id=13n_Ql64s7eXncUQx_FagU4z5X-tBhtxC&export=download";//Avalonia.Native.0.10.0.16-rc1.nupkg custom build
379
+
380
+ string nugetname = $ "Avalonia.Native.{ nugetversion } ";
381
+ string nugetcontentsdir = Path . Combine ( nugetdir , nugetname ) ;
382
+ string nugetpath = nugetcontentsdir + ".nupkg" ;
383
+ Logger . Info ( $ "Downloading { nugetname } from { nugeturl } ") ;
384
+ Nuke . Common . IO . HttpTasks . HttpDownloadFile ( nugeturl , nugetpath ) ;
385
+ System . IO . Compression . ZipFile . ExtractToDirectory ( nugetpath , nugetcontentsdir , true ) ;
386
+
387
+ CopyFile ( nugetcontentsdir + @"/runtimes/osx/native/libAvaloniaNative.dylib" , nugetdir + "libAvalonia.Native.OSX." +
388
+ "dylib" , Nuke . Common . IO . FileExistsPolicy . Overwrite ) ;
389
+ } ) ;
390
+
337
391
Target CreateIntermediateNugetPackages => _ => _
338
392
. DependsOn ( Compile )
339
393
. After ( RunTests )
@@ -342,6 +396,7 @@ void RunCoreTest(string projectName)
342
396
if ( Parameters . IsRunningOnWindows && ! IsDotnetCoreOnlyBuild ( ) )
343
397
344
398
MsBuildCommon ( Parameters . MSBuildSolution , c => c
399
+ . AddProperty ( "PackAvaloniaNative" , "true" )
345
400
. AddTargets ( "Pack" ) ) ;
346
401
else
347
402
DotNetPack ( c => c
@@ -364,6 +419,75 @@ void RunCoreTest(string projectName)
364
419
throw new Exception ( "Package merge failed" ) ;
365
420
} ) ;
366
421
422
+ private static string GetNuGetNugetPackagesDir ( )
423
+ {
424
+ string env ( string v ) => Environment . GetEnvironmentVariable ( v ) ;
425
+ return env ( "NUGET_PACKAGES" ) ?? Path . Combine ( env ( "USERPROFILE" ) ?? env ( "HOME" ) , ".nuget/packages" ) ;
426
+ }
427
+
428
+ Target PublishLocalNugetPackages => _ => _
429
+ . Executes ( ( ) =>
430
+ {
431
+ string nugetPackagesDir = GetNuGetNugetPackagesDir ( ) ;
432
+
433
+ //clean up often locked dlls from avalonia packages
434
+ var preCleanUpDirs = new [ ]
435
+ {
436
+ "Avalonia/{0}/tools/" , //Avalonia.Build.Tasks.dll
437
+ "Avalonia/{0}/lib/" ,
438
+ "Avalonia.Remote.Protocol/{0}/lib/" //Avalonia.Remote.Protocol.dll
439
+ } ;
440
+ foreach ( var pattern in preCleanUpDirs )
441
+ {
442
+ var path = Path . Combine ( nugetPackagesDir , string . Format ( pattern , Parameters . Version ) ) ;
443
+ foreach ( var filePath in Directory . GetFiles ( path , "*.*" , SearchOption . AllDirectories ) )
444
+ {
445
+ try
446
+ {
447
+ DeleteFile ( filePath ) ;
448
+ }
449
+ catch ( Exception e )
450
+ {
451
+ Logger . Warn ( $ "Will rename! Failed delete { e . Message } for { filePath } ") ;
452
+ if ( ! filePath . EndsWith ( ".old" ) )
453
+ RenameFile ( filePath , $ "{ filePath } .{ Guid . NewGuid ( ) } .old", Nuke . Common . IO . FileExistsPolicy . Overwrite ) ;
454
+ }
455
+ }
456
+ }
457
+
458
+ foreach ( var package in Directory . EnumerateFiles ( Parameters . NugetRoot ) )
459
+ {
460
+ var packName = Path . GetFileName ( package ) ;
461
+ string packgageFolderName = packName . Replace ( $ ".{ Parameters . Version } .nupkg", "" ) ;
462
+ var nugetCaheFolder = Path . Combine ( nugetPackagesDir , packgageFolderName , Parameters . Version ) ;
463
+
464
+ //clean directory is not good, nuget will noticed and clean our files
465
+ //EnsureCleanDirectory(nugetCaheFolder);
466
+ EnsureExistingDirectory ( nugetCaheFolder ) ;
467
+
468
+ CopyFile ( package , nugetCaheFolder + "/" + packName , Nuke . Common . IO . FileExistsPolicy . Skip ) ;
469
+
470
+ Logger . Info ( $ "Extracting to { nugetCaheFolder } , { package } ") ;
471
+
472
+ ZipFile . ExtractToDirectory ( package , nugetCaheFolder , true ) ;
473
+ }
474
+ } ) ;
475
+
476
+ Target ClearLocalNugetPackages => _ => _
477
+ . Executes ( ( ) =>
478
+ {
479
+ string nugetPackagesDir = GetNuGetNugetPackagesDir ( ) ;
480
+
481
+ foreach ( var package in Directory . EnumerateFiles ( Parameters . NugetRoot ) )
482
+ {
483
+ var packName = Path . GetFileName ( package ) ;
484
+ string packgageFolderName = packName . Replace ( $ ".{ Parameters . Version } .nupkg", "" ) ;
485
+ var nugetCaheFolder = Path . Combine ( nugetPackagesDir , packgageFolderName , Parameters . Version ) ;
486
+
487
+ EnsureCleanDirectory ( nugetCaheFolder ) ;
488
+ }
489
+ } ) ;
490
+
367
491
Target RunTests => _ => _
368
492
. DependsOn ( RunCoreLibsTests )
369
493
. DependsOn ( RunRenderTests )
0 commit comments