1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2016-2020, Intel Corporation
5 # SRCVERSION.PS1 -- script to create SCRVERSION macro and generate srcversion.h
9 # Windows dll versioning supports only fixed number of fields. The most
10 # important are MAJOR, MINOR and REVISION. We have 3-compoment releases
11 # (e.g. 1.5.1) with release candidates, so we have to encode this information
12 # into this fixed number of fields. That's why we abuse REVISION to encode both
13 # 3rd component and rc status.
14 # REVISION = 3RDCOMP * 1000 + (!is_rc) * 100 + rc.
17 # +---------------------+-----+-----+--------+-----+------+-------+----------+
18 # |git describe --long |MAJOR|MINOR|REVISION|BUILD|BUGFIX|PRIVATE|PRERELEASE|
19 # +---------------------+-----+-----+--------+-----+------+-------+----------+
20 # |1.5-rc2-0-12345678 | 1| 5| 2| 0| false| false| true|
21 # |1.5-rc3-6-12345678 | 1| 5| 3| 6| false| true| true|
22 # |1.5-0-12345678 | 1| 5| 100| 0| false| false| false|
23 # |1.5-6-123345678 | 1| 5| 100| 6| false| true| false|
24 # |1.5.2-rc1-0-12345678 | 1| 5| 2001| 0| true| false| true|
25 # |1.5.2-rc4-6-12345678 | 1| 5| 2004| 6| true| true| true|
26 # |1.5.2-0-12345678 | 1| 5| 2100| 0| true| false| false|
27 # |1.5.2-6-12345678 | 1| 5| 2100| 6| true| true| false|
28 # +---------------------+-----+-----+--------+-----+------+-------+----------+
31 $scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
32 $file_path = $scriptPath + "\..\src\windows\include\srcversion.h"
33 $git_version_file = $scriptPath + "\..\GIT_VERSION"
34 $version_file = $scriptPath + "\..\VERSION"
35 $git = Get-Command -Name git -ErrorAction SilentlyContinue
37 if (Test-Path $file_path) {
38 $old_src_version = Get-Content $file_path | `
39 Where-Object { $_ -like '#define SRCVERSION*' }
45 $git_version_hash = ""
47 if (Test-Path $git_version_file) {
48 $git_version = Get-Content $git_version_file
49 if ($git_version -eq "`$Format:%h`$") {
52 $git_version_hash = $git_version
61 if ($null -ne $args[0]) {
63 $ver_array = $version.split("-+")
64 } elseif (Test-Path $version_file) {
65 $version = Get-Content $version_file
66 $ver_array = $version.split("-+")
67 } elseif ($git_version_hash -ne "") {
73 $version = $git_version_hash
75 $version_custom_msg = "#define VERSION_CUSTOM_MSG `"$git_version_hash`""
76 } elseif ($null -ne $git) {
77 $version = $(git describe)
78 $ver_array = $(git describe --long).split("-+")
85 $version = "UNKNOWN_VERSION"
87 $version_custom_msg = "#define VERSION_CUSTOM_MSG `"UNKNOWN_VERSION`""
90 if ($null -ne $ver_array) {
91 $ver_dots = $ver_array[0].split(".")
94 if ($ver_dots.length -ge 3) {
101 $REVISION = 1000 * $REV
102 $BUILD = $ver_array[$ver_array.length - 2]
104 if ($ver_array.length -eq 4) {
105 # <MAJOR>.<MINOR>[.<BUGFIX>]-<SUFFIX><REVISION>-<BUILD>-<HASH>
107 if ($ver_array[1].StartsWith("rc")) {
108 # <MAJOR>.<MINOR>[.<BUGFIX>]-rc<REVISION>-<BUILD>-<HASH>
109 $REVISION += $ver_array[1].Substring("rc".Length)
111 $version = "$($ver_array[0])-$($ver_array[1])+git$($ver_array[2]).$($ver_array[3])"
113 # <MAJOR>.<MINOR>[.<BUGFIX>]-<SOMETHING>-<BUILD>-<HASH>
114 throw "Unknown version format"
117 # <MAJOR>.<MINOR>[.<BUGFIX>]-<BUILD>-<HASH>
119 $version = "$($ver_array[0])+git$($ver_array[1]).$($ver_array[2])"
123 # it is not a (pre)release build
128 $src_version = "#define SRCVERSION `"$version`""
130 if ($old_src_version -eq $src_version) {
134 Write-Output "updating source version: $version"
135 Write-Output $src_version > $file_path
137 Write-Output "#ifdef RC_INVOKED" >> $file_path
139 Write-Output "#define MAJOR $MAJOR" >> $file_path
140 Write-Output "#define MINOR $MINOR" >> $file_path
141 Write-Output "#define REVISION $REVISION" >> $file_path
142 Write-Output "#define BUILD $BUILD" >> $file_path
145 Write-Output "#define PRERELEASE 1" >> $file_path
148 Write-Output "#define BUGFIX 1" >> $file_path
151 Write-Output "#define PRIVATE 1" >> $file_path
154 Write-Output "#define CUSTOM 1" >> $file_path
155 Write-Output $version_custom_msg >> $file_path
158 Write-Output "#endif" >> $file_path