File indexing completed on 2024-05-19 04:41:19

0001 /*
0002     SPDX-FileCopyrightText: 2019 Daniel Mensinger <daniel@mensinger-ka.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "mesonconfig.h"
0010 #include "mesonoptions.h"
0011 #include "mesonprojectinfo.h"
0012 #include "mesontargets.h"
0013 #include "mesontests.h"
0014 
0015 #include <interfaces/iproject.h>
0016 
0017 #include <KJob>
0018 
0019 #include <QFutureWatcher>
0020 
0021 #include <memory>
0022 
0023 class QJsonObject;
0024 
0025 class MesonIntrospectJob : public KJob
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     enum Type { BENCHMARKS, BUILDOPTIONS, BUILDSYSTEM_FILES, DEPENDENCIES, INSTALLED, PROJECTINFO, TARGETS, TESTS };
0031     enum Mode { BUILD_DIR, MESON_FILE };
0032 
0033 public:
0034     explicit MesonIntrospectJob(KDevelop::IProject* project, QVector<Type> types, Mode mode, QObject* parent);
0035     explicit MesonIntrospectJob(KDevelop::IProject* project, KDevelop::Path meson, QVector<Type> types,
0036                                 QObject* parent);
0037     explicit MesonIntrospectJob(KDevelop::IProject* project, Meson::BuildDir buildDir, QVector<Type> types, Mode mode,
0038                                 QObject* parent);
0039 
0040     void start() override;
0041     bool doKill() override;
0042 
0043     QString getTypeString(Type type) const;
0044 
0045     MesonOptsPtr buildOptions();
0046     MesonProjectInfoPtr projectInfo();
0047     MesonTargetsPtr targets();
0048     MesonTestSuitesPtr tests();
0049 
0050 private:
0051     QString importJSONFile(const Meson::BuildDir& buildDir, Type type, QJsonObject* out);
0052     QString importMesonAPI(const Meson::BuildDir& buildDir, Type type, QJsonObject* out);
0053     QString import(Meson::BuildDir buildDir);
0054     void finished();
0055 
0056     QFutureWatcher<QString> m_futureWatcher;
0057 
0058     // The commands to execute
0059     QVector<Type> m_types = {};
0060     Mode m_mode = BUILD_DIR;
0061     Meson::BuildDir m_buildDir;
0062     KDevelop::Path m_projectPath;
0063     KDevelop::IProject* m_project = nullptr;
0064 
0065     // The results
0066     MesonOptsPtr m_res_options = nullptr;
0067     MesonProjectInfoPtr m_res_projectInfo = nullptr;
0068     MesonTargetsPtr m_res_targets = nullptr;
0069     MesonTestSuitesPtr m_res_tests = nullptr;
0070 };