Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(ODB_SOURCES
include/model/buildaction.h
include/model/builddirectory.h
include/model/buildlog.h
include/model/buildsourcetarget.h
include/model/filecontent.h
Expand Down
37 changes: 37 additions & 0 deletions model/include/model/builddirectory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef CC_MODEL_BUILDDIRECTORY_H
#define CC_MODEL_BUILDDIRECTORY_H

#include <memory>

#include <odb/core.hxx>

#include <model/buildaction.h>
#include <model/file.h>

namespace cc
{
namespace model
{

struct BuildAction;

#pragma db object
struct BuildDirectory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this has to be a brand new table, foreign key, and all that jazz for the storage. BuildAction already contains string command;, for example. If "directory" is just another member of the entries in a compilation database JSON (just like "command"), then why isn't this reflected in the schema? Every build action MUST have a build directory (it just may or may not exist or point to anything meaningful).

This struct, as it is now, won't do uniqueing of build directories either, because it is the build directory that refers to one build action each. If we want a separate record to only store one directory ("string") exactly once, then it is the buildaction that has to refer into this relation's key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep backwards compatibility with existing databases, that's why I didn't want to change BuildAction's schema. Is that not a priority? In that case you're right, storing it in BuildAction would make more sense.

Deduplicating the strings is not worth the hassle, in the CodeCompass SQLite database BuildAction only takes up 0.012% of the space.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can easily reparse projects, backward-compatibility with existing databases is not a high priority.

{
#pragma db id auto
std::uint64_t id;

#pragma db not_null
std::string directory;

#pragma db not_null
#pragma db on_delete(cascade)
std::shared_ptr<BuildAction> action;
};

typedef std::shared_ptr<BuildDirectory> BuildDirectoryPtr;

} // model
} // cc

#endif // CC_MODEL_BUILDDIRECTORY_H
7 changes: 7 additions & 0 deletions plugins/cpp/parser/src/cppparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <model/buildaction.h>
#include <model/buildaction-odb.hxx>
#include <model/builddirectory.h>
#include <model/builddirectory-odb.hxx>
#include <model/buildsourcetarget.h>
#include <model/buildsourcetarget-odb.hxx>
#include <model/file.h>
Expand Down Expand Up @@ -254,6 +256,7 @@ void CppParser::addCompileCommand(

std::vector<model::BuildSource> sources;
std::vector<model::BuildTarget> targets;
model::BuildDirectory buildDir;

for (const auto& srcTarget : extractInputOutputs(command_))
{
Expand All @@ -277,6 +280,9 @@ void CppParser::addCompileCommand(

targets.push_back(std::move(buildTarget));
}

buildDir.directory = command_.Directory;
buildDir.action = buildAction_;

_ctx.srcMgr.persistFiles();

Expand All @@ -285,6 +291,7 @@ void CppParser::addCompileCommand(
_ctx.db->persist(buildSource);
for (model::BuildTarget buildTarget : targets)
_ctx.db->persist(buildTarget);
_ctx.db->persist(buildDir);
});
}

Expand Down