-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcreate_git_rev.cpp
More file actions
58 lines (49 loc) · 1.72 KB
/
create_git_rev.cpp
File metadata and controls
58 lines (49 loc) · 1.72 KB
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
// Copyright (C) 2019 Egor Pugin <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <boost/algorithm/string.hpp>
#include <primitives/command.h>
#include <primitives/sw/main.h>
#include <primitives/sw/cl.h>
#include <primitives/sw/settings_program_name.h>
static cl::opt<path> git(cl::Positional, cl::Required);
static cl::opt<path> wdir(cl::Positional, cl::Required);
static cl::opt<path> outfn(cl::Positional, cl::Required);
int main(int argc, char **argv)
{
cl::ParseCommandLineOptions(argc, argv);
String rev, status, time;
{
primitives::Command c;
c.working_directory = wdir;
c.arguments.push_back(git.u8string());
c.arguments.push_back("rev-parse");
c.arguments.push_back("HEAD");
c.execute();
rev = boost::trim_copy(c.out.text);
}
{
primitives::Command c;
c.working_directory = wdir;
c.arguments.push_back(git.u8string());
c.arguments.push_back("status");
c.arguments.push_back("--porcelain");
c.execute();
status = boost::trim_copy(c.out.text);
if (status.empty())
status = "0";
else
status = std::to_string(split_lines(status).size());
}
{
time = std::to_string(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
}
String t;
t += "#define SW_GIT_REV \"" + rev + "\"\n";
t += "#define SW_GIT_CHANGED_FILES " + status + "\n";
t += "#define SW_BUILD_TIME_T " + time + "LL\n";
write_file(outfn, t);
return 0;
}