Skip to content

Commit 0aeb975

Browse files
committed
version.hh: make the utilities aware of their version
1 parent 7db25a6 commit 0aeb975

File tree

11 files changed

+97
-11
lines changed

11 files changed

+97
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/csdiff_build
22
/tags
3+
/version.cc

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ add_library(cs STATIC
6969
instream.cc
7070
json-parser.cc
7171
json-writer.cc
72+
version.cc
7273
${flex_scanner}
7374
)
7475

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ CMAKE_BUILD_TYPE ?= RelWithDebInfo
2727

2828
.PHONY: all check clean cppcheck distclean distcheck fast install
2929

30-
all:
30+
all: version.cc
3131
mkdir -p csdiff_build
3232
cd csdiff_build && $(CMAKE) -D 'CMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)' ..
3333
$(MAKE) -C csdiff_build
3434

35-
fast:
35+
fast: version.cc
3636
$(MAKE) -sC csdiff_build
3737

3838
check: all
@@ -43,6 +43,7 @@ cppcheck: all
4343

4444
clean:
4545
if test -e csdiff_build/Makefile; then $(MAKE) clean -C csdiff_build; fi
46+
if test -e .git; then rm -f version.cc; fi
4647

4748
distclean:
4849
rm -rf csdiff_build
@@ -52,3 +53,12 @@ distcheck: distclean
5253

5354
install: all
5455
$(MAKE) -C csdiff_build install
56+
57+
version.cc:
58+
@if test -e .git; then \
59+
printf "#include \"version.hh\"\nconst char *CS_VERSION = \"%s\";\n" \
60+
"0.`git log --pretty="%cd_%h" --date=short -1 | tr -d -`" \
61+
> $@.tmp \
62+
&& install -m0644 -C -v $@.tmp $@ \
63+
&& rm -f $@.tmp; \
64+
fi

csdiff.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "csdiff-core.hh"
2121
#include "csfilter.hh"
2222
#include "instream.hh"
23+
#include "version.hh"
2324

2425
#include <cstdlib>
2526

@@ -49,7 +50,8 @@ int main(int argc, char *argv[])
4950
("quiet,q", "do not report any parsing errors")
5051
("file-rename,s", po::value<TStringList>(),
5152
"account the file base-name change, [OLD,NEW] (*testing*)")
52-
("help", "produce help message");
53+
("help", "produce help message")
54+
("version", "print version");
5355

5456
po::options_description hidden("");
5557
hidden.add_options()
@@ -77,6 +79,11 @@ int main(int argc, char *argv[])
7779
return 0;
7880
}
7981

82+
if (vm.count("version")) {
83+
std::cout << CS_VERSION << "\n";
84+
return 0;
85+
}
86+
8087
const bool forceCov = !!vm.count("coverity-output");
8188
const bool forceJson = !!vm.count("json-output");
8289
if (forceCov && forceJson) {

cshtml.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "deflookup.hh"
2222
#include "html-writer.hh"
2323
#include "instream.hh"
24+
#include "version.hh"
2425

2526
#include <boost/program_options.hpp>
2627
#include <boost/regex.hpp>
@@ -63,7 +64,8 @@ int main(int argc, char *argv[])
6364
po::value<string>(&spPosition)->default_value("top"),
6465
"placement of the table with scan properties: top, bottom, none")
6566
("quiet,q", "do not report any parsing errors")
66-
("help", "produce help message");
67+
("help", "produce help message")
68+
("version", "print version");
6769

6870
po::options_description hidden("");
6971
hidden.add_options()
@@ -91,6 +93,11 @@ int main(int argc, char *argv[])
9193
return 0;
9294
}
9395

