Implement builders to build Boost from source code

This commit is contained in:
Maxim Lobanov
2020-05-27 09:24:57 +03:00
parent 886c1d6104
commit 610555ac3d
36 changed files with 2005 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
class BoostBuilder {
<#
.SYNOPSIS
Base Boost builder class.
.DESCRIPTION
Base Boost builder class that contains general builder methods.
.PARAMETER Version
The version of Boost that should be built.
.PARAMETER Platform
The platform of Boost that should be built.
.PARAMETER Architecture
The architecture with which Boost should be built.
.PARAMETER TempFolderLocation
The location of temporary files that will be used during Boost package generation. Using system BUILD_STAGINGDIRECTORY variable value.
.PARAMETER ArtifactLocation
The location of generated Boost artifact. Using system environment BUILD_BINARIESDIRECTORY variable value.
.PARAMETER InstallationTemplatesLocation
The location of installation script template. Using "installers" folder from current repository.
#>
[version] $Version
[string] $Platform
[string] $Architecture
[string] $Toolset
[string] $TempFolderLocation
[string] $WorkFolderLocation
[string] $ArtifactFolderLocation
[string] $InstallationTemplatesLocation
BoostBuilder ([version] $version, [string] $platform, [string] $architecture, [string] $toolset) {
$this.Version = $version
$this.Platform = $platform
$this.Architecture = $architecture
$this.Toolset = $toolset
$this.TempFolderLocation = [IO.Path]::GetTempPath()
$this.WorkFolderLocation = $env:BUILD_BINARIESDIRECTORY
$this.ArtifactFolderLocation = $env:BUILD_STAGINGDIRECTORY
$this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers"
}
[void] Download() {
<#
.SYNOPSIS
Download Boost source code.
#>
$gitArguments = @(
"clone"
"https://github.com/boostorg/boost.git",
$this.WorkFolderLocation,
"--branch", "boost-$($this.Version)",
"--single-branch",
"--recursive"
) -join " "
Execute-Command "git $gitArguments"
Write-Host "Removing .git subfolder to reduce artifact size..."
$gitFolder = Join-Path $this.WorkFolderLocation ".git"
Remove-Item $gitFolder -Recurse -Force
}
[void] Build() {
<#
.SYNOPSIS
Generates Boost artifact from downloaded binaries.
#>
Write-Host "Download Boost $($this.Version) source code..."
$this.Download()
Write-Host "Build source code..."
$this.Make()
Write-Host "Create installation script..."
$this.CreateInstallationScript()
Write-Host "Archive artifact..."
$this.ArchiveArtifact()
}
}

75
builders/build-boost.ps1 Normal file
View File

@@ -0,0 +1,75 @@
using module "./builders/win-boost-builder.psm1"
using module "./builders/nix-boost-builder.psm1"
<#
.SYNOPSIS
Generate Boost artifact.
.DESCRIPTION
Main script that creates instance of BoostBuilder and builds of Boost using specified parameters.
.PARAMETER Version
Required parameter. The version with which Boost will be built.
.PARAMETER Architecture
Optional parameter. The architecture with which Boost will be built. Using x64 by default.
.PARAMETER Platform
Required parameter. The platform for which Boost will be built.
#>
param(
[Parameter (Mandatory=$true)][Version] $Version,
[Parameter (Mandatory=$true)][string] $Platform,
[Parameter (Mandatory=$true)][string] $Architecture,
[Parameter (Mandatory=$true)][string] $Toolset
)
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "common-helpers.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "nix-helpers.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "win-helpers.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "win-vs-env.psm1") -DisableNameChecking
$ErrorActionPreference = "Stop"
function Get-BoostBuilder {
<#
.SYNOPSIS
Wrapper for class constructor to simplify importing BoostBuilder.
.DESCRIPTION
Create instance of BoostBuilder with specified parameters.
.PARAMETER Version
The version with which Boost will be built.
.PARAMETER Platform
The platform for which Boost will be built.
.PARAMETER Architecture
The architecture with which Boost will be built.
#>
param (
[version] $Version,
[string] $Architecture,
[string] $Platform
)
if ($Platform -match 'win32') {
$builder = [WinBoostBuilder]::New($Version, $Platform, $Architecture, $Toolset)
} elseif ($Platform -match 'linux') {
$builder = [NixBoostBuilder]::New($Version, $Platform, $Architecture, $Toolset)
} else {
Write-Host "##vso[task.logissue type=error;] Invalid platform: $Platform"
exit 1
}
return $builder
}
### Create Boost builder instance, and build artifact
$Builder = Get-BoostBuilder -Version $Version -Platform $Platform -Architecture $Architecture
$Builder.Build()

View File

