|
| 1 | +# |
| 2 | +# Copyright 2024 Centreon |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | +# use this file except in compliance with the License. You may obtain a copy of |
| 6 | +# the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | +# License for the specific language governing permissions and limitations under |
| 14 | +# the License. |
| 15 | +# |
| 16 | +# For more information : [email protected] |
| 17 | +# |
| 18 | + |
| 19 | +Write-Host "Work in" $pwd.ToString() |
| 20 | + |
| 21 | +[System.Environment]::SetEnvironmentVariable("AWS_EC2_METADATA_DISABLED","true") |
| 22 | + |
| 23 | +Write-Host $env:VCPKG_BINARY_SOURCES |
| 24 | + |
| 25 | +$current_dir = $pwd.ToString() |
| 26 | + |
| 27 | +#get cache from s3 |
| 28 | +$files_to_hash = "vcpkg.json", "custom-triplets\x64-windows.cmake", "CMakeLists.txt", "CMakeListsWindows.txt" |
| 29 | +$files_content = Get-Content -Path $files_to_hash -Raw |
| 30 | +$stringAsStream = [System.IO.MemoryStream]::new() |
| 31 | +$writer = [System.IO.StreamWriter]::new($stringAsStream) |
| 32 | +$writer.write($files_content -join " ") |
| 33 | +$writer.Flush() |
| 34 | +$stringAsStream.Position = 0 |
| 35 | +$vcpkg_hash = Get-FileHash -InputStream $stringAsStream -Algorithm SHA256 | Select-Object Hash |
| 36 | +$file_name = "windows-agent-vcpkg-dependencies-cache-" + $vcpkg_hash.Hash |
| 37 | +$file_name_extension = "${file_name}.7z" |
| 38 | + |
| 39 | +#try to get compiled dependenciesfrom s3 |
| 40 | +Write-Host "try to download compiled dependencies from s3" |
| 41 | +aws --quiet s3 cp s3://centreon-collect-robot-report/$file_name_extension $file_name_extension |
| 42 | +if ( $? -ne $true ) { |
| 43 | + #no => generate |
| 44 | + Write-Host "#######################################################################################################################" |
| 45 | + Write-Host "compiled dependencies unavailable for this version we will need to build it, it will take a long time" |
| 46 | + Write-Host "#######################################################################################################################" |
| 47 | + |
| 48 | + Write-Host "install vcpkg" |
| 49 | + git clone --depth 1 --single-branch --no-tags https://github.com/microsoft/vcpkg vcpkg |
| 50 | + cd vcpkg |
| 51 | + bootstrap-vcpkg.bat |
| 52 | + cd $current_dir |
| 53 | + |
| 54 | + [System.Environment]::SetEnvironmentVariable("VCPKG_ROOT",$pwd.ToString()+"\vcpkg") |
| 55 | + [System.Environment]::SetEnvironmentVariable("PATH",$pwd.ToString()+"\vcpkg;" + $env:PATH) |
| 56 | + |
| 57 | + Write-Host "compile vcpkg dependencies" |
| 58 | + vcpkg install --vcpkg-root $env:VCPKG_ROOT --x-install-root build_windows\vcpkg_installed --x-manifest-root . --overlay-triplets custom-triplets --triplet x64-windows |
| 59 | + |
| 60 | + Write-Host "Compress binary archive" |
| 61 | + 7z a $file_name_extension build_windows\vcpkg_installed |
| 62 | + Write-Host "Upload binary archive" |
| 63 | + aws s3 cp $file_name_extension s3://centreon-collect-robot-report/$file_name_extension |
| 64 | + Write-Host "create CMake files" |
| 65 | +} |
| 66 | +else { |
| 67 | + 7z x $file_name_extension |
| 68 | + Write-Host "Create cmake files from binary-cache downloaded without use vcpkg" |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +cmake -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=On -DWINDOWS=On -DBUILD_FROM_CACHE=On -S. -DVCPKG_CRT_LINKAGE=dynamic -DBUILD_SHARED_LIBS=OFF -Bbuild_windows |
| 74 | + |
| 75 | +Write-Host "build agent and tests" |
| 76 | + |
| 77 | +cmake --build build_windows --config Release |
| 78 | + |
0 commit comments