Skip to content

Commit 5e09810

Browse files
committed
[MERGE #1717 @dilijev] MicroBuild v2: Fix binary and package version metadata; refactor and improve scripts.
Merge pull request #1717 from dilijev:microbuildv2 MicroBuild v2: Fix binary and package version metadata; refactor and improve scripts. Binary and Package Versions =========================== Binary File Version Metadata ---------------------------- Enables correct embedding of version string in file info. All binaries will now embed File Version metadata as follows: <MAJOR>.<MINOR>.<PATCH>.0 (<branch>:<hash>.<build_high>.<build_low>.<push_date>) Example: 1.2.1.0 (release/1.2:9786fcdbcaa6963a5ccc6648b7aa9bd9dd51d9ec.00008.12122.161007-1756) `MAJOR`, `MINOR`, and `PATCH` correspond to SemVer fields and will match the version of ChakraCore the package corresponds to. The fourth field would have been used to indicate security fixes (a.k.a. `QFE`) but because a fourth field is not allowed in NuGet package version numbers, but is standard for versions of binaries produced from VS projects, we are keeping the fourth field in the binary data and locking it to 0, and omitting it from NuGet package version numbers and release numbers from now on. Release NuGet Package Versions ------------------------------ The format of version strings for released NuGet packages will continue to be: Microsoft.ChakraCore.<MAJOR>.<MINOR>.<PATCH>.nupkg Example: Microsoft.ChakraCore.1.2.1.nupkg Preview NuGet Package Versions ------------------------------ The format of version strings for preview NuGet packages will now be: Microsoft.ChakraCore.<MAJOR>.<MINOR>.<PATCH>-<SPECIAL>.nupkg Where `<SPECIAL>` is: preview-<build_high>-<build_low> This solves the problem of getting enough information into the package preview version string (`<SPECIAL>`) to order builds correctly while still guaranteeing that we fit the requirements for the `<SPECIAL>` field: 1. It must start with a letter 2. It can only contain the characters [a-zA-Z0-9-] 3. It must be 20 characters or less Example: Microsoft.ChakraCore.1.2.1-preview-00008-12122.nupkg Miscellaneous Version-Related Changes ------------------------------------- Add `PATCH` version to `CommonDefines.h` so that it doesn't need to be manually coded into builds. (By reducing user intervention for package versions we make it more feasible to automatically release preview packages from multiple branches.) Extract `MAJOR`, `MINOR`, `PATCH`, and `QFE` version numbers from the source code by grepping for values of the `#defines` that correspond to those values. Refactorings and Script Parameters ================================== Merge `pogo_build.ps1` into `run_build.ps1`. Passing the required pogo-related flags to `run_build.ps1` produces a POGO build. No need to have separate scripts. Compute `ObjectDirectory` and use that for `Chakra.Generated.BuildInfo.props` unless `TF_BUILD_BUILDDIRECTORY` is specified in the PATH. Infer `$binpath`. For many parameters that were previously specified as environment variables from the environment of the build infrastructure, it is now possible to specify them as script parameters directly, where script parameters will take precedence over the values of the corresponding environment variables. This can be helpful when running scripts manually where you want to quickly experiment with the value of a variable without having to write it to the environment first. Since it is sometime valuable to get that variable from the environment, if the script parameter is unspecified, the value of the environment variable will be used instead. Additionally, if any parameter is unspecified by either script parameter or environment variable, a reasonable default is encoded in the script logic. In order of precedence, all values will be determined by checking for values in the following order, if applicable: 1. Script parameter 2. Environment variable 3. Script logic to retrieve value 4. Default value Add parameters with corresponding environment variables to specify skipping certain paths through the build scripts, which can save time when testing certain changes by ignoring expensive but unimportant parts of the builds. Specifying an environment value at the time the build is queued is easier than modifying the build definition, so adding the environment variable option adds convenience when testing with the production build definitions. * `run_build.ps1 -skipPogo` or set `SKIP_POGO` to a non-empty string will skip the POGO phase of the build, if it would have been a POGO build. Useful if the build binaries produced at the correct locations is enough and you're most interested in testing the non-POGO-related aspects of the build scripts. * `post_build.ps1 -skipTests` or set `SKIP_TESTS` to a non-empty string will skip running tests, which can be lengthy. This is useful if the quality of the binaries produced is not important and you're interested in testing other aspects of the build scripts. Miscellaneous ------------- Reduce dependencies on data from build server environments so that these scripts can be used to perform local builds. Update `UseValueOrDefault` to take any number of arguments. Reduce dependency on `locate_msbuild.ps1`. Add `$BuildSubtype` to 'not enough info' error. Check for the existence of `nuget.exe` before trying to invoke it. This helps when running in environments where NuGet is not installed or is not available. Can avoid errors related to NuGet package restore when running on a build server with a custom NuGet location and a specific NuGet Task separate from our scripts. Keeping the NuGet invocation in our scripts allows us to still do local builds without MicroBuild infrastructure configured on the dev machine (we don't take a hard dependency on the aforementioned NuGet Task.
2 parents f05c42e + 60b8f01 commit 5e09810

File tree

12 files changed

+254
-235
lines changed

12 files changed

+254
-235
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ Build/Chakra.Core.VC.opendb
3232
test/benchmarks/*.txt
3333
test/benchmarks/*.dpl
3434
*.nupkg
35+
_DROP
36+
packages.config

Build/Common.Build.Default.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
<PlatformPathNameAlt Condition="'$(Platform)'=='x64'">amd64</PlatformPathNameAlt>
5959
</PropertyGroup>
6060

61-
6261
<!-- Default output directories -->
6362
<PropertyGroup>
6463
<OutBaseDir Condition="'$(OutBaseDir)'!=''">$(OutBaseDir)\$(SolutionName)</OutBaseDir>
@@ -68,7 +67,11 @@
6867
</PropertyGroup>
6968

7069
<!-- Import generated build info -->
71-
<Import Project="$(TF_BUILD_BUILDDIRECTORY)\Chakra.Generated.BuildInfo.props" Condition="'$(TF_BUILD_BUILDDIRECTORY)' != '' AND exists('$(TF_BUILD_BUILDDIRECTORY)\Chakra.Generated.BuildInfo.props')" />
70+
<PropertyGroup>
71+
<ObjectDirectory Condition="'$(TF_BUILD_BUILDDIRECTORY)'!=''">$(TF_BUILD_BUILDDIRECTORY)</ObjectDirectory>
72+
<ObjectDirectory Condition="'$(TF_BUILD_BUILDDIRECTORY)'==''">$(IntBaseDir)\obj\$(PlatformPathName.ToLower())_$(Configuration.ToLower())</ObjectDirectory>
73+
</PropertyGroup>
74+
<Import Project="$(ObjectDirectory)\Chakra.Generated.BuildInfo.props" Condition="'$(ObjectDirectory)'!='' AND exists('$(ObjectDirectory)\Chakra.Generated.BuildInfo.props')" />
7275

7376
<!-- Output directories -->
7477
<PropertyGroup>

Build/scripts/finalize_build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ $buildFlavorJson | Add-Member -type NoteProperty -name flavor -value $Env:BuildC
101101
$buildFlavorJson | Add-Member -type NoteProperty -name subtype -value $Env:BuildSubtype
102102

103103
$buildFlavorJson | ConvertTo-Json | Write-Output
104-
$buildFlavorJson | ConvertTo-Json | Out-File $buildFlavorJsonFile -Encoding ascii
104+
$buildFlavorJson | ConvertTo-Json | Out-File $buildFlavorJsonFile -Encoding utf8
105105

106106
#
107107
# Copy outputs to metadata directory

Build/scripts/init_build.ps1

Lines changed: 110 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,47 @@
1212
# before running the Pre-Build script.
1313

1414
param (
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+
83109
if (-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
111159
if ($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
128175
The 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
132179
New-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")
134181
New-Item -ItemType Directory -Force -Path (Join-Path $BinariesDirectory "buildlogs")
135182
New-Item -ItemType Directory -Force -Path (Join-Path $BinariesDirectory "logs")
136183

137184
$FlavorBuildIncompleteFile = Join-Path $DropPath "${BuildType}.incomplete"
138185

139186
if (-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
@"
149196
set BranchName=${BranchName}
197+
set ShortBranch=${ShortBranch}
150198
set BranchPath=${BranchPath}
151199
set YearAndMonth=${YearAndMonth}
152200
set 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}
155208
set VersionString=${VersionString}
156209
set PreviewVersionString=${PreviewVersionString}
157210
set PushDate=${PushDate}
158211
set CommitTime=${CommitTime}
159212
set Username=${Username}
160213
set CommitHash=${CommitHash}
214+
set CommitShortHash=${CommitShortHash}
161215
162216
set ComputedDropPathSegment=${ComputedDropPathSegment}
163217
set BinariesDirectory=${BinariesDirectory}
@@ -174,24 +228,30 @@ set FlavorBuildIncompleteFile=${FlavorBuildIncompleteFile}
174228
set 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}
184238
set TF_BUILD_DROPLOCATION=${BinariesDirectory}
185239
186-
set TF_BUILD_SOURCESDIRECTORY=${Env:BUILD_SOURCESDIRECTORY}
240+
set TF_BUILD_SOURCESDIRECTORY=${SourcesDirectory}
187241
set TF_BUILD_BUILDDIRECTORY=${ObjectDirectory}
188242
set TF_BUILD_BINARIESDIRECTORY=${BinariesDirectory}
189243
244+
REM The following variables are only used for logging build metadata.
190245
set TF_BUILD_BUILDDEFINITIONNAME=${Env:BUILD_DEFINITIONNAME}
191246
set TF_BUILD_BUILDNUMBER=${Env:BUILD_BUILDNUMBER}
192247
set 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}"
216276
Write-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

Comments
 (0)