Skip to content

Commit 024f8cc

Browse files
committed
Merge branch 'gh-343'
2 parents a7d2ab9 + 9cba3f8 commit 024f8cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+936
-1068
lines changed

.github/workflows/build_on_push.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ jobs:
2323
if: startsWith( matrix.os, 'ubuntu' )
2424
run: |
2525
sudo apt-get update -y
26-
sudo apt-get install -y cmake pkg-config gfortran nvidia-cuda-toolkit valgrind
26+
sudo apt-get install -y cmake pkg-config gfortran nvidia-cuda-toolkit valgrind libsqlite3-dev
2727
2828
- name: Install package dependencies
2929
if: startsWith( matrix.os, 'macos' )
3030
run: |
31-
brew install cmake pkg-config fmt spdlog nlohmann-json grpc
31+
brew install cmake pkg-config fmt spdlog nlohmann-json grpc sqlite
3232
echo "PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl@1.1/lib/pkgconfig" >> $GITHUB_ENV
3333
3434
- name: Set up Python

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install package dependencies
2828
run: |
2929
sudo apt-get update -y
30-
sudo apt-get install -y cmake pkg-config
30+
sudo apt-get install -y cmake pkg-config libsqlite3-dev
3131
3232
- name: Prepare
3333
run: |

INSTALL.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and build locally.
2323
- [fmt](https://github.com/fmtlib/fmt) >= 6.2
2424
- [spdlog](https://github.com/gabime/spdlog) >= 1.5
2525
- [json](https://github.com/nlohmann/json) >= 3.7
26+
- [sqlite](https://www.sqlite.org/) >= 3.14
2627

2728
Developer dependencies:
2829

@@ -57,29 +58,30 @@ it before.
5758
Install dependencies from packages on Fedora 32/33
5859

5960
dnf install python cmake pkg-config
60-
dnf install json-devel spdlog-devel fmt-devel grpc-devel grpc-plugins
61+
dnf install json-devel spdlog-devel fmt-devel sqlite-devel grpc-devel grpc-plugins
6162
dnf install gtest-devel gmock-devel # optional for running the tests
6263

6364
Install dependencies from packages on Arch
6465

6566
pacman -S python cmake pkg-config
66-
pacman -S grpc spdlog fmt nlohmann-json
67+
pacman -S grpc spdlog fmt nlohmann-json sqlite
6768
pacman -S gtest gmock # optional for running the tests
6869

6970
Install dependencies from packages on Ubuntu 20.04
7071

7172
apt-get install python cmake pkg-config
72-
apt-get install libfmt-dev libspdlog-dev nlohmann-json3-dev
73+
apt-get install libfmt-dev libspdlog-dev nlohmann-json3-dev libsqlite3-dev
7374
apt-get install libgrpc++-dev protobuf-compiler-grpc libssl-dev
7475

7576
Install dependencies from packages from Brew
7677

77-
brew install fmt spdlog nlohmann-json grpc pkg-config
78+
brew install fmt spdlog nlohmann-json sqlite grpc pkg-config
7879

7980
Install dependencies from packages on Alpine edge
8081

8182
apk add git cmake pkgconf make g++
82-
apk add protobuf-dev grpc-dev fmt-dev spdlog-dev nlohmann-json c-ares-dev
83+
apk add fmt-dev spdlog-dev nlohmann-json sqlite-dev
84+
apk add protobuf-dev grpc-dev c-ares-dev
8385

8486
### Platform: macOS
8587

source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ find_package(fmt REQUIRED)
2828
find_package(spdlog REQUIRED)
2929
find_package(PkgConfig REQUIRED)
3030
pkg_check_modules(gRPC REQUIRED IMPORTED_TARGET protobuf grpc++)
31+
pkg_check_modules(sqlite REQUIRED IMPORTED_TARGET sqlite3)
3132

3233
if (UNIX AND NOT APPLE)
3334
set(SUPPORT_PRELOAD 1)

source/bear/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ namespace {
201201
{
202202
auto commands = args.as_string(OUTPUT)
203203
.map<fs::path>([](const auto &output) {
204-
return fs::path(output).replace_extension(".commands.json");
204+
return fs::path(output).replace_extension(".sqlite3");
205205
})
206-
.unwrap_or(fs::path("commands.json"));
206+
.unwrap_or(fs::path("commands.sqlite3"));
207207

208208
auto environment = sys::env::from(const_cast<const char **>(envp));
209209
auto intercept = prepare_intercept(args, environment, commands);

source/citnames/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
add_library(citnames_json_a OBJECT
33
source/Configuration.cc
44
source/Output.cc
5+
source/semantic/Command.cc
56
)
67

78
target_link_libraries(citnames_json_a PUBLIC result_a)
@@ -49,6 +50,7 @@ target_link_libraries(citnames report_a)
4950
target_link_libraries(citnames flags_a)
5051
target_link_libraries(citnames shell_a)
5152
target_link_libraries(citnames sys_a)
53+
target_link_libraries(citnames rpc_a)
5254
target_link_libraries(citnames fmt::fmt)
5355
target_link_libraries(citnames spdlog::spdlog)
5456
target_link_libraries(citnames nlohmann_json::nlohmann_json)
@@ -84,6 +86,7 @@ if (ENABLE_UNIT_TESTS)
8486
target_link_libraries(citnames_unit_test flags_a)
8587
target_link_libraries(citnames_unit_test shell_a)
8688
target_link_libraries(citnames_unit_test sys_a)
89+
target_link_libraries(citnames_unit_test rpc_a)
8790
target_link_libraries(citnames_unit_test fmt::fmt)
8891
target_link_libraries(citnames_unit_test nlohmann_json::nlohmann_json)
8992
target_link_libraries(citnames_unit_test PkgConfig::GTest ${CMAKE_THREAD_LIBS_INIT})

source/citnames/source/Application.cc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "Configuration.h"
2424
#include "Output.h"
2525
#include "semantic/Tool.h"
26-
#include "intercept/output/Report.h"
2726

2827
#include <filesystem>
2928

@@ -118,29 +117,30 @@ namespace {
118117
namespace cs {
119118

120119
rust::Result<int> Command::execute() const {
120+
cs::CompilationDatabase output(configuration_.output.format, configuration_.output.content);
121+
121122
// get current compilations from the input.
122-
return report_serializer_.from_json(arguments_.input)
123+
return ic::EventsDatabase::open(arguments_.input)
123124
.map<Entries>([this](const auto &commands) {
124-
spdlog::debug("commands have read. [size: {}]", commands.executions.size());
125125
auto compilations = tools_.transform(commands);
126126
// remove duplicates
127127
return merge({}, compilations);
128128
})
129-
.and_then<Entries>([this](const auto &compilations) {
129+
.and_then<Entries>([this, &output](const auto &compilations) {
130130
// read back the current content and extend with the new elements.
131131
spdlog::debug("compilation entries created. [size: {}]", compilations.size());
132132
return (arguments_.append)
133-
? output_.from_json(arguments_.output.c_str())
133+
? output.from_json(arguments_.output.c_str())
134134
.template map<Entries>([&compilations](auto old_entries) {
135135
spdlog::debug("compilation entries have read. [size: {}]", old_entries.size());
136136
return merge(compilations, old_entries);
137137
})
138138
: rust::Result<Entries>(rust::Ok(compilations));
139139
})
140-
.and_then<size_t>([this](const auto &compilations) {
140+
.and_then<size_t>([this, &output](const auto &compilations) {
141141
// write the entries into the output file.
142142
spdlog::debug("compilation entries to output. [size: {}]", compilations.size());
143-
return output_.to_json(arguments_.output.c_str(), compilations);
143+
return output.to_json(arguments_.output.c_str(), compilations);
144144
})
145145
.map<int>([](auto size) {
146146
// just map to success exit code if it was successful.
@@ -159,7 +159,7 @@ namespace cs {
159159
"citnames",
160160
VERSION,
161161
{
162-
{cs::INPUT, {1, false, "path of the input file", {"commands.json"}, std::nullopt}},
162+
{cs::INPUT, {1, false, "path of the input file", {"commands.sqlite3"}, std::nullopt}},
163163
{cs::OUTPUT, {1, false, "path of the result file", {"compile_commands.json"}, std::nullopt}},
164164
{cs::CONFIG, {1, false, "path of the config file", std::nullopt, std::nullopt}},
165165
{cs::APPEND, {0, false, "append to output, instead of overwrite it", std::nullopt, std::nullopt}},
@@ -173,17 +173,16 @@ namespace cs {
173173

174174
auto arguments = into_arguments(args);
175175
auto configuration = into_configuration(args, environment);
176-
auto semantic = configuration.and_then<cs::semantic::Tools>([](auto config) {
177-
return semantic::Tools::from(config.compilation);
178-
});
176+
auto tools = configuration
177+
.and_then<cs::semantic::Tools>([](auto config) {
178+
return semantic::Tools::from(config.compilation);
179+
});
179180

180-
return rust::merge(arguments, configuration, semantic)
181+
return rust::merge(arguments, configuration, tools)
181182
.map<ps::CommandPtr>([](auto tuples) {
182-
const auto&[arguments, configuration, semantic] = tuples;
183+
const auto&[arguments, configuration, tools] = tuples;
183184
// read the configuration
184-
cs::CompilationDatabase output(configuration.output.format, configuration.output.content);
185-
report::ReportSerializer report_serializer;
186-
return std::make_unique<Command>(arguments, report_serializer, semantic, output);
185+
return std::make_unique<Command>(arguments, configuration, tools);
187186
});
188187
}
189188
}

source/citnames/source/Application.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
#include "Output.h"
2323
#include "semantic/Tool.h"
24+
#include "intercept/EventsDatabase.h"
2425
#include "libmain/ApplicationFromArgs.h"
2526
#include "libresult/Result.h"
2627
#include "libsys/Environment.h"
27-
#include "intercept/output/Report.h"
2828

2929
#include <filesystem>
30+
#include <utility>
3031

3132
namespace fs = std::filesystem;
3233

@@ -39,24 +40,20 @@ namespace cs {
3940
};
4041

4142
struct Command : ps::Command {
42-
Command(Arguments arguments,
43-
report::ReportSerializer report_serializer,
44-
cs::semantic::Tools tools,
45-
cs::CompilationDatabase output)
43+
44+
Command(Arguments arguments, cs::Configuration configuration, cs::semantic::Tools tools)
4645
: ps::Command()
47-
, arguments_(arguments)
48-
, report_serializer_(report_serializer)
46+
, arguments_(std::move(arguments))
47+
, configuration_(std::move(configuration))
4948
, tools_(tools)
50-
, output_(output)
5149
{ }
5250

5351
[[nodiscard]] rust::Result<int> execute() const override;
5452

5553
private:
5654
Arguments arguments_;
57-
report::ReportSerializer report_serializer_;
55+
cs::Configuration configuration_;
5856
cs::semantic::Tools tools_;
59-
cs::CompilationDatabase output_;
6057
};
6158

6259
struct Application : ps::ApplicationFromArgs {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Copyright (C) 2012-2020 by László Nagy
2+
This file is part of Bear.
3+
4+
Bear is a tool to generate compilation database for clang tooling.
5+
6+
Bear is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Bear is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "Command.h"
21+
22+
#include <iostream>
23+
24+
#include <nlohmann/json.hpp>
25+
26+
namespace cs::semantic {
27+
28+
bool operator==(const Command& lhs, const Command& rhs)
29+
{
30+
return (lhs.program == rhs.program)
31+
&& (lhs.arguments == rhs.arguments)
32+
&& (lhs.working_dir == rhs.working_dir)
33+
&& (lhs.environment == rhs.environment);
34+
}
35+
36+
std::ostream& operator<<(std::ostream& os, const Command& rhs)
37+
{
38+
nlohmann::json payload = nlohmann::json {
39+
{ "program", rhs.program },
40+
{ "arguments", nlohmann::json(rhs.arguments) },
41+
{ "working_dir", rhs.working_dir },
42+
};
43+
os << payload;
44+
return os;
45+
}
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (C) 2012-2020 by László Nagy
2+
This file is part of Bear.
3+
4+
Bear is a tool to generate compilation database for clang tooling.
5+
6+
Bear is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Bear is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#pragma once
21+
22+
#include <filesystem>
23+
#include <list>
24+
#include <map>
25+
#include <string>
26+
#include <iosfwd>
27+
28+
namespace fs = std::filesystem;
29+
30+
namespace cs::semantic {
31+
32+
// This represents the executed command itself. Describes all the
33+
// context that the caller was given. And these are the those parameters
34+
// which are essential for re-run the command.
35+
struct Command {
36+
fs::path program;
37+
std::list<std::string> arguments;
38+
fs::path working_dir;
39+
std::map<std::string, std::string> environment;
40+
};
41+
42+
bool operator==(const Command& lhs, const Command& rhs);
43+
std::ostream& operator<<(std::ostream&, const Command&);
44+
}

0 commit comments

Comments
 (0)