Skip to content

Commit ec22d67

Browse files
committed
version.py can now create WebSocketsVersion.h
1 parent 39e6a8e commit ec22d67

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/WebSocketsVersion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file WebSocketsVersion.h
33
* @date 07.01.2021
44
* @author Markus Sattler
5-
*
5+
*
66
* Copyright (c) 2015 Markus Sattler. All rights reserved.
77
* This file is part of the WebSockets for Arduino.
88
*

travis/version.py

+56-5
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,72 @@
55
import argparse
66
import re
77
import os
8+
import datetime
89

910
travis_dir = os.path.dirname(os.path.abspath(__file__))
1011
base_dir = os.path.abspath(travis_dir + "/../")
1112

13+
def write_header_file(version):
14+
hvs = version.split('.')
15+
intversion = int(hvs[0]) * 1000000 + int(hvs[1]) * 1000 + int(hvs[2])
16+
now = datetime.datetime.now()
17+
18+
text = f'''/**
19+
* @file WebSocketsVersion.h
20+
* @date {now.strftime("%d.%m.%Y")}
21+
* @author Markus Sattler
22+
*
23+
* Copyright (c) 2015 Markus Sattler. All rights reserved.
24+
* This file is part of the WebSockets for Arduino.
25+
*
26+
* This library is free software; you can redistribute it and/or
27+
* modify it under the terms of the GNU Lesser General Public
28+
* License as published by the Free Software Foundation; either
29+
* version 2.1 of the License, or (at your option) any later version.
30+
*
31+
* This library is distributed in the hope that it will be useful,
32+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34+
* Lesser General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU Lesser General Public
37+
* License along with this library; if not, write to the Free Software
38+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39+
*
40+
*/
41+
42+
#ifndef WEBSOCKETSVERSION_H_
43+
#define WEBSOCKETSVERSION_H_
44+
45+
#define WEBSOCKETS_VERSION "{version}"
46+
47+
#define WEBSOCKETS_VERSION_MAJOR {hvs[0]}
48+
#define WEBSOCKETS_VERSION_MINOR {hvs[1]}
49+
#define WEBSOCKETS_VERSION_PATCH {hvs[2]}
50+
51+
#define WEBSOCKETS_VERSION_INT {intversion}
52+
53+
#endif /* WEBSOCKETSVERSION_H_ */
54+
'''
55+
with open(f'{base_dir}/src/WebSocketsVersion.h', 'w') as f:
56+
f.write(text)
57+
58+
1259
def get_library_properties_version():
1360
library_properties = {}
1461
with open(f'{base_dir}/library.properties', 'r') as f:
1562
library_properties = configparser.ConfigParser()
1663
library_properties.read_string('[root]\n' + f.read())
1764
return library_properties['root']['version']
1865

66+
1967
def get_library_json_version():
2068
library_json = {}
2169
with open(f'{base_dir}/library.json', 'r') as f:
2270
library_json = json.load(f)
2371
return library_json['version']
2472

73+
2574
def get_header_versions():
2675
data = {}
2776
define = re.compile('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\.]*)"?$')
@@ -31,8 +80,8 @@ def get_header_versions():
3180
if m:
3281
name = m[1]
3382
if name == "":
34-
name = "VERSION"
35-
data[name] = m[2]
83+
name = "VERSION"
84+
data[name] = m[2]
3685
return data
3786

3887

@@ -46,7 +95,7 @@ def get_header_versions():
4695

4796
if args.update:
4897
library_properties_version = get_library_properties_version()
49-
98+
5099
with open(f'{base_dir}/library.json', 'r') as f:
51100
library_json = json.load(f)
52101

@@ -55,6 +104,8 @@ def get_header_versions():
55104
with open(f'{base_dir}/library.json', 'w') as f:
56105
json.dump(library_json, f, indent=4, sort_keys=True)
57106

107+
write_header_file(library_properties_version)
108+
58109

59110
library_json_version = get_library_json_version()
60111
library_properties_version = get_library_properties_version()
@@ -76,6 +127,6 @@ def get_header_versions():
76127
if header_version['PATCH'] != hvs[2]:
77128
raise Exception('header PATCH version wrong!')
78129

79-
intversion = int(hvs[0]) * 1000000 + int(hvs[1]) * 1000 + int(hvs[2])
130+
intversion = int(hvs[0]) * 1000000 + int(hvs[1]) * 1000 + int(hvs[2])
80131
if int(header_version['INT']) != intversion:
81-
raise Exception('header INT version wrong!')
132+
raise Exception('header INT version wrong!')

0 commit comments

Comments
 (0)