1212# before running the Pre-Build script.
1313
1414param (
15+ [ValidateSet (" x86" , " x64" , " arm" , " " )]
16+ [string ]$arch = " " ,
17+ [ValidateSet (" debug" , " release" , " test" , " codecoverage" , " " )]
18+ [string ]$flavor = " " ,
19+ [ValidateSet (" default" , " codecoverage" , " pogo" )]
20+ [string ]$subtype = " default" ,
21+ [string ]$buildtype ,
22+
1523 [string ]$envConfigScript = " ComputedEnvironment.cmd" ,
1624
1725 [string []]$supportedPogoBuildTypes = @ (" x64_release" , " x86_release" ),
1826
19- [Parameter (Mandatory = $True )]
27+ [string ]$verMajor = " " ,
28+ [string ]$verMinor = " " ,
29+ [string ]$verPatch = " " ,
30+ [string ]$verSecurity = " " ,
31+
32+ [string ]$dropRoot ,
33+
34+ [switch ]$cleanBinDir ,
35+
2036 [string ]$oauth
2137)
2238
23- # If $Env:BuildType is specified, extract BuildPlatform and BuildConfiguration
24- # Otherwise, if $Env:BuildPlatform and $Env:BuildConfiguration are specified, construct $BuildType
25- $BuildPlatform = $Env: BuildPlatform
26- $BuildConfiguration = $Env: BuildConfiguration
27- $BuildType = $Env: BuildType
28- $BuildSubtype = " default" # will remain as "default" or become e.g. "pogo", "codecoverage"
39+ #
40+ # Define values for variables based on parameters and environment variables
41+ # with default values in case the environment variables are not defined.
42+ #
43+
44+ . $PSScriptRoot \util.ps1
45+ $gitExe = GetGitPath
46+
47+ $BuildType = UseValueOrDefault $buildtype $Env: BuildType
48+ $BuildPlatform = UseValueOrDefault $arch $Env: BuildPlatform
49+ $BuildConfiguration = UseValueOrDefault $flavor $Env: BuildConfiguration
50+ $BuildSubtype = UseValueOrDefault $subtype $Env: BuildSubtype
2951
30- if (Test-Path Env:\BuildType) {
31- $BuildType = $Env: BuildType
52+ # If $BuildType is specified, extract BuildPlatform and BuildConfiguration
53+ # Otherwise, if $BuildPlatform and $BuildConfiguration are specified, construct $BuildType
54+ # $BuildSubtype will remain as "default" if not already specified, or become e.g. "pogo", "codecoverage"
55+ if ($BuildType ) {
3256 $buildTypeSegments = $BuildType.split (" _" )
3357 $BuildPlatform = $buildTypeSegments [0 ]
3458 $BuildConfiguration = $buildTypeSegments [1 ]
@@ -42,12 +66,10 @@ if (Test-Path Env:\BuildType) {
4266 $BuildSubtype = " codecoverage" # keep information about codecoverage in the subtype
4367 }
4468
45- if (-not ($BuildSubtype -in @ (" default" , " pogo" , " codecoverage" ))) {
69+ if (-not ($BuildSubtype -in @ (" default" , " pogo" , " codecoverage" ))) {
4670 Write-Error " Unsupported BuildSubtype: $BuildSubtype "
4771 }
48- } elseif ((Test-Path Env:\BuildPlatform) -and (Test-Path Env:\BuildConfiguration)) {
49- $BuildPlatform = $Env: BuildPlatform
50- $BuildConfiguration = $Env: BuildConfiguration
72+ } elseif ($BuildPlatform -and $BuildConfiguration ) {
5173 $BuildType = " ${BuildPlatform} _${BuildConfiguration} "
5274} else {
5375 Write-Error (@"
@@ -56,67 +78,92 @@ if (Test-Path Env:\BuildType) {
5678 BuildType={0}
5779 BuildPlatform={1}
5880 BuildConfiguration={2}
81+ BuildSubtype={3}
5982
60- "@ -f $Env: BuildType , $Env: BuildPlatform , $Env: BuildConfiguration )
83+ "@ -f $BuildType , $BuildPlatform , $BuildConfiguration , $BuildSubtype )
6184
6285 exit 1
6386}
6487
88+ $CommitHash = UseValueOrDefault $Env: BUILD_SOURCEVERSION $ (iex " ${gitExe} rev-parse HEAD" )
89+
90+ $branchFullName = UseValueOrDefault $Env: BUILD_SOURCEBRANCH $ (iex " ${gitExe} rev-parse --symbolic-full-name HEAD" )
91+
92+ $SourcesDirectory = UseValueOrDefault $Env: BUILD_SOURCESDIRECTORY $ (GetRepoRoot)
93+ $BinariesDirectory = UseValueOrDefault (Join-Path $SourcesDirectory " Build\VcBuild" )
94+ $ObjectDirectory = Join-Path $BinariesDirectory " obj\${BuildPlatform} _${BuildConfiguration} "
95+
96+ $DropRoot = UseValueOrDefault $dropRoot $Env: DROP_ROOT (Join-Path $ (GetRepoRoot) " _DROP" )
97+
6598# set up required variables and import pre_post_util.ps1
6699$arch = $BuildPlatform
67100$flavor = $BuildConfiguration
68101$OuterScriptRoot = $PSScriptRoot # Used in pre_post_util.ps1
69102. " $PSScriptRoot \pre_post_util.ps1"
70103
71- $gitExe = GetGitPath
72-
73104$BuildName = ConstructBuildName - arch $BuildPlatform - flavor $BuildConfiguration - subtype $BuildSubtype
74105
75- $branch = $Env: BUILD_SOURCEBRANCH
76- if (-not $branch ) {
77- $branch = iex " $gitExe rev-parse --symbolic-full-name HEAD"
78- }
79-
80- $BranchName = $branch.split (' /' , 3 )[2 ]
106+ $BranchName = $branchFullName.split (' /' , 3 )[2 ]
81107$BranchPath = $BranchName.replace (' /' , ' \' )
82- $CommitHash = $ Env: BUILD_SOURCEVERSION
108+
83109if (-not $CommitHash ) {
84- $CommitHash = iex " $gitExe rev-parse HEAD"
110+ $CommitHash = iex " ${ gitExe} rev-parse HEAD"
85111}
112+ $CommitShortHash = $ (iex " ${gitExe} rev-parse --short $CommitHash " )
86113
87- $Username = (iex " $gitExe log $CommitHash -1 --pretty=%ae" ).split(' @' )[0 ]
88- $CommitDateTime = [DateTime ]$ (iex " $gitExe log $CommitHash -1 --pretty=%aD" )
114+ $Username = (iex " ${ gitExe} log $CommitHash -1 --pretty=%ae" ).split(' @' )[0 ]
115+ $CommitDateTime = [DateTime ]$ (iex " ${ gitExe} log $CommitHash -1 --pretty=%aD" )
89116$CommitTime = Get-Date $CommitDateTime - Format yyMMdd.HHmm
90117
91118#
92119# Get Build Info
93120#
94121
95- $info = GetBuildInfo $oauth $CommitHash
122+ $buildPushDate = $null
123+ $buildPushIdString = $null
96124
97- $BuildPushDate = [datetime ]$info.push.date
98- $PushDate = Get-Date $BuildPushDate - Format yyMMdd.HHmm
125+ if (-not $oauth )
126+ {
127+ $buildPushIdPart1 = 65535
128+ $buildPushIdPart2 = 65535
129+ $buildPushIdString = " 65535.65535"
130+ $buildPushDate = [DateTime ]$CommitDateTime
131+ }
132+ else
133+ {
134+ $info = GetBuildInfo $oauth $CommitHash
135+ $_ , $buildPushIdPart1 , $buildPushIdPart2 , $buildPushIdString = GetBuildPushId $info
136+ $buildPushDate = [DateTime ]$info.push.date
137+ }
138+
139+ $PushDate = Get-Date $buildPushDate - Format yyMMdd.HHmm
140+
141+ $VersionMajor = UseValueOrDefault $verMajor $Env: VERSION_MAJOR (GetVersionField " CHAKRA_CORE_MAJOR_VERSION" ) " 0"
142+ $VersionMinor = UseValueOrDefault $verMinor $Env: VERSION_MINOR (GetVersionField " CHAKRA_CORE_MINOR_VERSION" ) " 0"
143+ $VersionPatch = UseValueOrDefault $verPatch $Env: VERSION_PATCH (GetVersionField " CHAKRA_CORE_PATCH_VERSION" ) " 0"
144+ $VersionSecurity = UseValueOrDefault $verSecurity $Env: VERSION_QFE (GetVersionField " CHAKRA_CORE_VERSION_RELEASE_QFE" ) " 0"
99145
100- $buildPushId , $buildPushIdPart1 , $buildPushIdPart2 , $buildPushIdString = GetBuildPushId $info
146+ $VersionString = " ${VersionMajor} . ${VersionMinor} . ${VersionPatch} " # Only use MAJOR.MINOR.PATCH to align with SemVer
101147
102- $VersionMajor = UseValueOrDefault " $Env: VERSION_MAJOR " " 1"
103- $VersionMinor = UseValueOrDefault " $Env: VERSION_MINOR " " 2"
104- $VersionPatch = UseValueOrDefault " $Env: VERSION_PATCH " " 0"
105- $VersionQFE = UseValueOrDefault " $Env: VERSION_QFE " " 0"
148+ $buildVersionString = " {0}-{1}" -f $buildPushIdPart1.ToString (" 00000" ), $buildPushIdPart2.ToString (" 00000" )
149+ $PreviewVersionString = " ${VersionString} -preview-${buildVersionString} "
106150
107- $VersionString = " ${VersionMajor} .${VersionMinor} .${VersionPatch} .${VersionQFE} "
108- $PreviewVersionString = " ${VersionString} -preview"
151+ $ShortBranch = " commit"
152+ if ($BranchName -eq " master" ) {
153+ $ShortBranch = " master"
154+ } elseif ($BranchName.StartsWith (" release" )) {
155+ $ShortBranch = $BranchName.replace (" release/" , " " )
156+ }
109157
110158# unless it is a build branch, subdivide the output directory by month
111159if ($BranchPath.StartsWith (" build" )) {
112160 $YearAndMonth = " "
113161} else {
114- $YearAndMonth = (Get-Date $BuildPushDate - Format yyMM) + " \"
162+ $YearAndMonth = (Get-Date $buildPushDate - Format yyMM) + " \"
115163}
116164
117165$BuildIdentifier = " ${buildPushIdString} _${PushDate} _${Username} _${CommitHash} "
118166$ComputedDropPathSegment = " ${BranchPath} \${YearAndMonth}${BuildIdentifier} "
119- $BinariesDirectory = " ${Env: BUILD_SOURCESDIRECTORY} \Build\VcBuild"
120167$ObjectDirectory = " ${BinariesDirectory} \obj\${BuildPlatform} _${BuildConfiguration} "
121168
122169# Create a sentinel file for each build flavor to track whether the build is complete.
@@ -128,36 +175,43 @@ This could mean that the build is in progress, or that it was unable to run to c
128175The contents of this directory should not be relied on until the build completes.
129176"@
130177
131- $DropPath = Join-Path $Env: DROP_ROOT $ComputedDropPathSegment
178+ $DropPath = Join-Path $DropRoot $ComputedDropPathSegment
132179New-Item - ItemType Directory - Force - Path $DropPath
133- New-Item - ItemType Directory - Force - Path (Join-Path $Env: BUILD_SOURCESDIRECTORY " test\logs" )
180+ New-Item - ItemType Directory - Force - Path (Join-Path $SourcesDirectory " test\logs" )
134181New-Item - ItemType Directory - Force - Path (Join-Path $BinariesDirectory " buildlogs" )
135182New-Item - ItemType Directory - Force - Path (Join-Path $BinariesDirectory " logs" )
136183
137184$FlavorBuildIncompleteFile = Join-Path $DropPath " ${BuildType} .incomplete"
138185
139186if (-not (Test-Path $FlavorBuildIncompleteFile )) {
140187 ($buildIncompleteFileContentsString -f " Build of ${BuildType} " ) `
141- | Out-File $FlavorBuildIncompleteFile - Encoding Ascii
188+ | Out-File $FlavorBuildIncompleteFile - Encoding utf8
142189}
143190
144- $PogoConfig = $supportedPogoBuildTypes -contains " ${Env: BuildPlatform} _${Env: BuildConfiguration} "
191+ $PogoConfig = $supportedPogoBuildTypes -contains " ${BuildPlatform} _${BuildConfiguration} "
145192
146193# Write the $envConfigScript
147194
148195@"
149196set BranchName=${BranchName}
197+ set ShortBranch=${ShortBranch}
150198set BranchPath=${BranchPath}
151199set YearAndMonth=${YearAndMonth}
152200set BuildIdentifier=${BuildIdentifier}
153201
154- set buildPushIdString=${buildPushIdString}
202+ set VersionMajor=${VersionMajor}
203+ set VersionMinor=${VersionMinor}
204+ set VersionPatch=${VersionPatch}
205+ set VersionSecurity=${VersionSecurity}
206+
207+ set BuildPushIdString=${buildPushIdString}
155208set VersionString=${VersionString}
156209set PreviewVersionString=${PreviewVersionString}
157210set PushDate=${PushDate}
158211set CommitTime=${CommitTime}
159212set Username=${Username}
160213set CommitHash=${CommitHash}
214+ set CommitShortHash=${CommitShortHash}
161215
162216set ComputedDropPathSegment=${ComputedDropPathSegment}
163217set BinariesDirectory=${BinariesDirectory}
@@ -174,24 +228,30 @@ set FlavorBuildIncompleteFile=${FlavorBuildIncompleteFile}
174228set PogoConfig=${PogoConfig}
175229
176230"@ `
177- | Out-File $envConfigScript - Encoding Ascii
231+ | Out-File $envConfigScript - Encoding ASCII
178232
179233# Use the VSTS environment vars to construct a backwards-compatible VSO build environment
180234# for the sake of reusing the pre-build and post-build scripts as they are.
181235
182236@"
183- set TF_BUILD_SOURCEGETVERSION=LG:${branch } :${CommitHash}
237+ set TF_BUILD_SOURCEGETVERSION=LG:${branchFullName } :${CommitHash}
184238set TF_BUILD_DROPLOCATION=${BinariesDirectory}
185239
186- set TF_BUILD_SOURCESDIRECTORY=${Env: BUILD_SOURCESDIRECTORY }
240+ set TF_BUILD_SOURCESDIRECTORY=${SourcesDirectory }
187241set TF_BUILD_BUILDDIRECTORY=${ObjectDirectory}
188242set TF_BUILD_BINARIESDIRECTORY=${BinariesDirectory}
189243
244+ REM The following variables are only used for logging build metadata.
190245set TF_BUILD_BUILDDEFINITIONNAME=${Env: BUILD_DEFINITIONNAME}
191246set TF_BUILD_BUILDNUMBER=${Env: BUILD_BUILDNUMBER}
192247set TF_BUILD_BUILDURI=${Env: BUILD_BUILDURI}
193248"@ `
194- | Out-File $envConfigScript - Encoding Ascii - Append
249+ | Out-File $envConfigScript - Encoding ASCII - Append
250+
251+ # Print contents of $envConfigScript as a sanity check
252+ Write-Output " "
253+ Get-Content $envConfigScript | Write-Output
254+ Write-Output " "
195255
196256# Export VSO variables that can be consumed by other VSO tasks where the task
197257# definition in VSO itself needs to know the value of the variable.
@@ -216,10 +276,10 @@ Write-Output "Setting VSO variable VSO_VersionString = ${VersionString}"
216276Write-Output " ##vso[task.setvariable variable=VSO_VersionString;]${VersionString} "
217277
218278#
219- # Clean up files that might have been left behind from a previous build.
279+ # Optionally ($cleanBinDir): clean up files that might have been left behind from a previous build.
220280#
221281
222- if (( Test-Path Env:\BUILD_BINARIESDIRECTORY) -and (Test-Path " $Env: BUILD_BINARIESDIRECTORY " ) )
282+ if ($BinariesDirectory -and (Test-Path " $BinariesDirectory " ) -and $cleanBinDir )
223283{
224- Remove-Item - Verbose " ${Env: BUILD_BINARIESDIRECTORY } \*" - Recurse
284+ Remove-Item - Verbose " ${BinariesDirectory } \*" - Recurse
225285}
0 commit comments