96+
if (vm.count("version")) {
97+
std::cout << CS_VERSION << "\n";
98+
return 0;
99+
}
100+
94101
if (!vm.count("input-file")) {
95102
desc.print(std::cerr);
96103
return 1;

cslinker.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "defqueue.hh"
2222
#include "instream.hh"
2323
#include "json-writer.hh"
24+
#include "version.hh"
2425

2526
#include <boost/program_options.hpp>
2627
#include <boost/property_tree/ini_parser.hpp>
@@ -139,7 +140,8 @@ int main(int argc, char *argv[])
139140
try {
140141
desc.add_options()
141142
("quiet,q", "do not report any parsing errors")
142-
("help", "produce help message");
143+
("help", "produce help message")
144+
("version", "print version");
143145

144146
po::options_description hidden("");
145147
hidden.add_options()
@@ -167,6 +169,11 @@ int main(int argc, char *argv[])
167169
return 0;
168170
}
169171

172+
if (vm.count("version")) {
173+
std::cout << CS_VERSION << "\n";
174+
return 0;
175+
}
176+
170177
if (!vm.count("input-file")) {
171178
desc.print(std::cerr);
172179
return 1;

cssort.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "abstract-writer.hh"
21+
#include "version.hh"
2122

2223
#include <boost/foreach.hpp>
2324
#include <boost/program_options.hpp>
@@ -188,7 +189,8 @@ int main(int argc, char *argv[])
188189
("key", po::value<string>(&key)->default_value("path"),
189190
"checker, path")
190191
("help", "produce help message")
191-
("quiet,q", "do not report any parsing errors");
192+
("quiet,q", "do not report any parsing errors")
193+
("version", "print version");
192194

193195
po::options_description hidden("");
194196
hidden.add_options()
@@ -216,6 +218,11 @@ int main(int argc, char *argv[])
216218
return 0;
217219
}
218220

221+
if (vm.count("version")) {
222+
std::cout << CS_VERSION << "\n";
223+
return 0;
224+
}
225+
219226
SortFactory factory;
220227
AbstractWriter *eng = factory.create(key);
221228
if (!eng) {

cstat-core.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "abstract-filter.hh"
2424
#include "cswriter.hh"
2525
#include "json-writer.hh"
26+
#include "version.hh"
2627

2728
#include <cstdlib>
2829
#include <fstream>
@@ -434,7 +435,8 @@ int cStatCore(int argc, char *argv[], const char *defMode)
434435
"match source path by the given regex")
435436
("quiet,q", "do not report any parsing errors")
436437
("src-annot", po::value<string>(),
437-
"match annotations in the _source_ file by the given regex");
438+
"match annotations in the _source_ file by the given regex")
439+
("version", "print version");
438440

439441
po::options_description hidden("");
440442
hidden.add_options()
@@ -462,6 +464,11 @@ int cStatCore(int argc, char *argv[], const char *defMode)
462464
return 0;
463465
}
464466

467+
if (vm.count("version")) {
468+
std::cout << CS_VERSION << "\n";
469+
return 0;
470+
}
471+
465472
WriterFactory factory;
466473
AbstractWriter *eng = factory.create(mode);
467474
if (!eng) {

make-srpm.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ cd "$PKG" || die "git clone failed"
4141

4242
make -j5 distcheck CTEST='ctest -j5' || die "'make distcheck' has failed"
4343

44-
NV="${PKG}-$VER"
45-
SRC="${PKG}.tar.xz"
46-
git archive --prefix="$NV/" --format="tar" HEAD -- . | xz -c > "$SRC"
44+
NV="${PKG}-${VER}"
45+
mkdir "${NV}"
46+
mv version.cc "${NV}/" || die "failed to copy version.cc"
47+
48+
SRC_TAR="${PKG}.tar"
49+
SRC="${SRC_TAR}.xz"
50+
git archive --prefix="$NV/" --format="tar" HEAD -- . > "$SRC_TAR"
51+
tar -rf "$SRC_TAR" "${NV}/version.cc"
52+
53+
xz -c "$SRC_TAR" > "$SRC" || die "failed to compress sources"
4754

4855
SPEC="./$PKG.spec"
4956
cat > "$SPEC" << EOF

pycsdiff.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "csdiff-core.hh"
21+
#include "version.hh"
2122

2223
#include <sstream>
2324

@@ -34,7 +35,13 @@ std::string diff_scans(
3435
return strDst.str();
3536
}
3637

38+
std::string get_version(void)
39+
{
40+
return CS_VERSION;
41+
}
42+
3743
BOOST_PYTHON_MODULE(pycsdiff)
3844
{
39-
boost::python::def("diff_scans", diff_scans);
45+
boost::python::def("diff_scans", diff_scans);
46+
boost::python::def("get_version", get_version);
4047
}

0 commit comments

Comments
 (0)