Replace subversion info, with a command line parameter.

This commit is contained in:
Daniel James 2016-07-02 22:28:42 +01:00
parent 4e699ba697
commit f1f894fa1a
2 changed files with 30 additions and 89 deletions

View File

@ -56,6 +56,7 @@ Usage: inspect \[search-root\] \[options...\]
-brief
-text
-version-string <version message>
Checks:
@ -87,6 +88,9 @@ There are two types of options allowed, ones that control general operation and
[ [[^-brief]]
[The default report style can be rather verobse. This generates a more condesed report, for example suitable to send as an email.] ]
[ [[^-version-string]]
[Description of the version of boost that is being inspected.] ]
[ [[^-license]]
[Checks for presense of approved license text.] ]

View File

@ -130,91 +130,6 @@ namespace
typedef std::vector< lib_error_count > lib_error_count_vector;
lib_error_count_vector libs;
// run subversion to get revisions info ------------------------------------//
//
// implemented as function object that can be passed to boost::execution_monitor
// in order to swallow any errors from 'svn info'.
struct svn_check
{
explicit svn_check(const fs::path & inspect_root) :
inspect_root(inspect_root), fp(0) {}
int operator()() {
string rev("unknown");
string repos("unknown");
string command("cd ");
command += inspect_root.string() + " && svn info";
fp = (POPEN(command.c_str(), "r"));
if (fp)
{
static const int line_max = 128;
char line[line_max];
while (fgets(line, line_max, fp) != NULL)
{
string ln(line);
string::size_type pos;
if ((pos = ln.find("Revision: ")) != string::npos)
rev = ln.substr(pos + 10);
else if ((pos = ln.find("URL: ")) != string::npos)
repos = ln.substr(pos + 5);
}
}
result = repos + " at revision " + rev;
return 0;
}
~svn_check() { if (fp) PCLOSE(fp); }
const fs::path & inspect_root;
std::string result;
FILE* fp;
private:
svn_check(svn_check const&);
svn_check const& operator=(svn_check const&);
};
// Small helper class because svn_check can't be passed by copy.
template <typename F, typename R>
struct nullary_function_ref
{
explicit nullary_function_ref(F& f) : f(f) {}
R operator()() const { return f(); }
F& f;
};
// get info (as a string) if inspect_root is svn working copy --------------//
string info( const fs::path & inspect_root )
{
svn_check check(inspect_root);
#if !INSPECT_USE_BOOST_TEST
check();
#else
try {
boost::execution_monitor e;
e.execute(nullary_function_ref<svn_check, int>(check));
}
catch(boost::execution_exception const& e) {
if (e.code() == boost::execution_exception::system_error) {
// There was an error running 'svn info' - it probably
// wasn't run in a subversion repo.
return string("unknown");
}
else {
throw;
}
}
#endif
return check.result;
}
// visit_predicate (determines which directories are visited) --------------//
typedef bool(*pred_type)(const path&);
@ -634,6 +549,7 @@ namespace
" Output Options:\n\n"
" -brief\n"
" -text\n"
" -version-string <version message>\n"
"\n"
" Checks:\n\n"
" -license\n"
@ -649,6 +565,7 @@ namespace
" -deprecated_macro\n"
" -minmax\n"
" -unnamed\n"
" -version-string <version message>\n"
" default is all checks on; otherwise options specify desired checks"
"\n";
}
@ -833,6 +750,7 @@ int cpp_main( int argc_param, char * argv_param[] )
bool deprecated_ck = false;
bool minmax_ck = false;
bool unnamed_ck = false;
const char* version_string = 0;
if ( argc > 1 && *argv[1] != '-' )
{
@ -903,6 +821,16 @@ int cpp_main( int argc_param, char * argv_param[] )
{
display_mode = display_brief;
}
else if ( std::strcmp( argv[1], "-version-string" ) == 0 ) {
if (argc == 2 || argv[2][0] == '-') {
std::cerr << "Missing value for -version-string.\n";
invalid_options = true;
}
else {
--argc, ++argv;
version_string = argv[1];
}
}
else
{
std::cerr << "unknown option: " << argv[1] << '\n';
@ -989,6 +917,13 @@ int cpp_main( int argc_param, char * argv_param[] )
"\n"
;
if (version_string) {
std::cout
<< "The files checked were from "
<< version_string
<< ".\n\n";
}
std::cout
<< "Totals:\n"
<< " " << file_count << " files scanned\n"
@ -1026,10 +961,12 @@ int cpp_main( int argc_param, char * argv_param[] )
"<p>This report is generated by an <a href=\"http://www.boost.org/tools/inspect/index.html\">inspection\n"
"program</a> that checks files for the problems noted below.</p>\n"
;
std::cout
<< "<p>The files checked were from "
<< info( search_root_path() )
<< ".</p>\n";
if (version_string) {
std::cout
<< "<p>The files checked were from "
<< html_encode(version_string)
<< ".</p>\n";
}
std::cout