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

Check code style during Travis CI build #100

Merged
merged 2 commits into from
Sep 9, 2018
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
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ ENV LC_ALL C.UTF-8
ENV LC_CTYPE C.UTF-8

FROM base as builder
RUN apt-get update && apt-get install -y build-essential cmake libsparsehash-dev
RUN apt-get update && apt-get install -y build-essential clang-format cmake libsparsehash-dev
COPY . /app/

# Check formatting with the .clang-format project style
WORKDIR /app/
RUN misc/format-check.sh

WORKDIR /app/build/
RUN cmake -DCMAKE_BUILD_TYPE=Release .. && make -j $(nproc) && make test

Expand Down
31 changes: 31 additions & 0 deletions misc/format-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

printf "Checking sources for code style\n"
SOURCE_FILES=()
find . -not \( -path "./third_party/*" -prune \) -not \( -path "./build/*" -prune \) -name \*.h -print0 -o -name \*.cpp -print0 > sourcelist
while IFS= read -r -d $'\0'; do
SOURCE_FILES+=("$REPLY")
done <sourcelist

ERROR=0
for source in "${SOURCE_FILES[@]}" ;do
clang-format -output-replacements-xml $source | grep "<replacement " &> /dev/null
HAS_WRONG_FILES=$?
if [ $HAS_WRONG_FILES -ne 1 ] ; then
# Print an error and exit
printf "\x1b[31mError: "
printf "The source file \x1b[m$source\x1b[31m does not match the code style\n"
printf "Use clang-format with the .clang-format provided in the QLever\n"
printf "repository's root to ensure all code files are formatted "
printf "properly. We currently use the clang-format version in\n"
printf "Ubuntu 18.04.x which is version 6.0\n"
printf "\x1b[m"
ERROR=1
fi
done

if [ $ERROR -eq 0 ]; then
printf "\x1b[32mCongratulations! All sources match the code style\x1b[m\n"
else
exit 1
fi
1 change: 0 additions & 1 deletion src/PrefixHeuristicEvaluatorMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ int main(int argc, char** argv) {
std::cout << p << '\n';
}
}

2 changes: 1 addition & 1 deletion src/engine/IndexScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Chair of Algorithms and Data Structures.
// Author: Björn Buchhold (buchhold@informatik.uni-freiburg.de)

#include "./IndexScan.h"
#include <sstream>
#include <string>
#include "./IndexScan.h"

using std::string;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/QueryExecutionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Chair of Algorithms and Data Structures.
// Author: Björn Buchhold (buchhold@informatik.uni-freiburg.de)

