]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/utils/SRCVERSION.ps1
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / utils / SRCVERSION.ps1
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2016-2020, Intel Corporation
3
4 #
5 # SRCVERSION.PS1 -- script to create SCRVERSION macro and generate srcversion.h
6 #
7
8 #
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.
15 #
16 # Examples:
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 # +---------------------+-----+-----+--------+-----+------+-------+----------+
29 #
30
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
36
37 if (Test-Path $file_path) {
38 $old_src_version = Get-Content $file_path | `
39 Where-Object { $_ -like '#define SRCVERSION*' }
40 } else {
41 $old_src_version = ""
42 }
43
44 $git_version = ""
45 $git_version_hash = ""
46
47 if (Test-Path $git_version_file) {
48 $git_version = Get-Content $git_version_file
49 if ($git_version -eq "`$Format:%h`$") {
50 $git_version = ""
51 } else {
52 $git_version_hash = $git_version
53 }
54 }
55
56 $PRERELEASE = $false
57 $BUGFIX = $false
58 $PRIVATE = $true
59 $CUSTOM = $false
60
61 if ($null -ne $args[0]) {
62 $version = $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 "") {
68 $MAJOR = 0
69 $MINOR = 0
70 $REVISION = 0
71 $BUILD = 0
72
73 $version = $git_version_hash
74 $CUSTOM = $true
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("-+")
79 } else {
80 $MAJOR = 0
81 $MINOR = 0
82 $REVISION = 0
83 $BUILD = 0
84
85 $version = "UNKNOWN_VERSION"
86 $CUSTOM = $true
87 $version_custom_msg = "#define VERSION_CUSTOM_MSG `"UNKNOWN_VERSION`""
88 }
89
90 if ($null -ne $ver_array) {
91 $ver_dots = $ver_array[0].split(".")
92 $MAJOR = $ver_dots[0]
93 $MINOR = $ver_dots[1]
94 if ($ver_dots.length -ge 3) {
95 $REV = $ver_dots[2]
96 $BUGFIX = $true
97 } else {
98 $REV = 0
99 }
100
101 $REVISION = 1000 * $REV
102 $BUILD = $ver_array[$ver_array.length - 2]
103
104 if ($ver_array.length -eq 4) {
105 # <MAJOR>.<MINOR>[.<BUGFIX>]-<SUFFIX><REVISION>-<BUILD>-<HASH>
106
107 if ($ver_array[1].StartsWith("rc")) {
108 # <MAJOR>.<MINOR>[.<BUGFIX>]-rc<REVISION>-<BUILD>-<HASH>
109 $REVISION += $ver_array[1].Substring("rc".Length)
110 $PRERELEASE = $true
111 $version = "$($ver_array[0])-$($ver_array[1])+git$($ver_array[2]).$($ver_array[3])"
112 } else {
113 # <MAJOR>.<MINOR>[.<BUGFIX>]-<SOMETHING>-<BUILD>-<HASH>
114 throw "Unknown version format"
115 }
116 } else {
117 # <MAJOR>.<MINOR>[.<BUGFIX>]-<BUILD>-<HASH>
118 $REVISION += 100
119 $version = "$($ver_array[0])+git$($ver_array[1]).$($ver_array[2])"
120 }
121
122 if ($BUILD -eq 0) {
123 # it is not a (pre)release build
124 $PRIVATE = $false
125 }
126 }
127
128 $src_version = "#define SRCVERSION `"$version`""
129
130 if ($old_src_version -eq $src_version) {
131 exit 0
132 }
133
134 Write-Output "updating source version: $version"
135 Write-Output $src_version > $file_path
136
137 Write-Output "#ifdef RC_INVOKED" >> $file_path
138
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
143
144 if ($PRERELEASE) {
145 Write-Output "#define PRERELEASE 1" >> $file_path
146 }
147 if ($BUGFIX) {
148 Write-Output "#define BUGFIX 1" >> $file_path
149 }
150 if ($PRIVATE) {
151 Write-Output "#define PRIVATE 1" >> $file_path
152 }
153 if ($CUSTOM) {
154 Write-Output "#define CUSTOM 1" >> $file_path
155 Write-Output $version_custom_msg >> $file_path
156 }
157
158 Write-Output "#endif" >> $file_path