-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathbuild-version.cpp
88 lines (77 loc) · 2.79 KB
/
build-version.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
////////////////////////////////////////////////////////////////////////////////
/// @brief Library to build up VPack documents.
///
/// DISCLAIMER
///
/// Copyright 2015 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Max Neunhoeffer
/// @author Jan Steemann
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
#include <regex>
// a simple tool to generate a version number
// reads in an existing version file and increments the patch
// level in it. creates a new file if it does not yet exist
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " FILE" << std::endl;
return EXIT_FAILURE;
}
unsigned long major = 0;
unsigned long minor = 0;
unsigned long patch = 0;
std::regex version(
"\\s*#define VELOCYPACK_VERSION\\s*\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"",
std::regex::ECMAScript);
std::string infile = argv[1];
std::string s;
std::ifstream ifs(infile, std::ifstream::in);
char buffer[4096];
if (ifs.is_open()) {
ifs.read(&buffer[0], sizeof(buffer));
s.append(buffer, ifs.gcount());
ifs.close();
}
std::smatch match;
if (std::regex_search(s, match, version)) {
major = std::stoul(match[1].str());
minor = std::stoul(match[2].str());
patch = std::stoul(match[3].str());
}
++patch;
std::string result;
result.append("// this is an auto-generated file. do not edit!\n\n");
result.append("#pragma once\n");
result.append("#define VELOCYPACK_VERSION \"" + std::to_string(major) + "." +
std::to_string(minor) + "." + std::to_string(patch) + "\"\n\n");
result.append("#define VELOCYPACK_VERSION_MAJOR " + std::to_string(major) +
"\n");
result.append("#define VELOCYPACK_VERSION_MINOR " + std::to_string(minor) +
"\n");
result.append("#define VELOCYPACK_VERSION_PATCH " + std::to_string(patch) +
"\n");
std::string outfile = argv[1];
std::ofstream ofs(outfile, std::ifstream::out);
ofs.seekp(0);
ofs.write(result.c_str(), result.size());
ofs.close();
return EXIT_SUCCESS;
}