Skip to content

Commit 31021b5

Browse files
committed
Updated common build support so it can actually run on automated builds
- Resynched so that common build is not the same as the LibLLVM repo
1 parent 88465c2 commit 31021b5

7 files changed

+147
-42
lines changed

PsModules/CommonBuild/CommonBuild.psd1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ FunctionsToExport = @(
6666
'Assert-CMakeList',
6767
'Assert-OfficialGitRemote',
6868
'Get-BuildVersionTag',
69+
'Assert-IsCMakeConfig',
6970
'New-CMakeConfig',
7071
'Invoke-GenerateCMakeConfig',
7172
'Build-CmakeConfig',
@@ -74,7 +75,10 @@ FunctionsToExport = @(
7475
'Expand-ArchiveStream',
7576
'Expand-StreamFromUri',
7677
'Find-OnPath',
78+
'Get-BuildVersionTag',
7779
'Get-CurrentBuildKind',
80+
'Get-GitRemotes',
81+
'Get-GitRemoteName',
7882
'Get-GitHubReleases',
7983
'Get-GitHubTaggedRelease',
8084
'Initialize-CommonBuildEnvironment',

PsModules/CommonBuild/CommonBuild.psm1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This script is a generalized script entry point for module support that is easily cloned for other modules
2-
# and is independent of the module's functionality.
2+
# and is independent of the module's functionality. This is invocable using the PS module name qualifier
3+
# syntax `<ModuleName>/Get-ExportedFunctionNames`
34

45
function Get-ExportedFunctionNames
56
{

PsModules/CommonBuild/Debug-Module.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# This script is used for debugging the module when using the
22
# [Powershell Tools for VisualStudio 2022](https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsVS2022)
3+
# It is MOST useful for computing and reporting the set of functions to export from this module for the PSD1 file.
34
Import-Module $PSScriptRoot\CommonBuild.psd1 -Force -Verbose
45
CommonBuild\Get-FunctionsToExport
56

PsModules/CommonBuild/Public/ClassLike_CMakeConfig.ps1

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ function New-CMakeConfig($name, [string]$buildConfiguration, [hashtable]$buildIn
6464
.PARAMETER buildInfo
6565
Hashtable containing the standard build information.
6666
67-
.PARAMETER cmakrSrcRoot
67+
.PARAMETER cmakeSrcRoot
6868
Root of the CMAKE source files to build
6969
#>
7070
# start with an empty hash table and build up from there...
7171
$self = @{}
7272
if($IsWindows)
7373
{
74-
# TODO: Convert this to use NIJA for faster builds... [Maybe]
75-
$self['Generator'] = 'Visual Studio 17 2022'
74+
#$self['Generator'] = 'Visual Studio 17 2022'
75+
$self['Generator'] = 'Ninja'
7676
}
7777
else
7878
{
@@ -87,27 +87,35 @@ function New-CMakeConfig($name, [string]$buildConfiguration, [hashtable]$buildIn
8787
$self['CMakeCommandArgs'] = [System.Collections.ArrayList]@()
8888
$self['BuildCommandArgs'] = [System.Collections.ArrayList]@()
8989
$self['InheritEnvironments'] = [System.Collections.ArrayList]@()
90+
$self['CMakeBuildVariables'] = @{}
9091

91-
if($IsWindows)
92+
# single config generator; Requires setting the configuration type
93+
# as a build var during generation (Otherwise, debug is assumed...)
94+
if($self['Generator'] -ieq 'Ninja')
9295
{
93-
# running on ARM64 is not tested or supported
94-
# This might not be needed now that the build is auto configuring the "VCVARS"
95-
# Ninja build might also remove the need for this...
96-
if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq "X64" )
97-
{
98-
$self['CMakeCommandArgs'].Add('-Thost=x64') | Out-Null
99-
$self['InheritEnvironments'].Add('msvc_x64_x64') | Out-Null
100-
}
101-
else
102-
{
103-
$self['InheritEnvironments'].Add('msvc_x64') | Out-Null
104-
}
105-
106-
# pass the /m switch to MSBUILD to enable parallel builds on all available CPU cores
107-
$self['BuildCommandArgs'].Add('/m') | Out-Null
96+
$self['CMakeBuildVariables']['CMAKE_BUILD_TYPE']=$self['ConfigurationType']
10897
}
10998

110-
$self['CMakeBuildVariables'] = @{}
99+
# Not needed with Ninja builds
100+
#if($IsWindows)
101+
#{
102+
# # running on ARM64 is not tested or supported
103+
# # This might not be needed now that the build is auto configuring the "VCVARS"
104+
# # Ninja build might also remove the need for this...
105+
# if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq "X64" )
106+
# {
107+
# $self['CMakeCommandArgs'].Add('-Thost=x64') | Out-Null
108+
# $self['InheritEnvironments'].Add('msvc_x64_x64') | Out-Null
109+
# }
110+
# else
111+
# {
112+
# $self['InheritEnvironments'].Add('msvc_x64') | Out-Null
113+
# }
114+
#
115+
# # pass the /m switch to MSBUILD to enable parallel builds on all available CPU cores
116+
# $self['BuildCommandArgs'].Add('/m') | Out-Null
117+
#}
118+
111119
Assert-IsCMakeConfig $self
112120
return $self
113121
}
@@ -125,7 +133,8 @@ function Invoke-GenerateCMakeConfig([hashtable]$self, [hashtable] $additionalBui
125133

126134
# Construct full set of CMAKE args from fixed options and configuration variables
127135
$cmakeArgs = New-Object System.Collections.ArrayList
128-
$cmakeArgs.Add("-G $($self['Generator'])" ) | Out-Null
136+
$cmakeArgs.AddRange(@('-G', "$($self['Generator'])") ) | Out-Null
137+
$cmakeArgs.AddRange(@('-B', "$($self['BuildRoot'])") ) | Out-Null
129138
foreach( $param in $self['CMakeCommandArgs'] )
130139
{
131140
$cmakeArgs.Add( $param ) | Out-Null
@@ -154,21 +163,10 @@ function Invoke-GenerateCMakeConfig([hashtable]$self, [hashtable] $additionalBui
154163

155164
$cmakeArgs.Add( $self['SrcRoot'] ) | Out-Null
156165
Invoke-TimedBlock "CMAKE Generate" {
157-
Push-Location $self['BuildRoot']
158-
try
159-
{
160-
Write-Information "cmake $cmakeArgs"
161-
# Splat the array of args as distinct for external invoke
162-
Invoke-External cmake @cmakeArgs
163-
}
164-
catch
165-
{
166-
throw
167-
}
168-
finally
169-
{
170-
Pop-Location
171-
}
166+
Write-Information "cmake $($cmakeArgs -join ' ')"
167+
168+
# Splat the array of args as distinct elements for external invoke
169+
Invoke-External cmake @cmakeArgs
172170
}
173171
}
174172

@@ -177,14 +175,25 @@ function Invoke-GenerateCMakeConfig([hashtable]$self, [hashtable] $additionalBui
177175
# see: https://github.com/PowerShell/PowerShell/issues/13637
178176
New-Alias -Name Generate-CMakeConfig -Value Invoke-GenerateCMakeConfig
179177

180-
function Build-CmakeConfig([hashtable]$self)
178+
function Build-CmakeConfig([hashtable]$self, $targets)
181179
{
182180
Assert-IsCMakeConfig $self
181+
$cmakeArgs = [System.Collections.ArrayList]@('--build', "$($self['BuildRoot'])", '--config', "$($self['ConfigurationType'])")
182+
if($targets)
183+
{
184+
$cmakeArgs.Add('-t') | Out-Null
185+
$cmakeArgs.AddRange($targets)
186+
}
187+
188+
if($self['BuildCommandArgs'].Length -gt 0)
189+
{
190+
$cmakeArgs.AddRange( @('--', "$($self['BuildCommandArgs'])") )
191+
}
192+
183193
Invoke-TimedBlock "CMake Building $($self['Name'])" {
184-
$cmakeArgs = @('--build', "$($self['BuildRoot'])", '--config', "$($self['ConfigurationType'])", '--', "$($self['BuildCommandArgs'])")
185-
Write-Information "cmake $([string]::Join(' ', $cmakeArgs))"
194+
Write-Information "cmake $($cmakeArgs -join ' ')"
186195

187-
# Splat the array of args as distinct for external invoke
196+
# Splat the array of args as distinct items for external invoke
188197
Invoke-External cmake @cmakeArgs
189198
}
190199
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Get-BuildVersionTag
2+
{
3+
<#
4+
.SYNOPSIS
5+
Retrieves the git tag name to apply for this build.
6+
7+
.DESCRIPTION
8+
Reads the contents of the BuildVersion.xml file and generates a git
9+
release tag name for the current build.
10+
11+
This is a standalone function instead of a property on the build
12+
information Hashtable so that it is always dynamically evaluated
13+
based on the current contents of the BuildVersion.XML file as that
14+
is generally updated when this is needed.
15+
16+
.PARAMETER buildInfo
17+
Hashtable containing Information about the repository and build. This function
18+
requires the presence of a 'RepoRootPath' property to indicate the root of the
19+
repository containing the BuildVersion.xml file.
20+
#>
21+
[OutputType([string])]
22+
Param($buildInfo)
23+
24+
# determine release tag from the build version XML file in the branch
25+
$buildVersionXml = (Get-BuildVersionXML $buildInfo)
26+
$buildVersionData = $buildVersionXml.BuildVersionData
27+
$preReleaseSuffix=""
28+
if($buildVersionData.PSObject.Properties['PreReleaseName'])
29+
{
30+
$preReleaseSuffix = "-$($buildVersionData.PreReleaseName)"
31+
if($buildVersionData.PSObject.Properties['PreReleaseNumber'])
32+
{
33+
$preReleaseSuffix += ".$($buildVersionData.PreReleaseNumber)"
34+
if($buildVersionData.PSObject.Properties['PreReleaseFix'])
35+
{
36+
$preReleaseSuffix += ".$($buildVersionData.PreReleaseFix)"
37+
}
38+
}
39+
}
40+
41+
return "v$($buildVersionData.BuildMajor).$($buildVersionData.BuildMinor).$($buildVersionData.BuildPatch)$preReleaseSuffix"
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Get-GitRemotes
2+
{
3+
param($opName = "push")
4+
$remoteLines = ((git remote -v) -split [System.Environment]::NewLine)
5+
$retVal = [System.Collections.ArrayList]@()
6+
foreach($remoteLine in $remoteLines)
7+
{
8+
if( $remoteLine -match '([^\s]+)\s+([^\s]+)\s+\(([^\s]+)\)')
9+
{
10+
if($matches[3] -eq $opName)
11+
{
12+
$hashTable =@{
13+
Name = $matches[1]
14+
Uri = $matches[2]
15+
Op = $matches[3]
16+
}
17+
18+
$retVal.Add($hashTable) | Out-Null
19+
}
20+
}
21+
else
22+
{
23+
throw "'$remoteLine' - does not match pattern for a valid git remote..."
24+
}
25+
}
26+
27+
return $retVal
28+
}
29+
30+
function Get-GitRemoteName
31+
{
32+
param([hashtable]$bldInfo, [ValidateSet('official', 'fork')] $kind)
33+
34+
if($kind -eq 'official')
35+
{
36+
Get-GitRemotes | ? {$_.Uri -eq $bldInfo['OfficialGitRemoteUrl']} | Select -ExpandProperty Name
37+
}
38+
else
39+
{
40+
Get-GitRemotes | ? {$_.Uri -ne $bldInfo['OfficialGitRemoteUrl']} | Select -ExpandProperty Name
41+
}
42+
}

PsModules/CommonBuild/Public/Initialize-CommonBuildEnvironment.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ function Initialize-CommonBuildEnvironment
9999
# spelunking the process. This isn't as bad as it might seem as the
100100
# installer will create persistent use of this as a Windows Terminal
101101
# "profile" and the actual command is exposed.
102-
winget install Microsoft.VisualStudio.Locator | Out-Null
102+
if($null -eq (Find-OnPath vswhere))
103+
{
104+
# NOTE: automated builds in Github do NOT include winget (for reasons unknown)
105+
# However, they do contain VSWHERE so should not hit this.
106+
winget install Microsoft.VisualStudio.Locator | Out-Null
107+
}
108+
103109
$vsShellModulePath = vswhere -find **\Microsoft.VisualStudio.DevShell.dll
104110
$vsToolsArch = Get-VsArchitecture
105111
if(!$vsShellModulePath)

0 commit comments

Comments
 (0)