1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "cmakegenerator.h"
6
7#include "cmakebuild.h"
8#include "cmakedebug.h"
9#include "services/project/projectservice.h"
10#include <framework/framework.h>
11
12#include <QFile>
13
14using namespace dpfservice;
15
16class CMakeGeneratorPrivate
17{
18 friend class CMakeGenerator;
19 QSharedPointer<CMakeDebug> cmakeDebug;
20};
21
22CMakeGenerator::CMakeGenerator()
23 : d(new CMakeGeneratorPrivate())
24{
25 d->cmakeDebug.reset(new CMakeDebug());
26}
27
28CMakeGenerator::~CMakeGenerator()
29{
30 if (d)
31 delete d;
32}
33
34QString CMakeGenerator::debugger()
35{
36 return "dap";
37}
38
39bool CMakeGenerator::prepareDebug(const QMap<QString, QVariant> &param, QString &retMsg)
40{
41 Q_UNUSED(param)
42 return d->cmakeDebug->prepareDebug(retMsg);
43}
44
45bool CMakeGenerator::requestDAPPort(const QString &uuid, const QMap<QString, QVariant> &param, QString &retMsg)
46{
47 QString targetPath = param.value("targetPath").toString();
48 QStringList arguments = param.value("arguments").toStringList();
49
50 return d->cmakeDebug->requestDAPPort(uuid, toolKitName(), targetPath, arguments, retMsg);
51}
52
53bool CMakeGenerator::isNeedBuild()
54{
55 return true;
56}
57
58bool CMakeGenerator::isTargetReady()
59{
60 return true;
61}
62
63bool CMakeGenerator::isLaunchNotAttach()
64{
65 return true;
66}
67
68dap::LaunchRequest CMakeGenerator::launchDAP(const QMap<QString, QVariant> &param)
69{
70 QString targetPath = param.value("targetPath").toString();
71 QStringList arguments = param.value("arguments").toStringList();
72
73 return d->cmakeDebug->launchDAP(targetPath, arguments);
74}
75
76QString CMakeGenerator::build(const QString& projectPath)
77{
78 return CMakeBuild::build(toolKitName(), projectPath);
79}
80
81QString CMakeGenerator::getProjectFile(const QString& projectPath)
82{
83 return projectPath + QDir::separator() + "CMakeList.txt";
84}
85
86QMap<QString, QVariant> CMakeGenerator::getDebugArguments(const dpfservice::ProjectInfo &projectInfo,
87 const QString &currentFile)
88{
89 Q_UNUSED(currentFile)
90
91 QMap<QString, QVariant> param;
92 param.insert("workspace", projectInfo.runWorkspaceDir());
93 param.insert("targetPath", projectInfo.runProgram());
94
95 return param;
96}
97
98RunCommandInfo CMakeGenerator::getRunArguments(const ProjectInfo &projectInfo, const QString &currentFile)
99{
100 Q_UNUSED(currentFile)
101
102 RunCommandInfo runCommaindInfo;
103 runCommaindInfo.program = projectInfo.runProgram();
104 runCommaindInfo.arguments = projectInfo.runCustomArgs();
105 runCommaindInfo.workingDir = projectInfo.runWorkspaceDir();
106 return runCommaindInfo;
107}
108