#include "./QueryExecutionTree.h"
#include <algorithm>
#include <sstream>
#include <string>
Expand All @@ -10,7 +11,6 @@
#include "./IndexScan.h"
#include "./Join.h"
#include "./OrderBy.h"
#include "./QueryExecutionTree.h"
#include "./Sort.h"
#include "TextOperationForContexts.h"
#include "TextOperationWithFilter.h"
Expand Down
8 changes: 4 additions & 4 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ QueryExecutionTree QueryPlanner::createExecutionTree(ParsedQuery& pq) const {
static_cast<GroupBy*>(groupBy.get())->computeSortColumns(final._qet);

if (!sortColumns.empty() &&
!(sortColumns.size() == 1 && final._qet->resultSortedOn() ==
sortColumns[0].first)) {
!(sortColumns.size() == 1 &&
final._qet->resultSortedOn() == sortColumns[0].first)) {
// Create an order by operation as required by the group by
std::shared_ptr<Operation> orderBy =
std::make_shared<OrderBy>(_qec, final._qet, sortColumns);
Expand Down Expand Up @@ -340,7 +340,7 @@ QueryExecutionTree QueryPlanner::createExecutionTree(ParsedQuery& pq) const {
// but not necessarily optimal.
// TODO: Adjust so that the optimal place for the operation is found.
if (pq._distinct) {
QueryExecutionTree distinctTree(* final._qet.get());
QueryExecutionTree distinctTree(*final._qet.get());
vector<size_t> keepIndices;
ad_utility::HashSet<size_t> indDone;
for (const auto& var : pq._selectedVariables) {
Expand Down Expand Up @@ -405,7 +405,7 @@ QueryExecutionTree QueryPlanner::createExecutionTree(ParsedQuery& pq) const {

final._qet.get()->setTextLimit(getTextLimit(pq._textLimit));
LOG(DEBUG) << "Done creating execution plan.\n";
return * final._qet.get();
return *final._qet.get();
}

bool QueryPlanner::checkUsePatternTrick(
Expand Down
1 change: 0 additions & 1 deletion src/global/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ static constexpr uint8_t NUM_COMPRESSION_PREFIXES = 127;
// compression has been applied to a word
static const uint8_t NO_PREFIX_CHAR =
MIN_COMPRESSION_PREFIX + NUM_COMPRESSION_PREFIXES;

2 changes: 1 addition & 1 deletion src/index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "./Index.h"
#include <algorithm>
#include <cmath>
#include <optional>
#include <cstdio>
#include <optional>
#include <stxxl/algorithm>
#include <stxxl/map>
#include <unordered_set>
Expand Down
2 changes: 1 addition & 1 deletion src/index/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class Index {
void setKeepTempFiles(bool keepTempFiles);

void setOnDiskBase(const std::string& onDiskBase);

void setSettingsFile(const std::string& filename);

void setPrefixCompression(bool compressed);
Expand Down
2 changes: 1 addition & 1 deletion src/index/IndexMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WrongFormatException : public std::exception {
public:
WrongFormatException(std::string msg) : _msg(std::move(msg)) {}
const char* what() const throw() { return _msg.c_str(); }

private:
std::string _msg;
};
Expand Down Expand Up @@ -215,5 +216,4 @@ using IndexMetaDataMmap = IndexMetaData<
using IndexMetaDataMmapView = IndexMetaData<
MetaDataWrapperDense<ad_utility::MmapVectorView<FullRelationMetaData>>>;


#include "./IndexMetaDataImpl.h"
4 changes: 1 addition & 3 deletions src/index/PrefixHeuristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ std::pair<size_t, TreeNode*> TreeNode::getMaximum(size_t codelength) {

// score calculation


// Example: if this node is "abab", and we already have compressed by "ab"
// (_penaltyLength = 2) and our codes have length 1 then we actually gain only
// one byte per word (relevantLength = 1) by compressing with "abab"
Expand Down Expand Up @@ -152,8 +151,7 @@ void TreeNode::penaltize() {
// from now on
_active = false;
}
}

} // namespace ad_utility

// ______________________________________________________________________________________
std::vector<string> calculatePrefixes(const string& filename,
Expand Down
3 changes: 1 addition & 2 deletions src/index/PrefixHeuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,4 @@ class Tree {
std::pair<size_t, string> getAndDeleteMaximum(size_t codelength);
};

}

} // namespace ad_utility
2 changes: 1 addition & 1 deletion src/index/VocabularyImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "../util/File.h"
#include "../util/HashMap.h"
#include "../util/HashSet.h"
#include "./Vocabulary.h"
#include "./ConstantsIndexCreation.h"
#include "./Vocabulary.h"

using std::string;

Expand Down
21 changes: 11 additions & 10 deletions test/ConversionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,24 @@ TEST(ConversionsTest, isNumeric) {

TEST(ConversionsTest, convertNumericToIndexWordEndToEnd) {
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("42")),
"\"42\"^^<http://www.w3.org/2001/XMLSchema#int>");
"\"42\"^^<http://www.w3.org/2001/XMLSchema#int>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("42.3")),
"\"42.3\"^^<http://www.w3.org/2001/XMLSchema#float>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("12345678")),
"\"12345678\"^^<http://www.w3.org/2001/XMLSchema#int>");
"\"42.3\"^^<http://www.w3.org/2001/XMLSchema#float>");
ASSERT_EQ(
convertIndexWordToValueLiteral(convertNumericToIndexWord("12345678")),
"\"12345678\"^^<http://www.w3.org/2001/XMLSchema#int>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord(".4")),
"\"0.4\"^^<http://www.w3.org/2001/XMLSchema#float>");
"\"0.4\"^^<http://www.w3.org/2001/XMLSchema#float>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("-12.3")),
"\"-12.3\"^^<http://www.w3.org/2001/XMLSchema#float>");
"\"-12.3\"^^<http://www.w3.org/2001/XMLSchema#float>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("-2")),
"\"-2\"^^<http://www.w3.org/2001/XMLSchema#int>");
"\"-2\"^^<http://www.w3.org/2001/XMLSchema#int>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("0")),
"\"0\"^^<http://www.w3.org/2001/XMLSchema#int>");
"\"0\"^^<http://www.w3.org/2001/XMLSchema#int>");
ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("0.0")),
"\"0.0\"^^<http://www.w3.org/2001/XMLSchema#float>");
"\"0.0\"^^<http://www.w3.org/2001/XMLSchema#float>");
// TODO(schnelle) for whatever reason the actual result becomes 1230
//ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("0123")),
// ASSERT_EQ(convertIndexWordToValueLiteral(convertNumericToIndexWord("0123")),
// "\"123\"^^<http://www.w3.org/2001/XMLSchema#int>");
}

Expand Down
2 changes: 1 addition & 1 deletion test/VocabularyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Chair of Algorithms and Data Structures.
// Author: Björn Buchhold <buchholb>

#include "../src/index/Vocabulary.h"
#include <gtest/gtest.h>
#include <cstdio>
#include <nlohmann/json.hpp>
#include <vector>
#include "../src/index/Vocabulary.h"

using json = nlohmann::json;
using std::string;
Expand Down