Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced the inspect tool to take user directly to the problem with hyperlinks. #1801

Merged
merged 4 commits into from Oct 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
50 changes: 50 additions & 0 deletions tools/inspect/function_hyper.hpp
@@ -0,0 +1,50 @@
// 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 @@ -131,7 +132,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
18 changes: 12 additions & 6 deletions tools/inspect/link_check.cpp
Expand Up @@ -185,8 +185,10 @@ namespace boost
if (!result.second)
{
++m_duplicate_bookmark_errors;
std::size_t ln = std::count( contents.begin(), a_what[3].first, '\n' ) + 1;
error( library_name, full_path, "Duplicate bookmark: " + bookmark, ln );
std::size_t ln = std::count( contents.begin(),
a_what[3].first, '\n' ) + 1;
error( library_name, full_path, "Duplicate bookmark: "
+ bookmark, ln );
}
}
}
Expand Down Expand Up @@ -250,7 +252,8 @@ namespace boost

void link_check::do_url( const string & url, const string & library_name,
const path & source_path, bool no_link_errors, bool allow_external_content,
std::string::const_iterator contents_begin, std::string::const_iterator url_start )
std::string::const_iterator contents_begin,
std::string::const_iterator url_start )
// precondition: source_path.is_complete()
{
if(!no_link_errors && url.empty()) {
Expand Down Expand Up @@ -326,7 +329,8 @@ namespace boost
"Invalid URL (hardwired file): " + decoded_url, ln );
}
}
else if(scheme == "mailto" || scheme == "ftp" || scheme == "news" || scheme == "javascript") {
else if(scheme == "mailto" || scheme == "ftp"
|| scheme == "news" || scheme == "javascript") {
if ( !no_link_errors && is_css(source_path) ) {
++m_invalid_errors;
std::size_t ln = std::count( contents_begin, url_start, '\n' ) + 1;
Expand All @@ -338,7 +342,8 @@ namespace boost
if(!no_link_errors) {
++m_invalid_errors;
std::size_t ln = std::count( contents_begin, url_start, '\n' ) + 1;
error( library_name, source_path, "Unknown protocol: '" + scheme + "' in url: " + decoded_url, ln );
error( library_name, source_path,
"Unknown protocol: '" + scheme + "' in url: " + decoded_url, ln );
}
}

Expand Down Expand Up @@ -388,7 +393,8 @@ namespace boost
}

// Detect characters banned by RFC2396:
if ( !no_link_errors && decoded_url.find_first_of( " <>\"{}|\\^[]'" ) != string::npos )
if ( !no_link_errors
&& decoded_url.find_first_of( " <>\"{}|\\^[]'" ) != string::npos )
{
++m_invalid_errors;
std::size_t ln = std::count( contents_begin, url_start, '\n' ) + 1;
Expand Down