Skip to content

Commit

Permalink
version.hh: make the utilities aware of their version
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudka committed Jan 22, 2013
1 parent 7db25a6 commit 0aeb975
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/csdiff_build
/tags
/version.cc
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_library(cs STATIC
instream.cc
json-parser.cc
json-writer.cc
version.cc
${flex_scanner}
)

Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ CMAKE_BUILD_TYPE ?= RelWithDebInfo

.PHONY: all check clean cppcheck distclean distcheck fast install

all:
all: version.cc
mkdir -p csdiff_build
cd csdiff_build && $(CMAKE) -D 'CMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)' ..
$(MAKE) -C csdiff_build

fast:
fast: version.cc
$(MAKE) -sC csdiff_build

check: all
Expand All @@ -43,6 +43,7 @@ cppcheck: all

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

distclean:
rm -rf csdiff_build
Expand All @@ -52,3 +53,12 @@ distcheck: distclean

install: all
$(MAKE) -C csdiff_build install

version.cc:
@if test -e .git; then \
printf "#include \"version.hh\"\nconst char *CS_VERSION = \"%s\";\n" \
"0.`git log --pretty="%cd_%h" --date=short -1 | tr -d -`" \
> $@.tmp \
&& install -m0644 -C -v $@.tmp $@ \
&& rm -f $@.tmp; \
fi
9 changes: 8 additions & 1 deletion csdiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "csdiff-core.hh"
#include "csfilter.hh"
#include "instream.hh"
#include "version.hh"

#include <cstdlib>

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

po::options_description hidden("");
hidden.add_options()
Expand Down Expand Up @@ -77,6 +79,11 @@ int main(int argc, char *argv[])
return 0;
}

if (vm.count("version")) {
std::cout << CS_VERSION << "\n";
return 0;
}

const bool forceCov = !!vm.count("coverity-output");
const bool forceJson = !!vm.count("json-output");
if (forceCov && forceJson) {
Expand Down
9 changes: 8 additions & 1 deletion cshtml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "deflookup.hh"
#include "html-writer.hh"
#include "instream.hh"
#include "version.hh"

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

po::options_description hidden("");
hidden.add_options()
Expand Down Expand Up @@ -91,6 +93,11 @@ int main(int argc, char *argv[])
return 0;
}

if (vm.count("version")) {
std::cout << CS_VERSION << "\n";
return 0;
}

if (!vm.count("input-file")) {
desc.print(std::cerr);
return 1;
Expand Down
9 changes: 8 additions & 1 deletion cslinker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "defqueue.hh"
#include "instream.hh"
#include "json-writer.hh"
#include "version.hh"

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

po::options_description hidden("");
hidden.add_options()
Expand Down Expand Up @@ -167,6 +169,11 @@ int main(int argc, char *argv[])
return 0;
}

if (vm.count("version")) {
std::cout << CS_VERSION << "\n";
return 0;
}

if (!vm.count("input-file")) {
desc.print(std::cerr);
return 1;
Expand Down
9 changes: 8 additions & 1 deletion cssort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "abstract-writer.hh"
#include "version.hh"

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

po::options_description hidden("");
hidden.add_options()
Expand Down Expand Up @@ -216,6 +218,11 @@ int main(int argc, char *argv[])
return 0;
}

if (vm.count("version")) {
std::cout << CS_VERSION << "\n";
return 0;
}

SortFactory factory;
AbstractWriter *eng = factory.create(key);
if (!eng) {
Expand Down
9 changes: 8 additions & 1 deletion cstat-core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "abstract-filter.hh"
#include "cswriter.hh"
#include "json-writer.hh"
#include "version.hh"

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

po::options_description hidden("");
hidden.add_options()
Expand Down Expand Up @@ -462,6 +464,11 @@ int cStatCore(int argc, char *argv[], const char *defMode)
return 0;
}

if (vm.count("version")) {
std::cout << CS_VERSION << "\n";
return 0;
}

WriterFactory factory;
AbstractWriter *eng = factory.create(mode);
if (!eng) {
Expand Down
13 changes: 10 additions & 3 deletions make-srpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ cd "$PKG" || die "git clone failed"

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

NV="${PKG}-$VER"
SRC="${PKG}.tar.xz"
git archive --prefix="$NV/" --format="tar" HEAD -- . | xz -c > "$SRC"
NV="${PKG}-${VER}"
mkdir "${NV}"
mv version.cc "${NV}/" || die "failed to copy version.cc"

SRC_TAR="${PKG}.tar"
SRC="${SRC_TAR}.xz"
git archive --prefix="$NV/" --format="tar" HEAD -- . > "$SRC_TAR"
tar -rf "$SRC_TAR" "${NV}/version.cc"

xz -c "$SRC_TAR" > "$SRC" || die "failed to compress sources"

SPEC="./$PKG.spec"
cat > "$SPEC" << EOF
Expand Down
9 changes: 8 additions & 1 deletion pycsdiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "csdiff-core.hh"
#include "version.hh"

#include <sstream>

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

std::string get_version(void)
{
return CS_VERSION;
}

BOOST_PYTHON_MODULE(pycsdiff)
{
boost::python::def("diff_scans", diff_scans);
boost::python::def("diff_scans", diff_scans);
boost::python::def("get_version", get_version);
}
25 changes: 25 additions & 0 deletions version.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2013 Red Hat, Inc.
*
* This file is part of csdiff.
*
* csdiff is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* csdiff is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with csdiff. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef H_GUARD_VERSION_H
#define H_GUARD_VERSION_H

extern const char *CS_VERSION;

#endif /* H_GUARD_VERSION_H */

0 comments on commit 0aeb975

Please sign in to comment.