Skip to content

Commit 5609769

Browse files
committed
Merge branch 'develop'
2 parents df425e5 + bd0d1ba commit 5609769

9 files changed

Lines changed: 79 additions & 59 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
`cppscanner` is a standalone command-line utility to create snapshots of C++ programs.
55
It is based on clang's [LibTooling](https://clang.llvm.org/docs/LibTooling.html).
66

7-
Snapshots are saved as a SQLite database, making them easily usable in other programs.
7+
Snapshots are saved as SQLite databases, making them easily usable in other programs.<br/>
8+
The companion project [cppbrowser](https://github.com/strandfield/cppbrowser) provides navigation
9+
of snapshots in a Web browser.
10+
11+
[Browse the source code](https://code.strandfield.dev/snapshots/cppscanner/0.5.0)
812

913
## Compiling the project
1014

modules/cppscanner/base/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
#define CPPSCANNER_VERSION_MAJOR 0
99
#define CPPSCANNER_VERSION_MINOR 5
10-
#define CPPSCANNER_VERSION_PATCH 0
10+
#define CPPSCANNER_VERSION_PATCH 1
1111

12-
#define CPPSCANNER_VERSION_STRING "0.5.0"
12+
#define CPPSCANNER_VERSION_STRING "0.5.1"
1313

1414
namespace cppscanner
1515
{

modules/cppscanner/database/database.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace cppscanner
1414
{
1515

16-
Database::Database(Database&& other) :
16+
Database::Database(Database&& other) noexcept :
1717
m_database(other.m_database)
1818
{
1919
other.m_database = nullptr;
@@ -83,7 +83,7 @@ void Database::close()
8383
m_database = nullptr;
8484
}
8585

86-
Database& Database::operator=(Database&& other)
86+
Database& Database::operator=(Database&& other) noexcept
8787
{
8888
m_database = other.m_database;
8989
other.m_database = nullptr;

modules/cppscanner/database/database.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Database
2727
public:
2828
Database() = default;
2929
Database(const Database&) = delete;
30-
Database(Database&& other);
30+
Database(Database&& other) noexcept;
3131
~Database();
3232

3333
sqlite3* sqliteHandle() const;
@@ -41,7 +41,7 @@ class Database
4141
void close();
4242

4343
Database& operator=(const Database&) = delete;
44-
Database& operator=(Database&& other);
44+
Database& operator=(Database&& other) noexcept;
4545

4646
private:
4747
sqlite3* m_database = nullptr;

modules/cppscanner/database/sql.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Statement
5353
explicit Statement(Database& db);
5454
Statement(Database& db, const char* query);
5555
Statement(const Statement&) = delete;
56-
Statement(Statement&& other);
56+
Statement(Statement&& other) noexcept;
5757
~Statement();
5858

5959
Database& database() const;
@@ -100,7 +100,7 @@ inline Statement::Statement(Database& db, const char* query)
100100
prepare(query);
101101
}
102102

103-
inline Statement::Statement(Statement&& other) :
103+
inline Statement::Statement(Statement&& other) noexcept :
104104
m_database(other.m_database),
105105
m_statement(other.m_statement)
106106
{

modules/cppscanner/scannerInvocation/scannerinvocation.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ namespace cppscanner
1919
namespace
2020
{
2121

22-
bool isOption(const std::string& arg)
23-
{
24-
return !arg.empty() && arg.front() == '-';
25-
}
26-
2722
// test if arg is "-j<number>"
2823
bool isJobsArg(const std::string& arg)
2924
{
@@ -460,7 +455,7 @@ constexpr const char* RUN_DESCRIPTION = R"(Description:
460455

461456
constexpr const char* RUN_EXAMPLES = R"(Example:
462457
Compile a single file with C++17 enabled:
463-
cppscanner -i source.cpp -o snapshot.db -- -std=c++17)";
458+
cppscanner run -i source.cpp -o snapshot.db -- -std=c++17)";
464459

465460
constexpr const char* MERGE_DESCRIPTION = R"(Description:
466461
Merge two or more snapshots into one.)";

modules/cppscanner/snapshot/merge.cpp

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -289,76 +289,92 @@ void SnapshotMerger::runMerge()
289289
{
290290
Snapshot::Properties properties;
291291

292-
properties["cppscanner.version"] = cppscanner::versioncstr();
293-
properties["cppscanner.os"] = cppscanner::system_name();
294-
295-
bool a_new_home = false;
296-
297-
// look at home value for each project
292+
// process properties as found in the snapshots
298293
{
299-
std::optional<std::string> common_home;
300-
ValueUpdater updater{ common_home };
294+
std::set<std::string> property_names;
301295

302296
for (InputSnapshot& snapshot : m_snapshots)
303297
{
304-
updater.update(snapshot.properties.at("project.home"));
298+
for (const auto& p : snapshot.properties)
299+
{
300+
property_names.insert(p.first);
301+
}
305302
}
306303

307-
if (updater.valid())
308-
{
309-
home = common_home.value();
310-
}
311-
else
304+
for (const std::string& key : property_names)
312305
{
313-
a_new_home = true;
314-
// TODO: print warning ?
306+
std::optional<std::string> value;
307+
ValueUpdater updater{ value };
308+
309+
for (InputSnapshot& snapshot : m_snapshots)
310+
{
311+
updater.update(getProperty(snapshot.properties, key));
312+
}
313+
314+
if (updater.valid())
315+
{
316+
properties[key] = *value;
317+
}
315318
}
316319
}
317320

318-
if (m_project_home_path.has_value())
321+
// compute the "home" property
319322
{
320-
std::string final_home = Snapshot::normalizedPath(m_project_home_path->generic_u8string());
321-
a_new_home = a_new_home || final_home != home;
322-
home = std::move(final_home);
323-
}
323+
bool a_new_home = false;
324324

325-
if (home.empty())
326-
{
327-
// this is bad.
328-
// TODO: abort merge ?
329-
}
325+
// look at home value for each project
326+
{
327+
std::optional<std::string> common_home;
328+
ValueUpdater updater{ common_home };
330329

331-
if (a_new_home)
332-
{
333-
// TODO: voir si on peut trouver une autre façon de rapporter l'info
334-
std::cout << "Input snapshots do not have a common project.home property, or a new one was specified." << "\n";
335-
std::cout << "Some data may be erased." << std::endl;
336-
}
330+
for (InputSnapshot& snapshot : m_snapshots)
331+
{
332+
updater.update(snapshot.properties.at("project.home"));
333+
}
337334

338-
properties["project.home"] = home;
335+
if (updater.valid())
336+
{
337+
home = common_home.value();
338+
}
339+
else
340+
{
341+
a_new_home = true;
342+
// TODO: print warning ?
343+
}
344+
}
339345

340-
const std::vector<std::string> extraProps{ "scanner.indexLocalSymbols", "scanner.indexExternalFiles", "scanner.root" };
341-
for (const std::string& key : extraProps)
342-
{
343-
std::optional<std::string> value;
344-
ValueUpdater updater{ value };
346+
if (m_project_home_path.has_value())
347+
{
348+
std::string final_home = Snapshot::normalizedPath(m_project_home_path->generic_u8string());
349+
a_new_home = a_new_home || final_home != home;
350+
home = std::move(final_home);
351+
}
345352

346-
for (InputSnapshot& snapshot : m_snapshots)
353+
if (home.empty())
347354
{
348-
updater.update(getProperty(snapshot.properties, key));
355+
// this is bad.
356+
// TODO: abort merge ?
349357
}
350358

351-
if (updater.valid())
359+
if (a_new_home)
352360
{
353-
properties[key] = *value;
361+
// TODO: voir si on peut trouver une autre façon de rapporter l'info
362+
std::cout << "Input snapshots do not have a common project.home property, or a new one was specified." << "\n";
363+
std::cout << "Some data may be erased." << std::endl;
354364
}
355-
}
356365

366+
properties["project.home"] = home;
367+
}
368+
369+
// write extra properties
357370
for (const auto& p : m_extra_properties)
358371
{
359372
properties[p.first] = p.second;
360373
}
361374

375+
properties["cppscanner.version"] = cppscanner::versioncstr();
376+
properties["cppscanner.os"] = cppscanner::system_name();
377+
362378
writer().beginTransaction();
363379
writer().insert(properties);
364380
writer().endTransaction();

modules/cppscanner/snapshot/snapshotwriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static const char* SQL_CREATE_STATEMENTS = R"(
8585
BEGIN TRANSACTION;
8686
8787
CREATE TABLE "info" (
88-
"key" TEXT NOT NULL,
88+
"key" TEXT NOT NULL UNIQUE,
8989
"value" TEXT NOT NULL
9090
);
9191

tests/selftest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#include "helpers.h"
33

4+
#include "cppscanner/base/config.h"
45
#include "cppscanner/scannerInvocation/scannerinvocation.h"
56
#include "cppscanner/index/symbol.h"
67
#include "cppscanner/database/sql.h"
@@ -44,6 +45,10 @@ TEST_CASE("Self parsing test", "[scanner][self]")
4445

4546
SnapshotReader s{ snapshot_name };
4647

48+
Snapshot::Properties props = s.readProperties();
49+
REQUIRE(props[PROPERTY_PROJECT_NAME] == "cppscanner");
50+
REQUIRE(props[PROPERTY_PROJECT_VERSION] == cppscanner::versioncstr());
51+
4752
// verify the presence of some classes
4853
{
4954
SymbolRecord ns = s.getSymbolByName("cppscanner");

0 commit comments

Comments
 (0)