Skip to content

Commit cdc7057

Browse files
committed
Merge branch 'devel' into master
2 parents 41c1bdc + e05082c commit cdc7057

File tree

23 files changed

+87
-87
lines changed

23 files changed

+87
-87
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
22
cmake_policy(VERSION 3.12)
33

44
project(Bear
5-
VERSION 3.0.2
5+
VERSION 3.0.3
66
DESCRIPTION "Bear is a tool to generate compilation database for clang tooling."
77
LANGUAGES C CXX
88
)

source/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ include(GNUInstallDirs) # The directory names are used in the config file
6565
configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
6666
include_directories(${CMAKE_CURRENT_BINARY_DIR})
6767

68-
add_subdirectory(bear)
69-
add_subdirectory(citnames)
7068
add_subdirectory(libresult)
7169
add_subdirectory(libflags)
72-
add_subdirectory(libreport)
7370
add_subdirectory(libshell)
7471
add_subdirectory(libsys)
7572
add_subdirectory(intercept)
73+
add_subdirectory(citnames)
74+
add_subdirectory(bear)

source/citnames/source/Application.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
#include "Configuration.h"
2222
#include "Output.h"
2323
#include "semantic/Tool.h"
24-
25-
#include "libreport/Report.h"
24+
#include "intercept/output/Report.h"
2625

2726
#include <filesystem>
2827

source/citnames/source/Output.cc

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <algorithm>
2424
#include <iomanip>
2525
#include <fstream>
26+
#include <set>
2627

2728
#include <fmt/format.h>
2829
#include <nlohmann/json.hpp>
@@ -63,29 +64,27 @@ namespace {
6364
};
6465
}
6566

66-
using Comparator = std::function<bool(const cs::Entry &lhs, const cs::Entry &rhs)>;
67+
using Hash = std::function<std::string(const cs::Entry &entry)>;
6768

68-
bool compare_by_output(const cs::Entry &lhs, const cs::Entry &rhs) {
69-
// compare entries by the source and the output attribute only.
70-
return (lhs.file == rhs.file) && (lhs.output == rhs.output);
69+
std::string hash_by_output(const cs::Entry &entry) {
70+
return fmt::format("{}<->{}",
71+
entry.file.string(),
72+
entry.output.value_or(fs::path()).string());
7173
}
7274

73-
bool compare_by_all(const cs::Entry &lhs, const cs::Entry &rhs) {
74-
// compare entries by all possible attributes except the output field.
75-
return (lhs.file == rhs.file)
76-
&& (lhs.directory == rhs.directory)
77-
&& (std::equal(
78-
std::next(lhs.arguments.begin()),
79-
lhs.arguments.end(),
80-
std::next(rhs.arguments.begin())));
75+
std::string hash_by_all(const cs::Entry &entry) {
76+
return fmt::format("{}<->{}<->{}",
77+
entry.file.string(),
78+
entry.directory.string(),
79+
fmt::join(std::next(entry.arguments.begin()), entry.arguments.end(), ","));
8180
}
8281

83-
Comparator select_comparator(const cs::Entries &lhs, const cs::Entries &rhs) {
84-
// Select comparator based on the input values.
82+
Hash select_hash(const cs::Entries &lhs, const cs::Entries &rhs) {
83+
// Select hash function based on the input values.
8584
const bool lhs_outputs = std::all_of(lhs.begin(), lhs.end(), [](auto entry) { return entry.output; });
8685
const bool rhs_outputs = std::all_of(rhs.begin(), rhs.end(), [](auto entry) { return entry.output; });
8786
// if all entries have the output field, it can compare by the output field.
88-
return (lhs_outputs && rhs_outputs) ? compare_by_output : compare_by_all;
87+
return (lhs_outputs && rhs_outputs) ? hash_by_output : hash_by_all;
8988
}
9089
}
9190

@@ -239,14 +238,24 @@ namespace cs {
239238
Entries merge(const Entries &lhs, const Entries &rhs) {
240239
Entries result;
241240
// create a predicate which decides if the entry is already in the result.
242-
auto comparator = select_comparator(lhs, rhs);
243-
auto not_in_result = [&result, &comparator](const auto &it) {
244-
return std::none_of(result.begin(), result.end(),
245-
[&comparator, &it](const auto &already_in) { return comparator(already_in, it); });
246-
};
247-
// apply the predicate.
248-
std::copy_if(lhs.begin(), lhs.end(), std::back_inserter(result), not_in_result);
249-
std::copy_if(rhs.begin(), rhs.end(), std::back_inserter(result), not_in_result);
241+
auto hasher = select_hash(lhs, rhs);
242+
std::set<std::string> in_results_hashes;
243+
// copy the elements into the result list depending if it already there.
244+
for (const auto &entry : lhs) {
245+
auto hash = hasher(entry);
246+
if (in_results_hashes.find(hash) == in_results_hashes.end()) {
247+
in_results_hashes.insert(hash);
248+
result.push_back(entry);
249+
}
250+
}
251+
for (const auto &entry : rhs) {
252+
auto hash = hasher(entry);
253+
if (in_results_hashes.find(hash) == in_results_hashes.end()) {
254+
in_results_hashes.insert(hash);
255+
result.push_back(entry);
256+
}
257+
}
258+
250259
return result;
251260
}
252261

source/citnames/source/semantic/Parsers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#pragma once
2121

22-
#include "libreport/Report.h"
22+
#include "intercept/output/Report.h"
2323
#include "libresult/Result.h"
2424

2525
#include <cstdint>

source/citnames/source/semantic/Semantic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#pragma once
2121

2222
#include "Output.h"
23-
#include "libreport/Report.h"
23+
#include "intercept/output/Report.h"
2424

2525
#include <filesystem>
2626
#include <list>

source/citnames/source/semantic/Tool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "Output.h"
2424
#include "semantic/Semantic.h"
2525
#include "libresult/Result.h"
26-
#include "libreport/Report.h"
26+
#include "intercept/output/Report.h"
2727

2828
#include <filesystem>
2929
#include <list>

source/intercept/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ add_subdirectory(proto)
22

33
include(GNUInstallDirs)
44

5+
add_library(report_a OBJECT
6+
source/collect/Report.cc
7+
)
8+
9+
target_include_directories(report_a PUBLIC include)
10+
target_link_libraries(report_a PUBLIC result_a)
11+
target_link_libraries(report_a PRIVATE fmt::fmt)
12+
target_link_libraries(report_a PRIVATE nlohmann_json::nlohmann_json)
13+
target_compile_options(report_a PRIVATE -fexceptions)
14+
515
# Create a static library, which is used for unit tests and the final shared library.
616
add_library(intercept_a OBJECT
717
source/collect/Application.cc
@@ -54,6 +64,7 @@ install(FILES man/intercept.1
5464
# Create unit test
5565
if (ENABLE_UNIT_TESTS)
5666
add_executable(intercept_unit_test
67+
test/ReportTest.cc
5768
test/ReporterTest.cc
5869
test/SessionTest.cc
5970
)

source/libreport/source/Report.cc renamed to source/intercept/source/collect/Report.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
#include "libreport/Report.h"
20+
#include "intercept/output/Report.h"
2121

2222
#include <iomanip>
2323
#include <fstream>

0 commit comments

Comments
 (0)