-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcprj_loader_impl.cpp
More file actions
100 lines (75 loc) · 2.59 KB
/
cprj_loader_impl.cpp
File metadata and controls
100 lines (75 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "cmake_project/impl/cprj_loader_impl.hpp"
#include "cmake_project/impl/cprj_project_impl.hpp"
#include "cmake_project/impl/cprj_includes_parser.hpp"
#include "cmake_project/impl/cprj_project_impl.hpp"
#include "compilation_db/api/cdb_command_object.hpp"
#include "compilation_db/api/cdb_database.hpp"
#include <std_fs>
#include <memory>
//------------------------------------------------------------------------------
namespace cmake_project {
//------------------------------------------------------------------------------
LoaderImpl::LoaderImpl() = default;
LoaderImpl::~LoaderImpl() = default;
//------------------------------------------------------------------------------
LoaderImpl::ProjectPtr LoaderImpl::load( const compilation_db::Database & _db )
{
ProjectPtr result{ createEmptyProject() };
const compilation_db::Database::IndexType count = _db.getCount();
for( compilation_db::Database::IndexType i = 0; i < count; ++i )
{
const compilation_db::CommandObject & command = _db.getObject( i );
const Path file = loadFile( command, *result );
loadCommand( command, file, *result );
}
return result;
}
//------------------------------------------------------------------------------
LoaderImpl::ProjectPtr LoaderImpl::createEmptyProject()
{
return ProjectPtr{ new ProjectImpl };
}
//------------------------------------------------------------------------------
LoaderImpl::Path LoaderImpl::loadFile(
const compilation_db::CommandObject & _commnad,
Project & _project
)
{
const std::string & fileStr = _commnad.getFile();
Path filePath{ fileStr };
if( filePath.is_relative() )
{
const std::string & dirStr = _commnad.getDirectory();
stdfs::path dirPath{ dirStr };
filePath = dirPath / filePath;
}
filePath = stdfs::lexically_normal( filePath );
_project.addFilePath( filePath );
return filePath;
}
//------------------------------------------------------------------------------
IncludesParser & LoaderImpl::ensureIncludesParser()
{
if( !m_includeParser )
{
m_includeParser = std::make_unique< IncludesParser >();
}
return *m_includeParser;
}
//------------------------------------------------------------------------------
void LoaderImpl::loadCommand(
const compilation_db::CommandObject & _commnad,
const Path & _currentFile,
Project & _project
)
{
IncludesParser & parser = ensureIncludesParser();
const std::string & cmd = _commnad.getCommand();
auto includes = parser.parse( cmd );
for( const Path & include : includes )
{
_project.addIncludeToFile( _currentFile, include );
}
}
//------------------------------------------------------------------------------
}