Skip to content

Commit

Permalink
Enhanced the inspect tool to take user directly to the problem with h…
Browse files Browse the repository at this point in the history
…yperlinks. Includes a new header file and changes to the base inspect file. Questions and advice are welcome.
  • Loading branch information
Bcorde5 committed Oct 19, 2015
1 parent a3a9d96 commit b0f895b
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 33 deletions.
3 changes: 3 additions & 0 deletions tools/inspect/apple_macro_check.cpp
Expand Up @@ -8,7 +8,9 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include "apple_macro_check.hpp"
#include "function_hyper.hpp"
#include <functional>
#include <string>
#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/filesystem/operations.hpp"
Expand Down Expand Up @@ -89,6 +91,7 @@ namespace boost
}
}

std::string lineloc = linelink(full_path, std::to_string(line_number));
++errors;
error( library_name, full_path,
"Apple macro clash: " + std::string((*cur)[0].first, (*cur)[0].second-1),
Expand Down
4 changes: 3 additions & 1 deletion tools/inspect/ascii_check.cpp
Expand Up @@ -9,6 +9,7 @@
// √ -- this is a test.

#include "ascii_check.hpp"
#include "function_hyper.hpp"
#include <functional>

namespace boost
Expand Down Expand Up @@ -93,7 +94,8 @@ namespace boost
++m_files_with_errors;
std::size_t ln = std::count( contents.begin(), bad_char, '\n' ) + 1;
string the_line = find_line ( contents, bad_char );
error( library_name, full_path, "Non-ASCII: " + the_line, ln );
string location = linelink(full_path, the_line);
error( library_name, full_path, "Non-ASCII: ", ln );
}
}
} // namespace inspect
Expand Down
5 changes: 3 additions & 2 deletions tools/inspect/assert_macro_check.cpp
Expand Up @@ -9,6 +9,7 @@

#include "assert_macro_check.hpp"
#include <functional>
#include "function_hyper.hpp"
#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/filesystem/operations.hpp"
Expand Down Expand Up @@ -95,10 +96,10 @@ namespace boost
line_start = it + 1; // could be end()
}
}

std::string lineloc = linelink (full_path, boost::lexical_cast<string>(line_number));
++errors;
error( library_name, full_path, "C-style assert macro on line "
+ boost::lexical_cast<string>( line_number ) );
+ lineloc );
}
}
if(errors > 0)
Expand Down
4 changes: 3 additions & 1 deletion tools/inspect/copyright_check.cpp
Expand Up @@ -6,6 +6,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include "copyright_check.hpp"
#include "function_hyper.hpp"

namespace boost
{
Expand All @@ -26,7 +27,8 @@ namespace boost
&& contents.find( "copyright" ) == string::npos )
{
++m_files_with_errors;
error( library_name, full_path, name() );
std::string lineloc = loclink(full_path, name());
error( library_name, full_path, lineloc );
}
}
} // namespace inspect
Expand Down
3 changes: 2 additions & 1 deletion tools/inspect/crlf_check.cpp
Expand Up @@ -9,6 +9,7 @@
// Contributed by Joerg Walter

#include "crlf_check.hpp"
#include "function_hyper.hpp"

