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
88function WriteCommonArguments () {
99 WriteMessage " Source Path: $srcpath "
10+ WriteMessage " Build Root: $buildRoot "
1011 WriteMessage " Object Path: $objpath "
1112 WriteMessage " Binaries Path: $binpath "
1213}
1314
1415function 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) {
2526function 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+
4967function 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