Browse code

msvc: add branch name and commit hash to version output

Add a simple python script which generates header with
branch name and commit hash #defines.

While on it, fix filename in msvc-generate.vcxproj
and add proper copyright header to Makefile.mak.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20220926070843.717-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25314.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Lev Stipakov authored on 2022/09/26 16:08:43
Showing 4 changed files
... ...
@@ -1,4 +1,27 @@
1
-# Copyright (C) 2008-2012 Alon Bar-Lev <alon.barlev@gmail.com>
1
+#
2
+#  OpenVPN -- An application to securely tunnel IP networks
3
+#             over a single UDP port, with support for SSL/TLS-based
4
+#             session authentication and key exchange,
5
+#             packet encryption, packet authentication, and
6
+#             packet compression.
7
+#
8
+#  Copyright (C) 2002-2022 OpenVPN Inc <sales@openvpn.net>
9
+#  Copyright (C) 2008-2012 Alon Bar-Lev <alon.barlev@gmail.com>
10
+#  Copyright (C) 2022-2022 Lev Stipakov <lev@lestisoftware.fi>
11
+#
12
+#  This program is free software; you can redistribute it and/or modify
13
+#  it under the terms of the GNU General Public License version 2
14
+#  as published by the Free Software Foundation.
15
+#
16
+#  This program is distributed in the hope that it will be useful,
17
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+#  GNU General Public License for more details.
20
+#
21
+#  You should have received a copy of the GNU General Public License along
22
+#  with this program; if not, write to the Free Software Foundation, Inc.,
23
+#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
+#
2 25
 
3 26
 CONFIG=$(SOLUTIONDIR)/version.m4
4 27
 
... ...
@@ -14,7 +37,9 @@ OUTPUT_PLUGIN_CONFIG=version.m4
14 14
 INPUT_MAN=$(SOLUTIONDIR)/doc/openvpn.8.rst
15 15
 OUTPUT_MAN=$(SOLUTIONDIR)/doc/openvpn.8.html
16 16
 
17
-all:	$(OUTPUT_MSVC_VER) $(OUTPUT_PLUGIN) $(OUTPUT_MAN)
17
+OUTPUT_MSVC_GIT_CONFIG=$(SOLUTIONDIR)/config-version.h
18
+
19
+all:	$(OUTPUT_MSVC_VER) $(OUTPUT_PLUGIN) $(OUTPUT_MAN) $(OUTPUT_MSVC_GIT_CONFIG)
18 20
 
19 21
 $(OUTPUT_MSVC_VER): $(INPUT_MSVC_VER) $(CONFIG)
20 22
 	cscript //nologo msvc-generate.js --config="$(CONFIG)" --input="$(INPUT_MSVC_VER)" --output="$(OUTPUT_MSVC_VER)"
... ...
@@ -28,8 +53,12 @@ $(OUTPUT_PLUGIN): $(INPUT_PLUGIN) $(OUTPUT_PLUGIN_CONFIG)
28 28
 $(OUTPUT_MAN): $(INPUT_MAN)
29 29
     -FOR /F %i IN ('where rst2html.py') DO python %i "$(INPUT_MAN)" "$(OUTPUT_MAN)"
30 30
 
31
+$(OUTPUT_MSVC_GIT_CONFIG):
32
+    python git-version.py $(SOLUTIONDIR)
33
+
31 34
 clean:
32 35
 	-del "$(OUTPUT_MSVC_VER)"
33 36
 	-del "$(OUTPUT_PLUGIN)"
34 37
 	-del "$(OUTPUT_PLUGIN_CONFIG)"
35 38
 	-del "$(OUTPUT_MAN)"
39
+	-del "$(OUTPUT_MSVC_GIT_CONFIG)"
36 40
new file mode 100644
... ...
@@ -0,0 +1,50 @@
0
+#
1
+#  OpenVPN -- An application to securely tunnel IP networks
2
+#             over a single UDP port, with support for SSL/TLS-based
3
+#             session authentication and key exchange,
4
+#             packet encryption, packet authentication, and
5
+#             packet compression.
6
+#
7
+#  Copyright (C) 2022-2022 OpenVPN Inc <sales@openvpn.net>
8
+#  Copyright (C) 2022-2022 Lev Stipakov <lev@lestisoftware.fi>
9
+#
10
+#  This program is free software; you can redistribute it and/or modify
11
+#  it under the terms of the GNU General Public License version 2
12
+#  as published by the Free Software Foundation.
13
+#
14
+#  This program is distributed in the hope that it will be useful,
15
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+#  GNU General Public License for more details.
18
+#
19
+#  You should have received a copy of the GNU General Public License along
20
+#  with this program; if not, write to the Free Software Foundation, Inc.,
21
+#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
+#
23
+
24
+import os
25
+import sys
26
+
27
+def get_branch_commit_id():
28
+    commit_id = os.popen("git rev-parse --short=16 HEAD").read()[:-1]
29
+    if not commit_id:
30
+        raise
31
+    l = os.popen("git rev-parse --symbolic-full-name HEAD").read().split("/")[2:]
32
+    if not l:
33
+        l = ["none\n"]
34
+    branch = "/" .join(l)[:-1]
35
+    return branch, commit_id
36
+
37
+def main():
38
+    try:
39
+        branch, commit_id = get_branch_commit_id()
40
+    except:
41
+        branch, commit_id = "unknown", "unknown"
42
+
43
+    name = os.path.join("%s" %  (sys.argv[1] if len(sys.argv) > 1 else "."), "config-version.h")
44
+    with open(name, "w") as f:
45
+        f.write("#define CONFIGURE_GIT_REVISION \"%s/%s\"\n" % (branch, commit_id))
46
+        f.write("#define CONFIGURE_GIT_FLAGS \"\"\n")
47
+
48
+if __name__ == "__main__":
49
+    main()
... ...
@@ -150,7 +150,7 @@
150 150
   </ItemDefinitionGroup>
151 151
   <ItemGroup>
152 152
     <None Include="Makefile.mak" />
153
-    <None Include="msc-generate.js" />
153
+    <None Include="msvc-generate.js" />
154 154
   </ItemGroup>
155 155
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
156 156
   <ImportGroup Label="ExtensionTargets">
... ...
@@ -177,3 +177,5 @@ typedef uint16_t in_port_t;
177 177
     #define HAVE_INET_NTOP
178 178
     #define HAVE_INET_PTON
179 179
 #endif
180
+
181
+#define HAVE_CONFIG_VERSION_H 1