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 | |
14 | using namespace dpfservice; |
15 | |
16 | class CMakeGeneratorPrivate |
17 | { |
18 | friend class CMakeGenerator; |
19 | QSharedPointer<CMakeDebug> cmakeDebug; |
20 | }; |
21 | |
22 | CMakeGenerator::CMakeGenerator() |
23 | : d(new CMakeGeneratorPrivate()) |
24 | { |
25 | d->cmakeDebug.reset(new CMakeDebug()); |
26 | } |
27 | |
28 | CMakeGenerator::~CMakeGenerator() |
29 | { |
30 | if (d) |
31 | delete d; |
32 | } |
33 | |
34 | QString CMakeGenerator::debugger() |
35 | { |
36 | return "dap" ; |
37 | } |
38 | |
39 | bool CMakeGenerator::prepareDebug(const QMap<QString, QVariant> ¶m, QString &retMsg) |
40 | { |
41 | Q_UNUSED(param) |
42 | return d->cmakeDebug->prepareDebug(retMsg); |
43 | } |
44 | |
45 | bool CMakeGenerator::requestDAPPort(const QString &uuid, const QMap<QString, QVariant> ¶m, 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 | |
53 | bool CMakeGenerator::isNeedBuild() |
54 | { |
55 | return true; |
56 | } |
57 | |
58 | bool CMakeGenerator::isTargetReady() |
59 | { |
60 | return true; |
61 | } |
62 | |
63 | bool CMakeGenerator::isLaunchNotAttach() |
64 | { |
65 | return true; |
66 | } |
67 | |
68 | dap::LaunchRequest CMakeGenerator::launchDAP(const QMap<QString, QVariant> ¶m) |
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 | |
76 | QString CMakeGenerator::build(const QString& projectPath) |
77 | { |
78 | return CMakeBuild::build(toolKitName(), projectPath); |
79 | } |
80 | |
81 | QString CMakeGenerator::getProjectFile(const QString& projectPath) |
82 | { |
83 | return projectPath + QDir::separator() + "CMakeList.txt" ; |
84 | } |
85 | |
86 | QMap<QString, QVariant> CMakeGenerator::getDebugArguments(const dpfservice::ProjectInfo &projectInfo, |
87 | const QString ¤tFile) |
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 | |
98 | RunCommandInfo CMakeGenerator::getRunArguments(const ProjectInfo &projectInfo, const QString ¤tFile) |
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 | |