@@ -0,0 +1,77 @@
using module "./builders/boost-builder.psm1"
class NixBoostBuilder : BoostBuilder {
<#
.SYNOPSIS
Ubuntu Boost builder class.
.DESCRIPTION
Contains methods that required to build Ubuntu Boost artifact from sources. Inherited from base BoostBuilder.
#>
[string] $InstallationTemplateName
[string] $InstallationScriptName
[string] $OutputArtifactName
NixBoostBuilder(
[version] $version,
[string] $platform,
[string] $architecture,
[string] $toolset
) : Base($version, $platform, $architecture, $toolset) {
$this.InstallationTemplateName = "nix-setup-template.sh"
$this.InstallationScriptName = "setup.sh"
$this.OutputArtifactName = "boost-$Version-$Platform-$Toolset-$Architecture.tar.gz"
}
[void] Make() {
Push-Location -Path $this.WorkFolderLocation
Write-Host "Invoke bootstrap.sh"
Execute-Command "sudo ./bootstrap.sh"
$commonArguments = @(
"install"
"--prefix=$($this.WorkFolderLocation)",
"--build-dir=$($this.TempFolderLocation)",
"--layout='tagged'",
"link='static,shared'",
"runtime-link='static,shared'"
) -join " "
Write-Host "Build boost static and shared binaries in release"
Execute-Command "sudo ./b2 $commonArguments variant='release'"
Write-Host "Build boost static and shared binaries in debug"
Execute-Command "sudo ./b2 $commonArguments variant='debug'"
Pop-Location
}
[void] CreateInstallationScript() {
<#
.SYNOPSIS
Create Boost artifact installation script based on template specified in InstallationTemplateName property.
#>
$installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
$variablesToReplace = @{
"{{__VERSION__}}" = $this.Version;
"{{__ARCHITECTURE__}}" = "x64";
}
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
$installationTemplateContent | Out-File -FilePath $installationScriptLocation
Write-Debug "Done; Installation script location: $installationScriptLocation)"
}
[void] ArchiveArtifact() {
$OutputPath = Join-Path $this.ArtifactFolderLocation $this.OutputArtifactName
Create-TarArchive -SourceFolder $this.WorkFolderLocation -ArchivePath $OutputPath
}
}

View File

@@ -0,0 +1,105 @@
using module "./builders/boost-builder.psm1"
class WinBoostBuilder : BoostBuilder {
<#
.SYNOPSIS
Ubuntu Boost builder class.
.DESCRIPTION
Contains methods that required to build Ubuntu Boost artifact from sources. Inherited from base NixBoostBuilder.
.PARAMETER Toolset
The toolset which well be used to buil source code on windows vs.
#>
[string] $InstallationTemplateName
[string] $InstallationScriptName
[string] $OutputArtifactName
WinBoostBuilder(
[version] $version,
[string] $platform,
[string] $architecture,
[string] $toolset
) : Base($version, $platform, $architecture, $toolset) {
$this.InstallationTemplateName = "win-setup-template.ps1"
$this.InstallationScriptName = "setup.ps1"
$toolsetPart = $toolset.Replace("-", "")
$this.OutputArtifactName = "boost-$Version-$Platform-$toolsetPart-$Architecture.tar.gz"
}
[void] CreateIncludeSymlink() {
$includeFolder = "$($this.WorkFolderLocation)\include"
$headerDestination = "$($this.WorkFolderLocation)\include\boost"
if ((Test-Path $includeFolder) -and (-not(Test-Path $headerDestination))) {
Write-Host "Move headers to root"
$headersSource = Get-Childitem $includeFolder | Where-Object { $_.PsIsContainer } | Select-Object -First 1 -ExpandProperty FullName
Copy-Item -Path "${headersSource}\boost" -Destination $headerDestination -Recurse -Container
}
if (-not (Test-Path -Path "$($this.WorkFolderLocation)\bjam.exe")) {
Copy-Item -Path "$($this.WorkFolderLocation)\b2.exe" -Destination "$($this.WorkFolderLocation)\bjam.exe"
}
}
[void] Make() {
Write-Host "Initialize VS dev environment"
Invoke-VSDevEnvironment
Push-Location -Path $this.WorkFolderLocation
Write-Host "Invoke bootstrap.sh"
Execute-Command "./bootstrap.bat msvc"
Write-Host "Build boost with '$($this.Toolset)' toolset..."
$commonArguments = @(
"install",
"--prefix='$($this.WorkFolderLocation)'",
"--build-dir='$($this.TempFolderLocation)'",
"variant='debug,release'",
"link='static,shared'",
"runtime-link='static,shared'",
"address-model='32,64'",
"toolset='$($this.Toolset)'",
"-j4"
) -join " "
Execute-Command "./b2 $commonArguments" -ErrorAction Continue
$this.CreateIncludeSymlink()
Pop-Location
}
[void] CreateInstallationScript() {
<#
.SYNOPSIS
Create Boost artifact installation script based on specified template.
#>
$installationScriptLocation = New-Item -Path $this.WorkFolderLocation -Name $this.InstallationScriptName -ItemType File
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
$variablesToReplace = @{
"{{__VERSION__}}" = $this.Version;
"{{__ARCHITECTURE__}}" = $this.Architecture;
}
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
$installationTemplateContent | Out-File -FilePath $installationScriptLocation
Write-Debug "Done; Installation script location: $installationScriptLocation)"
}
[void] ArchiveArtifact() {
$archiveTempDir = (New-Item -Name "tempArchive" -ItemType Directory -Path $this.TempFolderLocation).Fullname
$TempTarArchive = [IO.Path]::GetFileNameWithoutExtension($this.OutputArtifactName)
$OutPathTempTar = Join-Path -Path $archiveTempDir -ChildPath $TempTarArchive
$OutputPath = Join-Path -Path $this.ArtifactFolderLocation -ChildPath $this.OutputArtifactName
Write-Host "Pack to tar"
Create-SevenZipArchive -SourceFolder $this.WorkFolderLocation -ArchivePath $OutPathTempTar -ArchiveType "tar" -IncludeSymlinks
Write-Host "Pack to tar.gz"
Create-SevenZipArchive -SourceFolder $archiveTempDir -ArchivePath $OutputPath -ArchiveType "gzip"
}
}