forked from scylladb/cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appveyor.ps1
829 lines (752 loc) · 39.1 KB
/
appveyor.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
<#
Copyright (c) DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>
Function Get-Commit-Sha {
return $($Env:APPVEYOR_REPO_COMMIT.SubString(0,7))
}
Function Get-OpenSSL-Version {
$openssl_version = "$($(Get-ChildItem Env:"OPENSSL_$($Env:OPENSSL_MAJOR_MINOR.Replace(".", "_"))_VERSION").Value)"
return $openssl_version
}
Function Bison-Version-Information {
If (Get-Command "bison" -ErrorAction SilentlyContinue) {
$temporary_file = New-TemporaryFile
Start-Process -FilePath bison -ArgumentList "--version" -RedirectStandardOutput $($temporary_file) -Wait -NoNewWindow
$output = Get-Content "$($temporary_file)" -Raw
Write-Host "$($output.Trim())" -BackgroundColor DarkCyan
Remove-Item $temporary_file
} Else {
Write-Host "Bison is not available" -BackgroundColor DarkRed
}
}
Function Perl-Version-Information {
If (Get-Command "perl" -ErrorAction SilentlyContinue) {
$temporary_file = New-TemporaryFile
Start-Process -FilePath perl -ArgumentList "--version" -RedirectStandardOutput $($temporary_file) -Wait -NoNewWindow
$output = Get-Content "$($temporary_file)" -Raw
Write-Host "$($output.Trim())" -BackgroundColor DarkGray
Remove-Item $temporary_file
} Else {
Write-Host "Perl is not available" -BackgroundColor DarkRed
}
}
Function CMake-Version-Information {
If (Get-Command "cmake" -ErrorAction SilentlyContinue) {
$temporary_file = New-TemporaryFile
Start-Process -FilePath cmake -ArgumentList "--version" -RedirectStandardOutput $($temporary_file) -Wait -NoNewWindow
$output = Get-Content "$($temporary_file)" -Raw
Write-Host "$($output.Trim())" -BackgroundColor DarkBlue
Remove-Item $temporary_file
} Else {
Write-Host "CMake is not available" -BackgroundColor DarkRed
}
}
Function Build-Configuration-Information {
$output = @"
Visual Studio: $($Env:CMAKE_GENERATOR.Split(" ")[-2]) [$($Env:CMAKE_GENERATOR.Split(" ")[-1])]
Architecture: $($Env:Platform)
libssh2: v$($Env:LIBSSH2_VERSION)
libuv: v$($Env:LIBUV_VERSION)
OpenSSL: v$(Get-OpenSSL-Version)
zlib: v$($Env:ZLIB_VERSION)
Build Number: $($Env:APPVEYOR_BUILD_NUMBER)
Branch: $($Env:APPVEYOR_REPO_BRANCH)
SHA: $(Get-Commit-Sha)
"@
Write-Host "$($output)" -BackgroundColor DarkGreen
}
Function Hardware-Information {
$computer_system = Get-CimInstance CIM_ComputerSystem
$operating_system = Get-CimInstance CIM_OperatingSystem
$processor = Get-CimInstance CIM_Processor
$logical_disk = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$capacity = "{0:N2}" -f ($logical_disk.Size / 1GB)
$free_space = "{0:N2}" -f ($logical_disk.FreeSpace / 1GB)
$free_space_percentage = "{0:P2}" -f ($logical_disk.FreeSpace / $logical_disk.Size)
$ram = "{0:N2}" -f ($computer_system.TotalPhysicalMemory / 1GB)
# Determine if hyper-threading is enabled in order to display number of cores
$number_of_cores = "$($processor.NumberOfCores)"
If ($processor.NumberOfCores -lt $processor.NumberOfLogicalProcessors) {
$number_of_cores = "$($processor.NumberOfLogicalProcessors) (Hyper-Threading)"
}
$hardware_information = @"
Hardware Information for $($computer_system.Name):
Operating System: $($operating_system.caption) (Version: $($operating_system.Version))
CPU: $($processor.Name)
Number of Cores: $($number_of_cores)
HDD Capacity: $($capacity) GB
HDD Free Capacity: $($free_space_percentage) ($($free_space) GB)
RAM: $($ram) GB
"@
Write-Host "$($hardware_information)" -BackgroundColor DarkMagenta
}
Function Environment-Information {
Write-Host "Visual Studio Environment Variables:" -BackgroundColor DarkMagenta
Get-ChildItem Env:VS* | ForEach-Object {
Write-Host " $($_.Name) = $($_.Value)" -BackgroundColor DarkMagenta
}
}
Function Initialize-Build-Environment {
# Get the versions for the third party dependencies
$libssh2_version = $Env:LIBSSH2_VERSION
$libuv_version = $Env:LIBUV_VERSION
$openssl_version = Get-OpenSSL-Version
$Env:OPENSSL_VERSION = $openssl_version
$zlib_version = $Env:ZLIB_VERSION
$kerberos_version = "4.1"
$bison_version = "2.4.1"
$perl_version = "5.26.2.1"
# Determine the platform and create associate environment variables
$Env:CMAKE_PLATFORM = $Env:Platform
$lib_architecture = "lib64"
$windows_architecture = "win64"
# Determine which header file to use for determine driver version
$driver_header_file = "cassandra.h"
$driver_archive_prefix = "cassandra"
If ($Env:DRIVER_TYPE -Like "dse") {
$driver_header_file = "dse.h"
$driver_archive_prefix = "dse"
}
# Get the driver version number from the header file
$version = @()
Get-Content "$($Env:APPVEYOR_BUILD_FOLDER)/include/$($driver_header_file)" | ForEach-Object {
If ($_ -Match "#define .*_VERSION_.*") {
$token = $_.Split(" ")[-1].Replace("`"", "")
If ($token) {
$version += , $token
}
}
}
$Env:DRIVER_VERSION = "$($version[0]).$($version[1]).$($version[2])"
If ($version.Length -eq 4) {
$Env:DRIVER_VERSION += "-$($version[3])"
}
# Generate the variables for use with third party dependencies
$bin_location_prefix = "C:/projects/dependencies/bin/"
$libs_location_prefix = "C:/projects/dependencies/libs/"
$dependencies_location_prefix = "$($libs_location_prefix)/$($Env:Platform)/$($Env:VISUAL_STUDIO_INTERNAL_VERSION)/"
$download_url_prefix = "https://raw.githubusercontent.com/mikefero/cpp-driver-msvc-libs/master"
# Generate the environment variables for use with the CMake FindXXX scripts
$Env:LIBUV_ROOT_DIR = "$($dependencies_location_prefix)/libuv-$($libuv_version)"
$Env:OPENSSL_BASE_DIR = "$($dependencies_location_prefix)/openssl-$($openssl_version)"
$Env:OPENSSL_ROOT_DIR = "$($Env:OPENSSL_BASE_DIR)/shared"
$Env:ZLIB_ROOT_DIR = "$($dependencies_location_prefix)/zlib-$($zlib_version)"
$Env:DRIVER_INSTALL_DIR = "C:/projects/driver/lib"
$Env:DRIVER_ARTIFACTS_DIR = "C:/projects/driver/artifacts"
$Env:DRIVER_ARTIFACTS_LOGS_DIR = "$($Env:DRIVER_ARTIFACTS_DIR)/logs"
# Generate the environment variables for the third party archives
$Env:KERBEROS_ARCHIVE = "kfw-$($kerberos_version)-$($windows_architecture)-msvc100.zip"
$Env:LIBUV_ARTIFACT_ARCHIVE = "libuv-$($libuv_version)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
$Env:OPENSSL_ARTIFACT_ARCHIVE = "openssl-$($openssl_version)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
$Env:ZLIB_ARTIFACT_ARCHIVE = "zlib-$($zlib_version)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
# Generate default environment variables for per commit builds
If ($Env:APPVEYOR_BUILD_WORKER_IMAGE -Like "Visual Studio 2019") {
$boost_version_directory_suffix = "1_71_0"
} Else {
$boost_version_directory_suffix = "1_69_0"
}
$visual_studio_version = "$($Env:VISUAL_STUDIO_INTERNAL_VERSION.Insert(2, "."))"
# Generate the default Boost environment variables
$Env:BOOST_ROOT = "C:/Libraries/boost_$($boost_version_directory_suffix)"
$Env:BOOST_INCLUDEDIR = "$($Env:BOOST_ROOT)/include"
# Generate the Kerberos environment variables
$Env:KERBEROS_DOWNLOAD_URL = "$($download_url_prefix)/kerberos/$($kerberos_version)/$($Env:KERBEROS_ARCHIVE)"
$Env:KERBEROS_EXTRACT_DIR = "$($libs_location_prefix)/$($Env:Platform)/100/kfw-$($kerberos_version)"
$Env:KERBEROS_ROOT_DIR = "$($Env:KERBEROS_EXTRACT_DIR)/MIT/Kerberos"
# Generate the default libssh2 environment variables
$Env:LIBSSH2_ROOT_DIR = "$($dependencies_location_prefix)/libssh2-$($libssh2_version)"
# Generate the archive name for the driver test and examples artifacts
$build_version = "$($Env:APPVEYOR_BUILD_NUMBER)-$($Env:APPVEYOR_REPO_BRANCH)"
# TODO: Re-enable OpenSSL version appending if multiple OpenSSL versions are enabled
#$Env:DRIVER_ARTIFACT_EXAMPLES_ARCHIVE = "$($driver_archive_prefix)-cpp-driver-$($Env:DRIVER_VERSION)-examples-openssl-$($Env:OPENSSL_MAJOR_MINOR)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
#$Env:DRIVER_ARTIFACT_TESTS_ARCHIVE = "$($driver_archive_prefix)-cpp-driver-$($Env:DRIVER_VERSION)-tests-openssl-$($Env:OPENSSL_MAJOR_MINOR)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
$Env:DRIVER_ARTIFACT_EXAMPLES_ARCHIVE = "$($driver_archive_prefix)-cpp-driver-$($Env:DRIVER_VERSION)-examples-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
$Env:DRIVER_ARTIFACT_TESTS_ARCHIVE = "$($driver_archive_prefix)-cpp-driver-$($Env:DRIVER_VERSION)-tests-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
# Generate the archive name for the driver packaging
# TODO: Re-enable OpenSSL version appending if multiple OpenSSL versions are enabled
#$Env:DRIVER_ARTIFACT_ARCHIVE = "$($driver_archive_prefix)-cpp-driver-$($Env:DRIVER_VERSION)-openssl-$($Env:OPENSSL_MAJOR_MINOR)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
$Env:DRIVER_ARTIFACT_ARCHIVE = "$($driver_archive_prefix)-cpp-driver-$($Env:DRIVER_VERSION)-$($windows_architecture)-msvc$($Env:VISUAL_STUDIO_INTERNAL_VERSION).zip"
# Generate additional download/install environments for third party build requirements
$Env:BISON_BINARIES_ARCHIVE = "bison-$($bison_version)-bin.zip"
$Env:BISON_BINARIES_DOWNLOAD_URL = "http://downloads.sourceforge.net/gnuwin32/$($Env:BISON_BINARIES_ARCHIVE)"
$Env:BISON_DEPENDENCIES_ARCHIVE = "bison-$($bison_version)-dep.zip"
$Env:BISON_DEPENDENCIES_DOWNLOAD_URL = "http://downloads.sourceforge.net/gnuwin32/$($Env:BISON_DEPENDENCIES_ARCHIVE)"
$Env:BISON_ROOT_DIR = "$($bin_location_prefix)/bison-$($bison_version)"
$Env:PERL_STANDALONE_ARCHIVE = "strawberry-perl-$($perl_version)-64bit-portable.zip"
$Env:PERL_STANDALONE_DOWNLOAD_URL = "http://strawberryperl.com/download/$($perl_version)/$($Env:PERL_STANDALONE_ARCHIVE)"
$Env:PERL_ROOT_DIR = "$($bin_location_prefix)/perl-$($perl_version)"
# Update the PATH to include the third party build requirement tools (prepend)
$Env:PATH = "$($Env:BISON_ROOT_DIR)/bin;$($Env:PERL_ROOT_DIR)/perl/site/bin;$($Env:PERL_ROOT_DIR)/perl/bin;$($Env:PERL_ROOT_DIR)/c/bin;$($Env:KERBEROS_ROOT_DIR)/bin;$($Env:LIBUV_ROOT_DIR)/bin;$($Env:OPENSSL_ROOT_DIR)/bin;$($Env:PATH)"
}
Function Install-Driver-Environment {
# Remove pre-installed OpenSSL (resolve conflicts)
Remove-Item -Force -Recurse -Path "C:/OpenSSL-*"
# Determine if Bison needs to be installed (cached)
If (-Not (Test-Path -Path "$($Env:BISON_ROOT_DIR)")) {
# Download and extract the dependency
try {
Write-Host "Downloading and extracting Bison for Windows"
New-Item -ItemType Directory -Force -Path "$($Env:BISON_ROOT_DIR)" | Out-Null
$is_download_complete = $False
$retries = 0
do {
try {
Invoke-WebRequest -Uri "$($Env:BISON_BINARIES_DOWNLOAD_URL)" -OutFile $Env:BISON_BINARIES_ARCHIVE -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
$is_download_complete = $True
} catch {
Write-Host "Error downloading Bison binaries; sleeping for 10 seconds ... " -NoNewLine -BackgroundColor DarkRed
Start-Sleep -s 10
Write-Host "done." -BackgroundColor DarkRed
Write-Host "Retrying Bison binaries download"
}
$retries++
} while($is_download_complete -eq $False -and $retries -lt 10)
$argument_list = @"
-o"$($Env:BISON_ROOT_DIR)" x "$($Env:BISON_BINARIES_ARCHIVE)"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Remove-Item -Force -Recurse -Path "$($Env:BISON_ROOT_DIR)"
Throw "Failed to extract Bison binaries"
}
$is_download_complete = $False
$retries = 0
do {
try {
Invoke-WebRequest -Uri "$($Env:BISON_DEPENDENCIES_DOWNLOAD_URL)" -OutFile $Env:BISON_DEPENDENCIES_ARCHIVE -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
$is_download_complete = $True
} catch {
Write-Host "Error downloading Bison dependencies; sleeping for 10 seconds ... " -NoNewLine -BackgroundColor DarkRed
Start-Sleep -s 10
Write-Host "done." -BackgroundColor DarkRed
Write-Host "Retrying Bison dependencies download"
}
$retries++
} while($is_download_complete -eq $False -and $retries -lt 10)
$argument_list = @"
-aoa -o"$($Env:BISON_ROOT_DIR)" x "$($Env:BISON_DEPENDENCIES_ARCHIVE)"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Remove-Item -Force -Recurse -Path "$($Env:BISON_ROOT_DIR)"
Throw "Failed to extract Bison dependencies"
}
# Delete the binary archive
Remove-Item $Env:BISON_BINARIES_ARCHIVE
Remove-Item $Env:BISON_DEPENDENCIES_ARCHIVE
} catch {
Remove-Item -Force -Recurse -Path "$($Env:BISON_ROOT_DIR)"
Throw $PSItem
}
}
# Display the Bison version information
Bison-Version-Information
# Determine if Strawberry Perl needs to be installed (cached)
If (-Not (Test-Path -Path "$($Env:PERL_ROOT_DIR)")) {
# Download and extract the dependency
try {
Write-Host "Downloading and extracting Strawberry Perl for Windows"
New-Item -ItemType Directory -Force -Path "$($Env:PERL_ROOT_DIR)" | Out-Null
If ($Env:APPVEYOR -Like "True") {
Start-FileDownload "$($Env:PERL_STANDALONE_DOWNLOAD_URL)" -FileName $Env:PERL_STANDALONE_ARCHIVE
} Else {
curl.exe -o "$($Env:PERL_STANDALONE_ARCHIVE)" "$($Env:PERL_STANDALONE_DOWNLOAD_URL)"
}
$argument_list = @"
-o"$($Env:PERL_ROOT_DIR)" x "$($Env:PERL_STANDALONE_ARCHIVE)"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Remove-Item -Force -Recurse -Path "$($Env:PERL_ROOT_DIR)"
Throw "Failed to extract Strawberry Perl"
}
# Delete the binary archive
Remove-Item $Env:PERL_STANDALONE_ARCHIVE
} catch {
Remove-Item -Force -Recurse -Path "$($Env:PERL_ROOT_DIR)"
Throw $PSItem
}
}
# Display the Perl and CMake version information
Perl-Version-Information
CMake-Version-Information
# Determine the location of the CMake modules (external projects)
$cmake_modules_dir = "$($Env:APPVEYOR_BUILD_FOLDER -Replace `"\\`", `"/`")/"
If ($Env:DRIVER_TYPE -Like "dse") {
$cmake_modules_dir += "cpp-driver/"
}
$cmake_modules_dir += "cmake"
# Build and install the dependencies (if needed; cached)
$dependencies_build_location_prefix = "C:/projects/dependencies/build/"
If (-Not (Test-Path -Path "$($Env:LIBUV_ROOT_DIR)/lib")) { # lib directory checked due to external project being CMake (automatically creates root directory)
New-Item -ItemType Directory -Force -Path "$($dependencies_build_location_prefix)/libuv" | Out-Null
Push-Location -Path "$($dependencies_build_location_prefix)/libuv"
$cmakelists_contents = @"
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(libuv)
set(PROJECT_DISPLAY_NAME "AppVeyor CI Build for libuv")
set(PROJECT_MODULE_DIR $cmake_modules_dir)
set(CMAKE_MODULE_PATH `${CMAKE_MODULE_PATH} `${PROJECT_MODULE_DIR})
include(ExternalProject-libuv)
set(GENERATED_SOURCE_FILE `${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
file(REMOVE `${GENERATED_SOURCE_FILE})
file(WRITE `${GENERATED_SOURCE_FILE} "int main () { return 0; }")
add_executable(`${PROJECT_NAME} `${GENERATED_SOURCE_FILE})
add_dependencies(`${PROJECT_NAME} `${LIBUV_LIBRARY_NAME})
"@
$cmakelists_contents | Out-File -FilePath "CMakeLists.txt" -Encoding Utf8 -Force
Write-Host "Configuring libuv"
cmake -G "$($Env:CMAKE_GENERATOR)" -A $Env:CMAKE_PLATFORM -DBUILD_SHARED_LIBS=On "-DLIBUV_VERSION=$($Env:LIBUV_VERSION)" "-DLIBUV_INSTALL_PREFIX=$($Env:LIBUV_ROOT_DIR)" .
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "libuv Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "libuv Error Log"
}
Pop-Location
Throw "Failed to configure libuv for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Write-Host "Building and Installing libuv"
cmake --build . --config RelWithDebInfo
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "libuv Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "libuv Error Log"
}
Pop-Location
Throw "Failed to build libuv for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Pop-Location
}
$library_types = ("shared", "static")
$library_types | foreach {
If (-Not (Test-Path -Path "$($Env:OPENSSL_BASE_DIR)/$_")) {
New-Item -ItemType Directory -Force -Path "$($dependencies_build_location_prefix)/openssl/$_" | Out-Null
Push-Location -Path "$($dependencies_build_location_prefix)/openssl/$_"
$cmakelists_contents = @"
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(OpenSSL)
set(PROJECT_DISPLAY_NAME "AppVeyor CI Build for OpenSSL")
set(PROJECT_MODULE_DIR $cmake_modules_dir)
set(CMAKE_MODULE_PATH `${CMAKE_MODULE_PATH} `${PROJECT_MODULE_DIR})
include(ExternalProject-OpenSSL)
set(GENERATED_SOURCE_FILE `${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
file(REMOVE `${GENERATED_SOURCE_FILE})
file(WRITE `${GENERATED_SOURCE_FILE} "int main () { return 0; }")
add_executable(`${PROJECT_NAME} `${GENERATED_SOURCE_FILE})
add_dependencies(`${PROJECT_NAME} `${OPENSSL_LIBRARY_NAME})
"@
$cmakelists_contents | Out-File -FilePath "CMakeLists.txt" -Encoding Utf8 -Force
Write-Host "Configuring OpenSSL [$_]"
$shared_libs = "Off"
if ("$_" -Like "shared") {
$shared_libs = "On"
}
cmake -G "$($Env:CMAKE_GENERATOR)" -A $Env:CMAKE_PLATFORM "-DBUILD_SHARED_LIBS=$($shared_libs)" "-DOPENSSL_VERSION=$($Env:OPENSSL_VERSION)" "-DOPENSSL_INSTALL_PREFIX=$($Env:OPENSSL_BASE_DIR)/$_" .
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "OpenSSL Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "OpenSSL Error Log"
}
Pop-Location
Throw "Failed to configure OpenSSL for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Write-Host "Building and Installing OpenSSL [$_]"
cmake --build . --config RelWithDebInfo
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "OpenSSL Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "OpenSSL Error Log"
}
Pop-Location
Throw "Failed to build OpenSSL for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Pop-Location
}
}
If (-Not (Test-Path -Path "$($Env:ZLIB_ROOT_DIR)/lib")) {
New-Item -ItemType Directory -Force -Path "$($dependencies_build_location_prefix)/zlib" | Out-Null
Push-Location -Path "$($dependencies_build_location_prefix)/zlib"
$cmakelists_contents = @"
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(zlib)
set(PROJECT_DISPLAY_NAME "AppVeyor CI Build for zlib")
set(PROJECT_MODULE_DIR $cmake_modules_dir)
set(CMAKE_MODULE_PATH `${CMAKE_MODULE_PATH} `${PROJECT_MODULE_DIR})
include(ExternalProject-zlib)
set(GENERATED_SOURCE_FILE `${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
file(REMOVE `${GENERATED_SOURCE_FILE})
file(WRITE `${GENERATED_SOURCE_FILE} "int main () { return 0; }")
add_executable(`${PROJECT_NAME} `${GENERATED_SOURCE_FILE})
add_dependencies(`${PROJECT_NAME} `${ZLIB_LIBRARY_NAME})
"@
$cmakelists_contents | Out-File -FilePath "CMakeLists.txt" -Encoding Utf8 -Force
Write-Host "Configuring zlib"
cmake -G "$($Env:CMAKE_GENERATOR)" -A $Env:CMAKE_PLATFORM -DBUILD_SHARED_LIBS=On "-DZLIB_VERSION=$($Env:ZLIB_VERSION)" "-DZLIB_INSTALL_PREFIX=$($Env:ZLIB_ROOT_DIR)" .
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "zlib Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "zlib Error Log"
}
Pop-Location
Throw "Failed to configure zlib for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Write-Host "Building and Installing zlib"
cmake --build . --config RelWithDebInfo
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "zlib Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "zlib Error Log"
}
Pop-Location
Throw "Failed to build zlib for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Pop-Location
}
# Determine if Kerberos for Windows should be installed (cached)
If (-Not (Test-Path -Path "$($Env:KERBEROS_ROOT_DIR)")) {
# Download and extract the dependency
try {
Write-Host "Downloading and extracting Kerberos for Windows"
New-Item -ItemType Directory -Force -Path "$($Env:KERBEROS_ROOT_DIR)" | Out-Null
If ($Env:APPVEYOR -Like "True") {
Start-FileDownload "$($Env:KERBEROS_DOWNLOAD_URL)" -FileName $Env:KERBEROS_ARCHIVE
} Else {
curl.exe -o "$($Env:KERBEROS_ARCHIVE)" "$($Env:KERBEROS_DOWNLOAD_URL)"
}
$argument_list = @"
-o"$($Env:KERBEROS_EXTRACT_DIR)" x "$($Env:KERBEROS_ARCHIVE)"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Remove-Item -Force -Recurse -Path "$($Env:KERBEROS_EXTRACT_DIR)"
Throw "Failed to extract Kerberos"
}
# Delete the binary archive
Remove-Item $Env:KERBEROS_ARCHIVE
} catch {
Remove-Item -Force -Recurse -Path "$($Env:KERBEROS_EXTRACT_DIR)"
Throw $PSItem
}
}
# Determine if libssh2 should be installed (cached)
If (-Not (Test-Path -Path "$($Env:LIBSSH2_ROOT_DIR)/lib")) { # lib directory checked due to external project being CMake (automatically creates root directory)
New-Item -ItemType Directory -Force -Path "$($dependencies_build_location_prefix)/libssh2" | Out-Null
Push-Location -Path "$($dependencies_build_location_prefix)/libssh2"
$cmakelists_contents = @"
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(libssh2)
set(PROJECT_DISPLAY_NAME "AppVeyor CI Build for libssh2")
set(PROJECT_MODULE_DIR $cmake_modules_dir)
set(CMAKE_MODULE_PATH `${CMAKE_MODULE_PATH} `${PROJECT_MODULE_DIR})
include(ExternalProject-libssh2)
set(GENERATED_SOURCE_FILE `${CMAKE_CURRENT_BINARY_DIR}/main.cpp)
file(REMOVE `${GENERATED_SOURCE_FILE})
file(WRITE `${GENERATED_SOURCE_FILE} "int main () { return 0; }")
add_executable(`${PROJECT_NAME} `${GENERATED_SOURCE_FILE})
add_dependencies(`${PROJECT_NAME} `${LIBSSH2_LIBRARY_NAME})
"@
$cmakelists_contents | Out-File -FilePath "CMakeLists.txt" -Encoding Utf8 -Force
Write-Host "Configuring libssh2"
cmake -G "$($Env:CMAKE_GENERATOR)" -A $Env:CMAKE_PLATFORM "-DLIBSSH2_VERSION=$($Env:LIBSSH2_VERSION)" "-DLIBSSH2_INSTALL_PREFIX=$($Env:LIBSSH2_ROOT_DIR)" .
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "libssh2 Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "libssh2 Error Log"
}
Pop-Location
Throw "Failed to configure libssh2 for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Write-Host "Building and Installing libssh2"
cmake --build . --config RelWithDebInfo
If ($LastExitCode -ne 0) {
If (Test-Path -Path "build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeOutput.log" -DeploymentName "libssh2 Output Log"
}
If (Test-Path -Path "build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "build/CMakeFiles/CMakeError.log" -DeploymentName "libssh2 Error Log"
}
Pop-Location
Throw "Failed to build libssh2 for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Pop-Location
}
# Archive any dependency builds logs and perform cleanup
Get-ChildItem -File -Filter "*.log" -Recurse -Path "C:/projects/dependencies/build" | ForEach-Object {
If ($_.FullName.ToLower() -Match "-stamp" -And
$_.Length -gt 0kb) {
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_LOGS_DIR)" | Out-Null
Copy-Item -Force -Path "$($_.FullName)" "$($Env:DRIVER_ARTIFACTS_LOGS_DIR)"
}
}
}
Function Build-Driver {
# Ensure Boost atomic is used for Visual Studio 2010 (increased performance)
$use_boost_atomic = "Off"
If ($Env:VISUAL_STUDIO_INTERNAL_VERSION -Like "100") {
$use_boost_atomic = "On" # Enable Boost atomic usage
}
# Build the driver
$driver_type = "Apache Cassandra and DataStax Products"
If ($Env:DRIVER_TYPE -Like "dse") {
$driver_type = "DSE"
}
New-Item -ItemType Directory -Force -Path "$($Env:APPVEYOR_BUILD_FOLDER)/build"
Push-Location "$($Env:APPVEYOR_BUILD_FOLDER)/build"
Write-Host "Configuring DataStax C/C++ $($driver_type) Driver"
cmake -G "$($Env:CMAKE_GENERATOR)" -A $Env:CMAKE_PLATFORM "-D$($Env:DRIVER_TYPE)_MULTICORE_COMPILATION=On" "-D$($Env:DRIVER_TYPE)_USE_KERBEROS=On" "-D$($Env:DRIVER_TYPE)_USE_OPENSSL=On" "-D$($Env:DRIVER_TYPE)_USE_ZLIB=On" "-D$($Env:DRIVER_TYPE)_USE_BOOST_ATOMIC=$($use_boost_atomic)" "-D$($Env:DRIVER_TYPE)_BUILD_EXAMPLES=On" "-D$($Env:DRIVER_TYPE)_BUILD_TESTS=On" "-D$($Env:DRIVER_TYPE)_USE_LIBSSH2=On" "-DCMAKE_INSTALL_PREFIX=`"$($Env:DRIVER_INSTALL_DIR)`"" ..
If ($LastExitCode -ne 0) {
Pop-Location
Throw "Failed to configure DataStax C/C++ $($driver_type) Driver for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Write-Host "Building and Installing DataStax C/C++ $($driver_type) Driver"
cmake --build . --config RelWithDebInfo --target install
If ($LastExitCode -ne 0) {
Pop-Location
Throw "Failed to build DataStax C/C++ $($driver_type) Driver for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
Pop-Location
# Copy the binary artifacts
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/bin/examples" | Out-Null
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/bin/tests" | Out-Null
Get-ChildItem -File -Filter "*.exe" -Recurse -Path "$($Env:APPVEYOR_BUILD_FOLDER)/build" | ForEach-Object {
If ($_.FullName.ToLower() -Match "relwithdebinfo") {
$suffix="bin"
If ($_.FullName.ToLower() -Match "examples") {
$suffix+="/examples"
} ElseIf ($_.FullName.ToLower() -Match "test.*exe") {
$suffix+="/tests"
}
Copy-Item -Force -Path "$($_.FullName)" "$($Env:DRIVER_ARTIFACTS_DIR)/$($suffix)"
}
}
}
Function Execute-Driver-Unit-Tests {
# Update the PATH for the test executables to run with output
$Env:PATH = "$($Env:DRIVER_ARTIFACTS_DIR)/bin/tests;$($Env:PATH)"
# Execute the unit tests
$is_failure = $False
cassandra-unit-tests.exe --gtest_output=xml:"$($Env:DRIVER_ARTIFACTS_DIR)\bin\tests\unit-tests-gtest-results.xml"
If ($LastExitCode -ne 0) {
Throw "Error Executing Unit tests: Check tests tab or download from the artifacts"
}
}
Function Push-Driver-Unit-Tests-Results {
# Push the unit test(s) results
If ($Env:APPVEYOR -Like "True") {
$web_client = New-Object "System.Net.WebClient"
Get-ChildItem -File -Filter "*.xml" -Path "$($Env:DRIVER_ARTIFACTS_DIR)/bin/tests" -Recurse | ForEach-Object {
$web_client.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($Env:APPVEYOR_JOB_ID)", (Resolve-Path "$($_.FullName)"))
}
}
}
Function Package-Artifacts {
# Package the driver artifacts
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)" | Out-Null
$argument_list = @"
a -tzip "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_ARCHIVE)" -r "$($Env:DRIVER_INSTALL_DIR)/*"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Throw "Failed to archive driver for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
# Package the driver example and test artifacts
$argument_list = @"
a -tzip "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_EXAMPLES_ARCHIVE)" -r "$($Env:DRIVER_ARTIFACTS_DIR)/bin/examples/*"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Throw "Failed to archive driver examples for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
$argument_list = @"
a -tzip "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_TESTS_ARCHIVE)" -r "$($Env:DRIVER_ARTIFACTS_DIR)/bin/tests/*.exe"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Throw "Failed to archive driver tests for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
# Clean up the library dependency directories for libuv packaging
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/libuv" | Out-Null
Copy-Item -Force -Recurse -Path "$($Env:LIBUV_ROOT_DIR)/*" "$($Env:DRIVER_ARTIFACTS_DIR)/libuv" | Out-Null
$argument_list = @"
a -tzip "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:LIBUV_ARTIFACT_ARCHIVE)" -r "$($Env:DRIVER_ARTIFACTS_DIR)/libuv/*"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Throw "Failed to archive libuv for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
# Clean up the library dependency directories for OpenSSL packaging
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl" | Out-Null
Copy-Item -Force -Recurse -Path "$($Env:OPENSSL_BASE_DIR)/*" "$($Env:DRIVER_ARTIFACTS_DIR)/openssl" | Out-Null
Move-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/static/LICENSE" "$($Env:DRIVER_ARTIFACTS_DIR)/openssl" | Out-Null
Move-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/static/include" "$($Env:DRIVER_ARTIFACTS_DIR)/openssl" | Out-Null
Move-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/static/openssl.cnf" "$($Env:DRIVER_ARTIFACTS_DIR)/openssl" | Out-Null
If (Test-Path -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/static/openssl.cnf.dist") {
Move-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/static/openssl.cnf.dist" "$($Env:DRIVER_ARTIFACTS_DIR)/openssl" | Out-Null
}
Remove-Item -Force -Recurse -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/shared/include" | Out-Null
Remove-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/shared/LICENSE" | Out-Null
Remove-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/shared/openssl.cnf" | Out-Null
If (Test-Path -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/shared/openssl.cnf.dist") {
Remove-Item -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/shared/openssl.cnf.dist" | Out-Null
}
$argument_list = @"
a -tzip "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:OPENSSL_ARTIFACT_ARCHIVE)" -r "$($Env:DRIVER_ARTIFACTS_DIR)/openssl/*"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Throw "Failed to archive OpenSSL for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
# Clean up the library dependency directories for zlib packaging
New-Item -ItemType Directory -Force -Path "$($Env:DRIVER_ARTIFACTS_DIR)/zlib" | Out-Null
Copy-Item -Force -Recurse -Path "$($Env:ZLIB_ROOT_DIR)/*" "$($Env:DRIVER_ARTIFACTS_DIR)/zlib" | Out-Null
$argument_list = @"
a -tzip "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:ZLIB_ARTIFACT_ARCHIVE)" -r "$($Env:DRIVER_ARTIFACTS_DIR)/zlib/*"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -ne 0) {
Throw "Failed to archive zlib for MSVC $($Env:VISUAL_STUDIO_INTERNAL_VERSION)-$($Env:Platform)"
}
}
Function Push-Artifacts {
If ($Env:APPVEYOR -Like "True") {
$driver_type = "Apache Cassandra and DataStax Products"
If ($Env:DRIVER_TYPE -Like "dse") {
$driver_type = "DSE"
}
Push-AppveyorArtifact "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_ARCHIVE)" -DeploymentName "DataStax C/C++ $($driver_type) Driver"
Push-AppveyorArtifact "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_EXAMPLES_ARCHIVE)" -DeploymentName "DataStax C/C++ $($driver_type) Driver Examples"
Push-AppveyorArtifact "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_TESTS_ARCHIVE)" -DeploymentName "DataStax C/C++ $($driver_type) Driver Tests"
Push-AppveyorArtifact "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:LIBUV_ARTIFACT_ARCHIVE)" -DeploymentName "libuv v$($Env:LIBUV_VERSION)"
Push-AppveyorArtifact "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:OPENSSL_ARTIFACT_ARCHIVE)" -DeploymentName "OpenSSL v$($Env:OPENSSL_VERSION)"
Push-AppveyorArtifact "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:ZLIB_ARTIFACT_ARCHIVE)" -DeploymentName "zlib v$($Env:ZLIB_VERSION)"
}
}
Function Publish-Artifact-To-Artifactory {
Param (
[Parameter(Mandatory=$True)] [String] $Uri,
[Parameter(Mandatory=$True)] [String] $FilePath,
[Parameter(Mandatory=$False)] [Int] $TimeoutSec = 480
)
# Create the credentials and checksum headers
$username = "$($Env:ARTIFACTORY_USERNAME)"
$password = ConvertTo-SecureString -String "$($Env:ARTIFACTORY_PASSWORD)" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password
$md5_hash = $(Get-FileHash "$($FilePath)" -Algorithm MD5).Hash
$sha1_hash = $(Get-FileHash "$($FilePath)" -Algorithm SHA1).Hash
$sha256_hash = $(Get-FileHash "$($FilePath)" -Algorithm SHA256).Hash
$headers = @{
# "X-Checksum-Deploy" = $True
"X-Checksum-Md5" = $md5_hash
"X-Checksum-Sha1" = $sha1_hash
"X-Checksum-Sha256" = $sha256_hash
}
# Publish the artifacts to artifactory
Try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Ensure TLS v1.2 is enabled
$result = Invoke-RestMethod -Headers $headers -Uri "$($Uri)" -Method Put -InFile "$($FilePath)" -Credential $credential -ContentType "multipart/form-data" -TimeoutSec $TimeoutSec
} Catch {
$error_code = $_.Exception.Response.StatusCode.value__
$message = $_.Exception.Message
$filename = Split-Path $FilePath -leaf
If ($Env:APPVEYOR -Like "True") {
Add-AppveyorMessage -Category Error -Message "Unable to Upload $($filename) [$($error_code)]" -Details "$($message)"
} Else {
Write-Error -Message "Unable to Upload $($filename) [$($error_code)]: $($message)"
}
return $error_code
}
return 0
}
Function Publish-Artifacts {
# Determine if the artifacts should to published to Artifactory
If ($Env:APPVEYOR_REPO_TAG -Like "True") {
# Create the upload environment
$driver_type = "cassandra"
If ($Env:DRIVER_TYPE -Like "dse") {
$driver_type = "dse"
}
# Create the Uri and FilePath components for the upload
$base_uri = "$($Env:ARTIFACTORY_BASE_URI)/$($Env:DRIVER_VERSION)/$(Get-Commit-Sha)/windows"
$driver_uri = "$($base_uri)/$($driver_type)/v$($Env:DRIVER_VERSION)/$($Env:DRIVER_ARTIFACT_ARCHIVE)"
$driver_archive = "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:DRIVER_ARTIFACT_ARCHIVE)"
$libuv_uri = "$($base_uri)/dependencies/libuv/v$($Env:LIBUV_VERSION)/$($Env:LIBUV_ARTIFACT_ARCHIVE)"
$libuv_archive = "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:LIBUV_ARTIFACT_ARCHIVE)"
#TODO: Need to handle OpenSSL v1.1.x if enabled
$openssl_uri = "$($base_uri)/dependencies/openssl/v$($Env:OPENSSL_VERSION)/$($Env:OPENSSL_ARTIFACT_ARCHIVE)"
$openssl_archive = "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:OPENSSL_ARTIFACT_ARCHIVE)"
$zlib_uri = "$($base_uri)/dependencies/zlib/v$($Env:ZLIB_VERSION)/$($Env:ZLIB_ARTIFACT_ARCHIVE)"
$zlib_archive = "$($Env:DRIVER_ARTIFACTS_DIR)/$($Env:ZLIB_ARTIFACT_ARCHIVE)"
# Publish/Upload the driver and it dependencies to Artifactory
$is_failure = $False
$failed_upload = @()
If ((Publish-Artifact-To-Artifactory -Uri "$($driver_uri)" -FilePath "$($driver_archive)") -ne 0) {
$is_failure = $True
$failed_upload += "Driver"
}
If ((Publish-Artifact-To-Artifactory -Uri "$($libuv_uri)" -FilePath "$($libuv_archive)") -ne 0) {
$is_failure = $True
$failed_upload += "libuv"
}
#TODO: Need to handle OpenSSL v1.1.x if enabled
If ((Publish-Artifact-To-Artifactory -Uri "$($openssl_uri)" -FilePath "$($openssl_archive)") -ne 0) {
$is_failure = $True
$failed_upload += "OpenSSL"
}
If ((Publish-Artifact-To-Artifactory -Uri "$($zlib_uri)" -FilePath "$($zlib_archive)") -ne 0) {
$is_failure = $True
$failed_upload += "zlib"
}
# Check to see if there was a failure uploading the artifacts
If ($is_failure) {
Throw "Error Uploading Artifacts to Artifactory: $($failed_upload -Join ", ")"
}
}
}
Function Push-Build-Logs {
If ($Env:APPVEYOR -Like "True") {
# Determine the prefix directory based on driver type
$prefix_dir = "./"
If ($Env:DRIVER_TYPE -Like "dse") {
$prefix_dir += "cpp-driver"
}
# Push the logs for the builds that occurred
If (Test-Path -Path "$($Env:DRIVER_ARTIFACTS_LOGS_DIR)") {
$argument_list = @"
a -tzip "cmake_external_project_logs.zip" -r "$($Env:DRIVER_ARTIFACTS_LOGS_DIR)/*.log"
"@
$process = Start-Process -FilePath 7z -ArgumentList $argument_list -PassThru -Wait -NoNewWindow
If ($process.ExitCode -eq 0) {
Push-AppveyorArtifact "cmake_external_project_logs.zip" -DeploymentName "CMake External Project Logs"
}
}
If (Test-Path -Path "$($Env:APPVEYOR_BUILD_FOLDER)/build/CMakeFiles/CMakeOutput.log") {
Push-AppveyorArtifact "$($Env:APPVEYOR_BUILD_FOLDER)/build/CMakeFiles/CMakeOutput.log" -DeploymentName "Driver Output Log"
}
If (Test-Path -Path "$($Env:APPVEYOR_BUILD_FOLDER)/build/CMakeFiles/CMakeError.log") {
Push-AppveyorArtifact "$($Env:APPVEYOR_BUILD_FOLDER)/build/CMakeFiles/CMakeError.log" -DeploymentName "Driver Error Log"
}
}
}