namespace boost
{
Expand Down Expand Up @@ -58,7 +59,7 @@ namespace boost
if (!failed && full_path.leaf() == test_file_name)
{
++m_files_with_errors;
error( library_name, full_path, string(name()) + " should have cr-only line endings" );
error( library_name, full_path, loclink(full_path, string(name()) + " should have cr-only line endings" ));
}

/*
Expand Down
7 changes: 4 additions & 3 deletions tools/inspect/deprecated_macro_check.cpp
Expand Up @@ -10,6 +10,7 @@

#include "deprecated_macro_check.hpp"
#include <functional>
#include "function_hyper.hpp"
#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/filesystem/operations.hpp"
Expand Down Expand Up @@ -117,23 +118,23 @@ namespace boost
{
if ( contents.find( *ptr ) != string::npos ) {
++errors;
error( library_name, full_path, string ( "Boost macro deprecated in 1.50: " ) + *ptr );
error( library_name, full_path, loclink(full_path, string ( "Boost macro deprecated in 1.50: " ) + *ptr ));
}
}

for ( ptr = boost151macros; *ptr != NULL; ++ptr )
{
if ( contents.find( *ptr ) != string::npos ) {
++errors;
error( library_name, full_path, string ( "Boost macro deprecated in 1.51: " ) + *ptr );
error( library_name, full_path, loclink(full_path, string("Boost macro deprecated in 1.51: ") + *ptr));
}
}

for ( ptr = boost153macros; *ptr != NULL; ++ptr )
{
if ( contents.find( *ptr ) != string::npos ) {
++errors;
error( library_name, full_path, string ( "Boost macro deprecated in 1.53: " ) + *ptr );
error( library_name, full_path, loclink(full_path, string("Boost macro deprecated in 1.53: ") + *ptr));
}
}

Expand Down
13 changes: 11 additions & 2 deletions tools/inspect/end_check.cpp
Expand Up @@ -8,6 +8,9 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include "end_check.hpp"
#include "function_hyper.hpp"
#include <string>
#include <boost/tokenizer.hpp>
#include <boost/next_prior.hpp>

namespace boost
Expand All @@ -31,7 +34,13 @@ namespace boost
const string & contents ) // contents of file to be inspected
{
if (contents.find( "hpxinspect:" "noend" ) != string::npos) return;

int linenumb = 0;
char_separator<char> sep("\n", "", boost::keep_empty_tokens);
tokenizer<char_separator<char>> tokens(contents, sep);
for (const auto& t : tokens) {
linenumb++;
}
std::string lineloc = std::to_string(linenumb);
// this file deliberately contains errors
const char test_file_name[] = "wrong_line_ends_test.cpp";

Expand All @@ -49,7 +58,7 @@ namespace boost
if (!failed && full_path.leaf() == test_file_name)
{
++m_files_with_errors;
error( library_name, full_path, string(name()) + " should not end with a newline" );
error( library_name, full_path, string(name()) + wordlink(full_path, lineloc, " should end with a newline") );
}
}
} // namespace inspect
Expand Down
6 changes: 4 additions & 2 deletions tools/inspect/endline_whitespace_check.cpp
Expand Up @@ -7,6 +7,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include "endline_whitespace_check.hpp"
#include "function_hyper.hpp"
#include <iostream>
#include <functional>
#include <string>
Expand All @@ -16,6 +17,7 @@
#include "boost/lexical_cast.hpp"
#include "boost/filesystem/operations.hpp"


using namespace std;
namespace fs = boost::filesystem;

Expand Down Expand Up @@ -95,7 +97,7 @@ namespace boost
p = 0;
while (p < lineorder.size())
{
total += lineorder[p];
total += linelink(full_path, lineorder[p]); //linelink is located in function_hyper.hpp
if (p < lineorder.size() - 1)
{
total += ", ";
Expand All @@ -104,7 +106,7 @@ namespace boost
}
if (errors > 0)
{
string errored = "Endline Whitespace*: " + total;
string errored = "*Endline Whitespace*: " + total;
error(library_name, full_path, errored);
++m_files_with_errors;
}
Expand Down
46 changes: 46 additions & 0 deletions tools/inspect/function_hyper.hpp
@@ -0,0 +1,46 @@
// Hyperlink Function ------------------------------------------//

// Copyright (c) 2015 Brandon Cordes
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef FUNCTION_HYPER_HPP
#define FUNCTION_HYPER_HPP

#include "boost/filesystem/path.hpp"
#include <hpx/config/defines.hpp>
#include <string>

using boost::filesystem::path;
//When you have a specific line and the line is the location of the link
inline std::string linelink(const path & full_path, std::string linenumb)
{
std::string commit = HPX_HAVE_GIT_COMMIT;
std::string total, location = full_path.string();
total += "†a href = \"https://github.com/STEllAR-GROUP/hpx/blob/" + commit + "/" + location + "#L" + linenumb + "\"";
total = total + linenumb;
total = total + "†/a‡";
return total;
}
//When you have a specific line, but a word is the location of the link
inline std::string wordlink(const path & full_path, std::string linenumb, std::string word)
{
std::string commit = HPX_HAVE_GIT_COMMIT;
std::string total, location = full_path.string();
total += "†a href = \"https://github.com/STEllAR-GROUP/hpx/blob/" + commit + "/" + location + "#L" + linenumb + "\"";
total = total + word;
total = total + "†/a‡";
return total;
}
//When you don't have a specific line
inline std::string loclink(const path & full_path, std::string word)
{
std::string commit = HPX_HAVE_GIT_COMMIT;
std::string total, location = full_path.string();
total += "†a href = \"https://github.com/STEllAR-GROUP/hpx/blob/" + commit + "/" + location + "\"";
total = total + word;
total = total + "†/a‡";
return total;
}
#endif
18 changes: 16 additions & 2 deletions tools/inspect/inspect.cpp
Expand Up @@ -28,12 +28,14 @@ const char* hpx_no_inspect = "hpx-" "no-inspect";
#include <iostream>
#include <fstream>
#include <limits>
#include <string>

#include "boost/shared_ptr.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/fstream.hpp"
#include "boost/program_options.hpp"
#include "function_hyper.hpp"

#include <stdio.h> // for popen, pclose
#if defined(_MSC_VER)
Expand Down Expand Up @@ -444,6 +446,13 @@ namespace
case '&':
result += "&amp;";
break;
//† and ‡ are used to force html formatting when needed, as these obscure ascii characters are practically unused
case '†':
result += "<";
break;
case '‡':
result += ">";
break;
default:
result += *it;
}
Expand Down Expand Up @@ -520,7 +529,7 @@ namespace
{
if ( !first ) out << "</pre>\n";
out << "\n<h3><a name=\"" << itr->library
<< "\">" << itr->library << "</a></h3>\n<pre>";
<< "\">" << itr->library << "</a></h3>\n<pre>";
}
if ( current.library != itr->library
|| current.rel_path != itr->rel_path )
Expand All @@ -543,7 +552,12 @@ namespace

// print the message
if (itr->line_number)
out << sep << "(line " << itr->line_number << ") " << html_encode(itr->msg);
{
string line = std::to_string(itr->line_number);
const path & full_path = itr->library;
string link = linelink(full_path, line);
out << sep << "(line " << link << ") " << html_encode(itr->msg);
}
else out << sep << html_encode(itr->msg);

first_sep = false;
Expand Down
3 changes: 2 additions & 1 deletion tools/inspect/length_check.cpp
Expand Up @@ -7,6 +7,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include "length_check.hpp"
#include "function_hyper.hpp"
#include <iostream>
#include <functional>
#include <string>
Expand Down Expand Up @@ -111,7 +112,7 @@ namespace boost
p = 0;
while (p < lineorder.size())
{
total += lineorder[p];
total += linelink(full_path, lineorder[p]); //linelink is located in function_hyper.hpp
if (p < lineorder.size() - 1)
{
total += ", ";
Expand Down
3 changes: 2 additions & 1 deletion tools/inspect/license_check.cpp
Expand Up @@ -7,6 +7,7 @@

#include "boost/regex.hpp"
#include "license_check.hpp"
#include "function_hyper.hpp"

namespace
{
Expand Down Expand Up @@ -39,7 +40,7 @@ namespace boost
if ( !boost::regex_search( contents, license_regex ) )
{
++m_files_with_errors;
error( library_name, full_path, name() );
error( library_name, full_path, loclink(full_path, name()) );
}
}
} // namespace inspect
Expand Down
3 changes: 2 additions & 1 deletion tools/inspect/minmax_check.cpp
Expand Up @@ -13,6 +13,7 @@
#include "minmax_check.hpp"
#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "function_hyper.hpp"

namespace
{
Expand Down Expand Up @@ -91,7 +92,7 @@ namespace boost
++m_errors;
error( library_name, full_path, string(name())
+ " violation of Boost min/max guidelines on line "
+ boost::lexical_cast<string>( line_number ) );
+ linelink(full_path, boost::lexical_cast<string>(line_number)));
}

}
Expand Down
9 changes: 5 additions & 4 deletions tools/inspect/path_name_check.cpp
Expand Up @@ -11,6 +11,7 @@

#include "boost/filesystem/operations.hpp"
#include "boost/lexical_cast.hpp"
#include "function_hyper.hpp"

#include <string>
#include <algorithm>
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace boost
if ( (pos = leaf.find_first_not_of( allowable )) != string::npos )
{
++m_name_errors;
error( library_name, full_path, string(name())
error( library_name, full_path, loclink(full_path, string(name()))
+ " file or directory name contains unacceptable character '"
+ leaf[pos] + "'" );
}
Expand All @@ -55,7 +56,7 @@ namespace boost
if ( std::strchr( initial_char, leaf[0] ) == 0 )
{
++m_name_errors;
error( library_name, full_path, string(name())
error( library_name, full_path, loclink(full_path, string(name()))
+ " file or directory name begins with an unacceptable character" );
}

Expand All @@ -65,7 +66,7 @@ namespace boost
if ( std::strchr( leaf.c_str(), '.' ) )
{
++m_name_errors;
error( library_name, full_path, string(name())
error( library_name, full_path, loclink(full_path, string(name()))
+ " directory name contains a dot character ('.')" );
}
}
Expand All @@ -90,7 +91,7 @@ namespace boost
{
++m_name_errors;
error( library_name, full_path,
string(name())
loclink(full_path, string(name()))
+ " path will exceed "
+ boost::lexical_cast<string>(max_relative_path)
+ " characters in a directory tree with a root in the form "
Expand Down

0 comments on commit b0f895b

Please sign in to comment.