@@ -5,6 +5,90 @@ $script:TestModulePathSeparator = [System.IO.Path]::PathSeparator
55$dotnetCLIChannel = " preview"
66$dotnetCLIRequiredVersion = " 2.0.0-preview2-006502"
77
8+ # Track if tags have been sync'ed
9+ $tagsUpToDate = $false
10+
11+ # Sync Tags
12+ # When not using a branch in PowerShell/PowerShell, tags will not be fetched automatically
13+ # Since code that uses Get-PSCommitID and Get-PSLatestTag assume that tags are fetched,
14+ # This function can ensure that tags have been fetched.
15+ # This function is used during the setup phase in tools/appveyor.psm1 and tools/travis.ps1
16+ function Sync-PSTags
17+ {
18+ param (
19+ [Switch ]
20+ $AddRemoteIfMissing
21+ )
22+
23+ $PowerShellRemoteUrl = " https://github.com/powershell/powershell.git"
24+ $upstreamRemoteDefaultName = ' upstream'
25+ $remotes = Start-NativeExecution {git -- git- dir= " $PSScriptRoot /.git" remote}
26+ $upstreamRemote = $null
27+ foreach ($remote in $remotes )
28+ {
29+ $url = Start-NativeExecution {git -- git- dir= " $PSScriptRoot /.git" remote get-url $remote }
30+ if ($url -eq $PowerShellRemoteUrl )
31+ {
32+ $upstreamRemote = $remote
33+ break
34+ }
35+ }
36+
37+ if (! $upstreamRemote -and $AddRemoteIfMissing.IsPresent -and $remotes -notcontains $upstreamRemoteDefaultName )
38+ {
39+ $null = Start-NativeExecution {git -- git- dir= " $PSScriptRoot /.git" remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl }
40+ $upstreamRemote = $upstreamRemoteDefaultName
41+ }
42+ elseif (! $upstreamRemote )
43+ {
44+ Write-Error " Please add a remote to PowerShell\PowerShell. Example: git remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl " - ErrorAction Stop
45+ }
46+
47+ $null = Start-NativeExecution {git -- git- dir= " $PSScriptRoot /.git" fetch -- tags -- quiet $upstreamRemote }
48+ $script :tagsUpToDate = $true
49+ }
50+
51+ # Gets the latest tag for the current branch
52+ function Get-PSLatestTag
53+ {
54+ # This function won't always return the correct value unless tags have been sync'ed
55+ # So, Write a warning to run Sync-PSTags
56+ if (! $tagsUpToDate )
57+ {
58+ Write-Warning " Run Sync-PSTags to update tags"
59+ }
60+
61+ return (Start-NativeExecution {git -- git- dir= " $PSScriptRoot /.git" describe -- abbrev= 0 })
62+ }
63+
64+ function Get-PSVersion
65+ {
66+ param (
67+ [switch ]
68+ $OmitCommitId
69+ )
70+ if ($OmitCommitId.IsPresent )
71+ {
72+ return (Get-PSLatestTag ) -replace ' ^v'
73+ }
74+ else
75+ {
76+ return (Get-PSCommitId ) -replace ' ^v'
77+ }
78+ }
79+
80+ function Get-PSCommitId
81+ {
82+ # This function won't always return the correct value unless tags have been sync'ed
83+ # So, Write a warning to run Sync-PSTags
84+ if (! $tagsUpToDate )
85+ {
86+ Write-Warning " Run Sync-PSTags to update tags"
87+ }
88+
89+ return (Start-NativeExecution {git -- git- dir= " $PSScriptRoot /.git" describe -- dirty -- abbrev= 60 })
90+ }
91+
892function Get-EnvironmentInformation
993{
1094 $environment = @ {}
@@ -268,7 +352,7 @@ function Start-PSBuild {
268352 $gitCommitId = $ReleaseTag
269353 if (-not $gitCommitId ) {
270354 # if ReleaseTag is not specified, use 'git describe' to get the commit id
271- $gitCommitId = git -- git - dir = " $PSScriptRoot /.git " describe -- dirty -- abbrev = 60
355+ $gitCommitId = Get-PSCommitId
272356 }
273357 $gitCommitId > " $psscriptroot /powershell.version"
274358
@@ -1934,35 +2018,6 @@ function script:Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
19342018 }
19352019}
19362020
1937- # Builds coming out of this project can have version number as 'a.b.c-stringf.d-e-f' OR 'a.b.c.d-e-f'
1938- # This function converts the above version into semantic version major.minor[.build-quality[.revision]] format
1939- function Get-PackageSemanticVersion
1940- {
1941- [CmdletBinding ()]
1942- param (
1943- # Version of the Package
1944- [Parameter (Mandatory = $true )]
1945- [ValidateNotNullOrEmpty ()]
1946- [string ] $Version
1947- )
1948-
1949- Write-Verbose " Extract the semantic version in the form of major.minor[.build-quality[.revision]] for $Version "
1950- $packageVersionTokens = $Version.Split (' .' )
1951-
1952- if (3 -eq $packageVersionTokens.Count ) {
1953- # In case the input is of the form a.b.c, add a '0' at the end for revision field
1954- $packageSemanticVersion = $Version , ' 0' -join ' .'
1955- } elseif (3 -lt $packageVersionTokens.Count ) {
1956- # We have all the four fields
1957- $packageRevisionTokens = ($packageVersionTokens [3 ].Split(' -' ))[0 ]
1958- $packageSemanticVersion = $packageVersionTokens [0 ], $packageVersionTokens [1 ], $packageVersionTokens [2 ], $packageRevisionTokens -join ' .'
1959- } else {
1960- throw " Cannot create Semantic Version from the string $Version containing 4 or more tokens"
1961- }
1962-
1963- $packageSemanticVersion
1964- }
1965-
19662021# Builds coming out of this project can have version number as 'a.b.c' OR 'a.b.c-d-f'
19672022# This function converts the above version into major.minor[.build[.revision]] format
19682023function Get-PackageVersionAsMajorMinorBuildRevision
@@ -2035,8 +2090,10 @@ function New-MSIPackage
20352090 [Parameter (Mandatory = $true )]
20362091 [ValidateSet (" x86" , " x64" )]
20372092 [ValidateNotNullOrEmpty ()]
2038- [string ] $ProductTargetArchitecture
2093+ [string ] $ProductTargetArchitecture ,
20392094
2095+ # Force overwrite of package
2096+ [Switch ] $Force
20402097 )
20412098
20422099 # # AppVeyor base image might update the version for Wix. Hence, we should
@@ -2095,7 +2152,11 @@ function New-MSIPackage
20952152 $packageName += " -$ProductNameSuffix "
20962153 }
20972154 $msiLocationPath = Join-Path $pwd " $packageName .msi"
2098- Remove-Item - ErrorAction SilentlyContinue $msiLocationPath - Force
2155+
2156+ if (! $Force.IsPresent -and (Test-Path - Path $msiLocationPath ))
2157+ {
2158+ Write-Error - Message " Package already exists, use -Force to overwrite, path: $msiLocationPath " - ErrorAction Stop
2159+ }
20992160
21002161 & $wixHeatExePath dir $ProductSourcePath - dr $productVersionWithName - cg $productVersionWithName - gg - sfrag - srd - scom - sreg - out $wixFragmentPath - var env.ProductSourcePath - v | Write-Verbose
21012162 & $wixCandleExePath " $ProductWxsPath " " $wixFragmentPath " - out (Join-Path " $env: Temp " " \\" ) - ext WixUIExtension - ext WixUtilExtension - arch x64 - v | Write-Verbose
0 commit comments