Skip to content

Commit 85fa291

Browse files
committed
[1.2>1.3] [MERGE #2256 @dilijev] run_build.ps1: Refactor and fix some bugs with VSO pogo builds of ChakraCore.
Merge pull request #2256 from dilijev:iffnuget * Fix inverted logic for running NuGet.exe. * Fix incorrect $binpath fallback location. * Refactor build scripts: rename confusingly-named variables, information hiding.
2 parents 23606de + c5bb082 commit 85fa291

File tree

8 files changed

+108
-91
lines changed

8 files changed

+108
-91
lines changed

Build/scripts/compose_build.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ $changeInfo = (Get-Content $changeJson) -join "`n" | ConvertFrom-Json
3939
# between the partially-composed root and the metadata directories.
4040
# Exclude change.json and build.json, the results of a previous composition already in the root.
4141
Get-ChildItem -Path $rootPath "*.json" -Recurse `
42-
| ? { -not ($_.Name -in @("change.json", "build.json")) } `
43-
| % { Move-Item -Verbose -Force -Path $_.FullName -Destination $rootPath }
42+
| Where-Object { -not ($_.Name -in @("change.json", "build.json")) } `
43+
| ForEach-Object { Move-Item -Verbose -Force -Path $_.FullName -Destination $rootPath }
4444

4545
# Determine the overall build status. Mark the build as "passed" until "failed" is encountered.
4646
$overallBuildStatus = "passed"
4747

4848
$files = Get-ChildItem -Path $rootPath "*.json" -Recurse `
49-
| ? { -not ($_.Name -in @("change.json", "build.json")) } `
50-
| % { $_.FullName }
49+
| Where-Object { -not ($_.Name -in @("change.json", "build.json")) } `
50+
| ForEach-Object { $_.FullName }
5151
$builds = New-Object System.Collections.ArrayList
5252
foreach ($file in $files) {
5353
$json = (Get-Content $file) -join "`n" | ConvertFrom-Json

Build/scripts/finalize_build.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ param (
2323
$corePathSegment = "" # e.g. "core"
2424
)
2525

26-
$sourcesDir = $Env:BUILD_SOURCESDIRECTORY
27-
$coreSourcesDir = Join-Path $sourcesDir $corePathSegment
26+
. $PSScriptRoot\pre_post_util.ps1
27+
28+
$sourcesDir, $_, $_, $_ = `
29+
ComputePaths `
30+
-arch $arch -flavor $flavor -subtype $subtype -OuterScriptRoot $PSScriptRoot
2831

29-
$OuterScriptRoot = $PSScriptRoot
30-
. "$PSScriptRoot\pre_post_util.ps1"
32+
$coreSourcesDir = Join-Path $sourcesDir $corePathSegment
3133

3234
$buildName = ConstructBuildName -arch $arch -flavor $flavor -subtype $subtype
3335

@@ -118,7 +120,7 @@ Copy-Item -Verbose -Force $buildFlavorJsonFile $metadataDir
118120

119121
# Search for *.nuspec files and copy them to $metadataDir
120122
Get-ChildItem -Path (Join-Path $sourcesDir "Build") "*.nuspec" `
121-
| % { Copy-Item -Verbose -Force $_.FullName $metadataDir }
123+
| ForEach-Object { Copy-Item -Verbose -Force $_.FullName $metadataDir }
122124

123125
#
124126
# Copy POGO directory if present for this build

Build/scripts/init_build.ps1

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ param (
3636
[string]$oauth
3737
)
3838

39+
. $PSScriptRoot\pre_post_util.ps1
40+
3941
#
40-
# Define values for variables based on parameters and environment variables
41-
# with default values in case the environment variables are not defined.
42+
# Process build type parameters
4243
#
4344

44-
. $PSScriptRoot\util.ps1
45-
$gitExe = GetGitPath
45+
# Define values for variables based on parameters and environment variables
46+
# with default values in case the environment variables are not defined.
4647

4748
$BuildType = UseValueOrDefault $buildtype $Env:BuildType
4849
$BuildPlatform = UseValueOrDefault $arch $Env:BuildPlatform
@@ -85,34 +86,30 @@ if ($BuildType) {
8586
exit 1
8687
}
8788

88-
$CommitHash = UseValueOrDefault $Env:BUILD_SOURCEVERSION $(iex "${gitExe} rev-parse HEAD")
89+
$gitExe = GetGitPath
90+
91+
$CommitHash = UseValueOrDefault $Env:BUILD_SOURCEVERSION $(Invoke-Expression "${gitExe} rev-parse HEAD")
8992

90-
$branchFullName = UseValueOrDefault $Env:BUILD_SOURCEBRANCH $(iex "${gitExe} rev-parse --symbolic-full-name HEAD")
93+
$branchFullName = UseValueOrDefault $Env:BUILD_SOURCEBRANCH $(Invoke-Expression "${gitExe} rev-parse --symbolic-full-name HEAD")
9194

9295
$SourcesDirectory = UseValueOrDefault $Env:BUILD_SOURCESDIRECTORY $(GetRepoRoot)
9396
$BinariesDirectory = UseValueOrDefault (Join-Path $SourcesDirectory "Build\VcBuild")
9497
$ObjectDirectory = Join-Path $BinariesDirectory "obj\${BuildPlatform}_${BuildConfiguration}"
9598

9699
$DropRoot = UseValueOrDefault $dropRoot $Env:DROP_ROOT (Join-Path $(GetRepoRoot) "_DROP")
97100

98-
# set up required variables and import pre_post_util.ps1
99-
$arch = $BuildPlatform
100-
$flavor = $BuildConfiguration
101-
$OuterScriptRoot = $PSScriptRoot # Used in pre_post_util.ps1
102-
. "$PSScriptRoot\pre_post_util.ps1"
103-
104101
$BuildName = ConstructBuildName -arch $BuildPlatform -flavor $BuildConfiguration -subtype $BuildSubtype
105102

106103
$BranchName = $branchFullName.split('/',3)[2]
107104
$BranchPath = $BranchName.replace('/','\')
108105

109106
if (-not $CommitHash) {
110-
$CommitHash = iex "${gitExe} rev-parse HEAD"
107+
$CommitHash = Invoke-Expression "${gitExe} rev-parse HEAD"
111108
}
112-
$CommitShortHash = $(iex "${gitExe} rev-parse --short $CommitHash")
109+
$CommitShortHash = $(Invoke-Expression "${gitExe} rev-parse --short $CommitHash")
113110

114-
$Username = (iex "${gitExe} log $CommitHash -1 --pretty=%ae").split('@')[0]
115-
$CommitDateTime = [DateTime]$(iex "${gitExe} log $CommitHash -1 --pretty=%aD")
111+
$Username = (Invoke-Expression "${gitExe} log $CommitHash -1 --pretty=%ae").split('@')[0]
112+
$CommitDateTime = [DateTime]$(Invoke-Expression "${gitExe} log $CommitHash -1 --pretty=%aD")
116113
$CommitTime = Get-Date $CommitDateTime -Format yyMMdd.HHmm
117114

118115
#

Build/scripts/post_build.ps1

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ param (
2323
[string]$subtype = "default",
2424

2525
[string]$srcpath = "",
26-
[string]$binpath = "",
26+
[string]$buildRoot = "",
2727
[string]$objpath = "",
2828

2929
[Parameter(Mandatory=$True)]
@@ -44,29 +44,31 @@ param (
4444
[switch]$skipTests # or set $Env:SKIP_TESTS before invoking build
4545
)
4646

47+
. $PSScriptRoot\pre_post_util.ps1
48+
49+
$srcpath, $buildRoot, $objpath, $_ = `
50+
ComputePaths `
51+
-arch $arch -flavor $flavor -subtype $subtype -OuterScriptRoot $PSScriptRoot `
52+
-srcpath $srcpath -buildRoot $buildRoot -objpath $objpath -binpath $_
53+
4754
$skipTests = $skipTests -or (Test-Path Env:\SKIP_TESTS)
4855

4956
$global:exitcode = 0
5057

5158
if ($arch -eq "*") {
5259

53-
. "$PSScriptRoot\util.ps1"
5460
foreach ($arch in ("x86", "x64", "arm")) {
55-
ExecuteCommand "$PSScriptRoot\post_build.ps1 -arch $arch -flavor $flavor -srcpath ""$srcpath"" -binpath ""$binpath"" -objpath ""$objpath"" -srcsrvcmdpath ""$srcsrvcmdpath"" -bvtcmdpath ""$bvtcmdpath"" -repo ""$repo""" -logFile ""$logFile""
61+
ExecuteCommand "$PSScriptRoot\post_build.ps1 -arch $arch -flavor $flavor -srcpath ""$srcpath"" -buildRoot ""$buildRoot"" -objpath ""$objpath"" -srcsrvcmdpath ""$srcsrvcmdpath"" -bvtcmdpath ""$bvtcmdpath"" -repo ""$repo""" -logFile ""$logFile""
5662
}
5763

5864
} elseif ($flavor -eq "*") {
5965

60-
. "$PSScriptRoot\util.ps1"
6166
foreach ($flavor in ("debug", "test", "release")) {
62-
ExecuteCommand "$PSScriptRoot\post_build.ps1 -arch $arch -flavor $flavor -srcpath ""$srcpath"" -binpath ""$binpath"" -objpath ""$objpath"" -srcsrvcmdpath ""$srcsrvcmdpath"" -bvtcmdpath ""$bvtcmdpath"" -repo ""$repo""" -logFile ""$logFile""
67+
ExecuteCommand "$PSScriptRoot\post_build.ps1 -arch $arch -flavor $flavor -srcpath ""$srcpath"" -buildRoot ""$buildRoot"" -objpath ""$objpath"" -srcsrvcmdpath ""$srcsrvcmdpath"" -bvtcmdpath ""$bvtcmdpath"" -repo ""$repo""" -logFile ""$logFile""
6368
}
6469

6570
} else {
6671

67-
$OuterScriptRoot = $PSScriptRoot
68-
. "$PSScriptRoot\pre_post_util.ps1"
69-
7072
$buildName = ConstructBuildName -arch $arch -flavor $flavor -subtype $subtype
7173

7274
if (($logFile -eq "") -and (Test-Path Env:\TF_BUILD_BINARIESDIRECTORY)) {
@@ -86,12 +88,12 @@ if ($arch -eq "*") {
8688
WriteMessage "BVT Command : $bvtcmdpath"
8789
WriteMessage ""
8890

89-
$srcsrvcmd = ("{0} {1} {2} {3}\bin\{4}\*.pdb" -f $srcsrvcmdpath, $repo, $srcpath, $binpath, $buildName)
90-
$prefastlog = ("{0}\logs\PrefastCheck.{1}.log" -f $binpath, $buildName)
91+
$srcsrvcmd = ("{0} {1} {2} {3}\bin\{4}\*.pdb" -f $srcsrvcmdpath, $repo, $srcpath, $buildRoot, $buildName)
92+
$prefastlog = ("{0}\logs\PrefastCheck.{1}.log" -f $buildRoot, $buildName)
9193
$prefastcmd = "$PSScriptRoot\check_prefast_error.ps1 -directory $objpath -logFile $prefastlog"
9294

9395
# generate srcsrv
94-
if ((Test-Path $srcsrvcmdpath) -and (Test-Path $srcpath) -and (Test-Path $binpath)) {
96+
if ((Test-Path $srcsrvcmdpath) -and (Test-Path $srcpath) -and (Test-Path $buildRoot)) {
9597
ExecuteCommand($srcsrvcmd)
9698
}
9799

Build/scripts/pre_build.ps1

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,26 @@ param (
4545
[string]$oauth
4646
)
4747

48-
$OuterScriptRoot = $PSScriptRoot # Used in pre_post_util.ps1
49-
. "$PSScriptRoot\pre_post_util.ps1"
48+
. $PSScriptRoot\pre_post_util.ps1
5049

51-
if (($logFile -eq "") -and (Test-Path Env:\TF_BUILD_BINARIESDIRECTORY)) {
52-
if (-not(Test-Path -Path "${Env:TF_BUILD_BINARIESDIRECTORY}\logs")) {
53-
$dummy = New-Item -Path "${Env:TF_BUILD_BINARIESDIRECTORY}\logs" -ItemType Directory -Force
50+
$srcpath, $buildRoot, $objpath, $binpath = `
51+
ComputePaths `
52+
-arch $arch -flavor $flavor -subtype $subtype -OuterScriptRoot $PSScriptRoot `
53+
-srcpath $srcpath -buildRoot $buildRoot -objpath $objpath -binpath $binpath
54+
55+
WriteCommonArguments
56+
57+
$buildName = ConstructBuildName $arch $flavor $subtype
58+
if (($logFile -eq "") -and (Test-Path $buildRoot)) {
59+
if (-not(Test-Path -Path "${buildRoot}\logs")) {
60+
$dummy = New-Item -Path "${buildRoot}\logs" -ItemType Directory -Force
5461
}
55-
$logFile = "${Env:TF_BUILD_BINARIESDIRECTORY}\logs\pre_build.${Env:BuildName}.log"
62+
$logFile = "${buildRoot}\logs\pre_build.${buildName}.log"
5663
if (Test-Path -Path $logFile) {
5764
Remove-Item $logFile -Force
5865
}
5966
}
6067

61-
WriteCommonArguments
62-
6368
#
6469
# Create packages.config files
6570
#
@@ -72,7 +77,7 @@ $packagesConfigFileText = @"
7277
"@
7378

7479
$packagesFiles = Get-ChildItem -Path $Env:TF_BUILD_SOURCESDIRECTORY *.vcxproj -Recurse `
75-
| % { Join-Path $_.DirectoryName "packages.config" }
80+
| ForEach-Object { Join-Path $_.DirectoryName "packages.config" }
7681

7782
foreach ($file in $packagesFiles) {
7883
if (-not (Test-Path $file)) {
@@ -91,7 +96,7 @@ if (Test-Path Env:\TF_BUILD_SOURCEGETVERSION)
9196

9297
$CoreHash = ""
9398
if (Test-Path $corePath) {
94-
$CoreHash = iex "$gitExe rev-parse ${commitHash}:core"
99+
$CoreHash = Invoke-Expression "$gitExe rev-parse ${commitHash}:core"
95100
if (-not $?) {
96101
$CoreHash = ""
97102
}
@@ -112,7 +117,7 @@ if (Test-Path Env:\TF_BUILD_SOURCEGETVERSION)
112117

113118
# commit message
114119
$command = "$gitExe log -1 --name-only -p $commitHash"
115-
$CommitMessageLines = iex $command
120+
$CommitMessageLines = Invoke-Expression $command
116121
$CommitMessage = $CommitMessageLines -join "`r`n"
117122

118123
$changeTextFile = Join-Path -Path $outputDir -ChildPath "change.txt"
@@ -183,7 +188,7 @@ $CommitMessage
183188
</Project>
184189
"@
185190

186-
$propsFileContent = $propsFileTemplate -f $binpath, $objpath, $buildPushIdPart1, $buildPushIdPart2, $buildCommit, $buildDate
191+
$propsFileContent = $propsFileTemplate -f $buildRoot, $objpath, $buildPushIdPart1, $buildPushIdPart2, $buildCommit, $buildDate
187192

188193
Write-Output "-----"
189194
Write-Output $propsFile

Build/scripts/pre_post_util.ps1

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
#-------------------------------------------------------------------------------------------------------
55

6-
. "$PSScriptRoot\util.ps1"
6+
. $PSScriptRoot\util.ps1
77

88
function WriteCommonArguments() {
99
WriteMessage " Source Path: $srcpath"
10+
WriteMessage " Build Root: $buildRoot"
1011
WriteMessage " Object Path: $objpath"
1112
WriteMessage "Binaries Path: $binpath"
1213
}
1314

1415
function GetVersionField($fieldname) {
1516
$gitExe = GetGitPath
1617
$query = "#define ${fieldname} (\d+)"
17-
$line = (iex "${gitExe} grep -P ""${query}"" :/")
18+
$line = (Invoke-Expression "${gitExe} grep -P ""${query}"" :/")
1819
$matches = $line | Select-String $query
1920
if ($matches) {
2021
return $matches[0].Matches.Groups[1].Value
@@ -25,7 +26,8 @@ function GetVersionField($fieldname) {
2526
function GetBuildInfo($oauth, $commitHash) {
2627
# Get the git remote path and construct the REST API URI
2728
$gitExe = GetGitPath
28-
$remote = (iex "$gitExe remote -v" | ? { $_.contains("_git") })[0].split()[1].replace("_git", "_apis/git/repositories")
29+
$remote = (Invoke-Expression "$gitExe remote -v" `
30+
| Where-Object { $_.contains("_git") })[0].split()[1].replace("_git", "_apis/git/repositories")
2931
$remote = $remote.replace("mshttps", "https")
3032

3133
# Get the pushId and push date time to use that for build number and build date time
@@ -46,7 +48,25 @@ function GetBuildPushId($info) {
4648
return @($buildPushId, $buildPushIdPart1, $buildPushIdPart2, $buildPushIdString)
4749
}
4850

51+
function EnsureVariables($functionName, $arch, $flavor, $OuterScriptRoot) {
52+
if (("$arch" -eq "") -or ("$flavor" -eq "") -or ("$OuterScriptRoot" -eq ""))
53+
{
54+
WriteErrorMessage @"
55+
56+
${functionName}: Required variables not set:
57+
`$arch = $arch
58+
`$flavor = $flavor
59+
`$OuterScriptRoot = $OuterScriptRoot
60+
61+
"@
62+
63+
throw "Cannot continue: ${functionName}: required variables not set."
64+
}
65+
}
66+
4967
function ConstructBuildName($arch, $flavor, $subtype) {
68+
EnsureVariables "ConstructBuildName" $arch $flavor "(OuterScriptRoot not needed)"
69+
5070
if ($subtype -eq "codecoverage") {
5171
# TODO eliminate tools' dependency on this particular formatting exception
5272
# Normalize the $BuildName of even if the $BuildType is e.g. x64_test_codecoverage
@@ -58,22 +78,12 @@ function ConstructBuildName($arch, $flavor, $subtype) {
5878
}
5979
}
6080

61-
# Compute paths
62-
63-
if (("$arch" -eq "") -or ("$flavor" -eq "") -or ("$OuterScriptRoot" -eq ""))
64-
{
65-
WriteErrorMessage @"
66-
67-
Required variables not set before script was included:
68-
`$arch = $arch
69-
`$flavor = $flavor
70-
`$OuterScriptRoot = $OuterScriptRoot
71-
72-
"@
73-
74-
throw "Cannot continue - required variables not set."
81+
function ComputePaths($arch, $flavor, $subtype, $OuterScriptRoot, $srcpath = "", $buildRoot = "", $objpath = "", $binpath = "") {
82+
EnsureVariables "ComputePaths" $arch $flavor $OuterScriptRoot
83+
$buildName = ConstructBuildName $arch $flavor $subtype
84+
$srcpath = UseValueOrDefault $srcpath "$Env:TF_BUILD_SOURCESDIRECTORY" (Resolve-Path "${OuterScriptRoot}\..\..")
85+
$buildRoot = UseValueOrDefault $buildRoot "$Env:BinariesDirectory" "$Env:TF_BUILD_BINARIESDIRECTORY" (Join-Path $srcpath "Build\VcBuild")
86+
$objpath = UseValueOrDefault $objpath "$Env:TF_BUILD_BUILDDIRECTORY" (Join-Path $buildRoot "obj\${buildName}")
87+
$binpath = Join-Path $buildRoot "bin\${buildName}"
88+
return @($srcpath, $buildRoot, $objpath, $binpath)
7589
}
76-
77-
$srcpath = UseValueOrDefault $srcpath "$env:TF_BUILD_SOURCESDIRECTORY" (Resolve-Path "$OuterScriptRoot\..\..")
78-
$objpath = UseValueOrDefault $objpath "$env:TF_BUILD_BUILDDIRECTORY" "${srcpath}\Build\VcBuild\obj\${arch}_${flavor}"
79-
$binpath = UseValueOrDefault $binpath "$env:TF_BUILD_BINARIESDIRECTORY" "${srcpath}\Build\VcBuild"

0 commit comments

Comments
 (0)