Changeset View
Changeset View
Standalone View
Standalone View
plugins/meson/mesonjobprune.cpp
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | Copyright 2018 Daniel Mensinger <daniel@mensinger-ka.de> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "mesonjobprune.h" | ||||
21 | #include "mesonbuilder.h" | ||||
22 | #include "mesonconfig.h" | ||||
23 | #include <KIO/DeleteJob> | ||||
24 | #include <QDir> | ||||
25 | #include <klocalizedstring.h> | ||||
26 | #include <outputview/outputmodel.h> | ||||
27 | | ||||
28 | using namespace KDevelop; | ||||
29 | | ||||
30 | MesonJobPrune::MesonJobPrune(Meson::BuildDir const& buildDir, QObject* parent) | ||||
31 | : OutputJob(parent, Verbose) | ||||
32 | , m_buildDir(buildDir.buildDir) | ||||
33 | , m_backend(buildDir.mesonBackend) | ||||
34 | { | ||||
35 | setCapabilities(Killable); | ||||
36 | setToolTitle(i18n("Meson")); | ||||
37 | setStandardToolView(KDevelop::IOutputView::BuildView); | ||||
38 | setBehaviours(KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll); | ||||
39 | } | ||||
40 | | ||||
41 | void MesonJobPrune::start() | ||||
42 | { | ||||
43 | auto* output = new OutputModel(this); | ||||
44 | setModel(output); | ||||
45 | startOutput(); | ||||
46 | | ||||
47 | auto status = MesonBuilder::evaluateBuildDirectory(m_buildDir, m_backend); | ||||
48 | | ||||
49 | switch (status) { | ||||
50 | case MesonBuilder::DOES_NOT_EXIST: | ||||
51 | case MesonBuilder::CLEAN: | ||||
52 | output->appendLine(i18n("The directory '%1' is already pruned", m_buildDir.toLocalFile())); | ||||
53 | emitResult(); | ||||
54 | return; | ||||
55 | case MesonBuilder::DIR_NOT_EMPTY: | ||||
56 | case MesonBuilder::INVALID_BUILD_DIR: | ||||
57 | output->appendLine( | ||||
58 | i18n("The directory '%1' does not appear to be a meson build directory", m_buildDir.toLocalFile())); | ||||
59 | output->appendLine(i18n("Aborting prune operation")); | ||||
60 | emitResult(); | ||||
61 | return; | ||||
62 | case MesonBuilder::EMPTY_STRING: | ||||
63 | output->appendLine( | ||||
64 | i18n("The current build configuration is broken, because the build directory is not specified")); | ||||
65 | emitResult(); | ||||
66 | return; | ||||
67 | default: | ||||
68 | break; | ||||
69 | } | ||||
70 | | ||||
71 | QDir d(m_buildDir.toLocalFile()); | ||||
72 | QList<QUrl> urls; | ||||
73 | const auto entries = d.entryList(QDir::NoDotAndDotDot | QDir::Hidden | QDir::AllEntries); | ||||
74 | urls.reserve(entries.size()); | ||||
75 | for (const auto& entry : entries) { | ||||
76 | urls << Path(m_buildDir, entry).toUrl(); | ||||
77 | } | ||||
78 | | ||||
79 | output->appendLine(i18n("Deleting contents of '%1'", m_buildDir.toLocalFile())); | ||||
80 | m_job = KIO::del(urls); | ||||
81 | m_job->start(); | ||||
82 | | ||||
83 | connect(m_job, &KJob::finished, this, [this, output](KJob* job) { | ||||
84 | if (job->error() == 0) { | ||||
85 | output->appendLine(i18n("** Prune successful **")); | ||||
86 | } else { | ||||
87 | output->appendLine(i18n("** Prune failed: %1 **", job->errorString())); | ||||
88 | } | ||||
89 | emitResult(); | ||||
90 | m_job = nullptr; | ||||
91 | }); | ||||
92 | } | ||||
93 | | ||||
94 | bool MesonJobPrune::doKill() | ||||
95 | { | ||||
96 | return m_job->kill(); | ||||
97 | } |