Changeset View
Changeset View
Standalone View
Standalone View
projectmanagers/cmake/cmakeimportjob.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 71 | if(subjobs().isEmpty() && m_started) { | |||
---|---|---|---|---|---|
73 | emitResult(); | 73 | emitResult(); | ||
74 | } | 74 | } | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | private: | 77 | private: | ||
78 | bool m_started; | 78 | bool m_started; | ||
79 | }; | 79 | }; | ||
80 | 80 | | |||
81 | CMakeImportJob::CMakeImportJob(ProjectFolderItem* dom, CMakeManager* parent) | 81 | CMakeImportJsonJob::CMakeImportJsonJob(ProjectFolderItem* dom, CMakeManager* parent) | ||
82 | : KJob(parent) | 82 | : KJob(parent) | ||
83 | , m_project(dom->project()) | 83 | , m_project(dom->project()) | ||
84 | , m_dom(dom) | 84 | , m_dom(dom) | ||
85 | , m_data(parent->projectData(dom->project())) | 85 | , m_data(parent->projectData(dom->project())) | ||
86 | , m_manager(parent) | 86 | , m_manager(parent) | ||
87 | , m_futureWatcher(new QFutureWatcher<void>) | 87 | , m_futureWatcher(new QFutureWatcher<void>) | ||
88 | { | 88 | { | ||
89 | connect(m_futureWatcher, SIGNAL(finished()), SLOT(importFinished())); | 89 | connect(m_futureWatcher, SIGNAL(finished()), SLOT(importFinished())); | ||
90 | } | 90 | } | ||
91 | 91 | | |||
92 | void CMakeImportJob::start() | 92 | void CMakeImportJsonJob::start() | ||
93 | { | 93 | { | ||
94 | QFuture<void> future = QtConcurrent::run(this, &CMakeImportJob::initialize); | 94 | QFuture<void> future = QtConcurrent::run(this, &CMakeImportJob::initialize); | ||
95 | m_futureWatcher->setFuture(future); | 95 | m_futureWatcher->setFuture(future); | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | void CMakeImportJob::importFinished() | 98 | void CMakeImportJsonJob::importCompileCommandsJsonFinished() | ||
99 | { | 99 | { | ||
100 | Q_ASSERT(m_project->thread() == QThread::currentThread()); | 100 | Q_ASSERT(m_project->thread() == QThread::currentThread()); | ||
101 | 101 | | |||
102 | WaitAllJobs* wjob = new WaitAllJobs(this); | 102 | WaitAllJobs* wjob = new WaitAllJobs(this); | ||
103 | connect(wjob, SIGNAL(finished(KJob*)), SLOT(waitFinished(KJob*))); | 103 | connect(wjob, SIGNAL(finished(KJob*)), SLOT(waitFinished(KJob*))); | ||
104 | foreach(KJob* job, m_jobs) { | 104 | foreach(KJob* job, m_jobs) { | ||
105 | wjob->addJob(job); | 105 | wjob->addJob(job); | ||
106 | } | 106 | } | ||
107 | wjob->start(); | 107 | wjob->start(); | ||
108 | } | 108 | } | ||
109 | 109 | | |||
110 | void CMakeImportJob::initialize() | 110 | void CMakeImportJsonJob::initialize() | ||
111 | { | 111 | { | ||
112 | ReferencedTopDUContext ctx; | 112 | ReferencedTopDUContext ctx; | ||
113 | ProjectBaseItem* parent = m_dom->parent(); | 113 | ProjectBaseItem* parent = m_dom->parent(); | ||
114 | while (parent && !ctx) { | 114 | while (parent && !ctx) { | ||
115 | DUChainReadLocker lock; | 115 | DUChainReadLocker lock; | ||
116 | ctx = DUChain::self()->chainForDocument(IndexedString(Path(parent->path(), "CMakeLists.txt").pathOrUrl())); | 116 | ctx = DUChain::self()->chainForDocument(IndexedString(Path(parent->path(), "CMakeLists.txt").pathOrUrl())); | ||
117 | parent = parent->parent(); | 117 | parent = parent->parent(); | ||
118 | } | 118 | } | ||
119 | if (!ctx) { | 119 | if (!ctx) { | ||
120 | ctx = initializeProject(dynamic_cast<CMakeFolderItem*>(m_dom)); | 120 | ctx = initializeProject(dynamic_cast<CMakeFolderItem*>(m_dom)); | ||
121 | } | 121 | } | ||
122 | importDirectory(m_project, m_dom->path(), ctx); | 122 | importDirectory(m_project, m_dom->path(), ctx); | ||
123 | } | 123 | } | ||
124 | 124 | | |||
125 | KDevelop::ReferencedTopDUContext CMakeImportJob::initializeProject(CMakeFolderItem* rootFolder) | 125 | KDevelop::ReferencedTopDUContext CMakeImportJsonJob::initializeProject(CMakeFolderItem* rootFolder) | ||
126 | { | 126 | { | ||
127 | Path base(CMake::projectRoot(m_project)); | 127 | Path base(CMake::projectRoot(m_project)); | ||
128 | 128 | | |||
129 | QPair<VariableMap,QStringList> initials = CMakeParserUtils::initialVariables(); | 129 | QPair<VariableMap,QStringList> initials = CMakeParserUtils::initialVariables(); | ||
130 | 130 | | |||
131 | m_data.clear(); | 131 | m_data.clear(); | ||
132 | m_data.modulePath=initials.first["CMAKE_MODULE_PATH"]; | 132 | m_data.modulePath=initials.first["CMAKE_MODULE_PATH"]; | ||
133 | m_data.vm=initials.first; | 133 | m_data.vm=initials.first; | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 171 | while(!toimport.isEmpty()) { | |||
188 | } | 188 | } | ||
189 | } | 189 | } | ||
190 | rootFolder->setIncludeDirectories(includes); | 190 | rootFolder->setIncludeDirectories(includes); | ||
191 | rootFolder->setBuildDir(base.relativePath(m_project->path())); | 191 | rootFolder->setBuildDir(base.relativePath(m_project->path())); | ||
192 | } | 192 | } | ||
193 | return ref; | 193 | return ref; | ||
194 | } | 194 | } | ||
195 | 195 | | |||
196 | void CMakeImportJob::waitFinished(KJob*) | 196 | void CMakeImportJsonJob::waitFinished(KJob*) | ||
197 | { | 197 | { | ||
198 | emitResult(); | 198 | emitResult(); | ||
199 | } | 199 | } | ||
200 | 200 | | |||
201 | KDevelop::ReferencedTopDUContext CMakeImportJob::includeScript(const QString& file, const QString& dir, ReferencedTopDUContext parent) | 201 | KDevelop::ReferencedTopDUContext CMakeImportJsonJob::includeScript(const QString& file, const QString& dir, ReferencedTopDUContext parent) | ||
202 | { | 202 | { | ||
203 | m_manager->addWatcher(m_project, file); | 203 | m_manager->addWatcher(m_project, file); | ||
204 | QString profile = CMake::currentEnvironment(m_project); | 204 | QString profile = CMake::currentEnvironment(m_project); | ||
205 | const KDevelop::EnvironmentProfileList env(KSharedConfig::openConfig()); | 205 | const KDevelop::EnvironmentProfileList env(KSharedConfig::openConfig()); | ||
206 | return CMakeParserUtils::includeScript( file, parent, &m_data, dir, env.variables(profile)); | 206 | return CMakeParserUtils::includeScript( file, parent, &m_data, dir, env.variables(profile)); | ||
207 | } | 207 | } | ||
208 | 208 | | |||
209 | CMakeCommitChangesJob* CMakeImportJob::importDirectory(IProject* project, const Path& path, const KDevelop::ReferencedTopDUContext& parentTop) | 209 | CMakeCommitChangesJob* CMakeImportJsonJob::importDirectory(IProject* project, const Path& path, const KDevelop::ReferencedTopDUContext& parentTop) | ||
210 | { | 210 | { | ||
211 | Q_ASSERT(thread() == m_project->thread()); | 211 | Q_ASSERT(thread() == m_project->thread()); | ||
212 | Path cmakeListsPath(path, "CMakeLists.txt"); | 212 | Path cmakeListsPath(path, "CMakeLists.txt"); | ||
213 | CMakeCommitChangesJob* commitJob = new CMakeCommitChangesJob(path, m_manager, project); | 213 | CMakeCommitChangesJob* commitJob = new CMakeCommitChangesJob(path, m_manager, project); | ||
214 | commitJob->moveToThread(thread()); | 214 | commitJob->moveToThread(thread()); | ||
215 | m_jobs += commitJob; | 215 | m_jobs += commitJob; | ||
216 | if(QFile::exists(cmakeListsPath.toLocalFile())) | 216 | if(QFile::exists(cmakeListsPath.toLocalFile())) | ||
217 | { | 217 | { | ||
Show All 18 Lines | 235 | connect(commitJob, SIGNAL(folderCreated(KDevelop::ProjectFolderItem*)), | |||
236 | job, SLOT(folderAvailable(KDevelop::ProjectFolderItem*))); | 236 | job, SLOT(folderAvailable(KDevelop::ProjectFolderItem*))); | ||
237 | } | 237 | } | ||
238 | m_data.vm.popScope(); | 238 | m_data.vm.popScope(); | ||
239 | } | 239 | } | ||
240 | 240 | | |||
241 | return commitJob; | 241 | return commitJob; | ||
242 | } | 242 | } | ||
243 | 243 | | |||
244 | IProject* CMakeImportJob::project() const | 244 | IProject* CMakeImportJsonJob::project() const | ||
245 | { | 245 | { | ||
246 | Q_ASSERT(!m_futureWatcher->isRunning()); | 246 | Q_ASSERT(!m_futureWatcher->isRunning()); | ||
247 | return m_project; | 247 | return m_project; | ||
248 | } | 248 | } | ||
249 | 249 | | |||
250 | CMakeProjectData CMakeImportJob::projectData() const | 250 | CMakeProjectData CMakeImportJsonJob::projectData() const | ||
251 | { | 251 | { | ||
252 | Q_ASSERT(!m_futureWatcher->isRunning()); | 252 | Q_ASSERT(!m_futureWatcher->isRunning()); | ||
253 | return m_data; | 253 | return m_data; | ||
254 | } | 254 | } | ||
255 | 255 | | |||
256 | #include "moc_cmakeimportjob.cpp" | 256 | #include "moc_cmakeimportjob.cpp" | ||
257 | #include "cmakeimportjob.moc" | 257 | #include "cmakeimportjob.moc" |