1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "ninjabuildergenerator.h" |
6 | #include "ninja/builder/parser/ninjaparser.h" |
7 | #include "services/window/windowservice.h" |
8 | #include "services/builder/builderservice.h" |
9 | #include "services/option/optionmanager.h" |
10 | |
11 | using namespace dpfservice; |
12 | |
13 | class NinjaBuilderGeneratorPrivate |
14 | { |
15 | friend class NinjaBuilderGenerator; |
16 | }; |
17 | |
18 | NinjaBuilderGenerator::NinjaBuilderGenerator() |
19 | : d(new NinjaBuilderGeneratorPrivate()) |
20 | { |
21 | |
22 | } |
23 | |
24 | NinjaBuilderGenerator::~NinjaBuilderGenerator() |
25 | { |
26 | if (d) |
27 | delete d; |
28 | } |
29 | |
30 | BuildCommandInfo NinjaBuilderGenerator::getMenuCommand(const BuildMenuType buildMenuType, const dpfservice::ProjectInfo &projectInfo) |
31 | { |
32 | BuildCommandInfo info; |
33 | info.kitName = projectInfo.kitName(); |
34 | info.workingDir = projectInfo.workspaceFolder(); |
35 | info.program = projectInfo.buildProgram(); |
36 | if (info.program.isEmpty()) |
37 | info.program = OptionManager::getInstance()->getNinjaToolPath(); |
38 | switch (buildMenuType) { |
39 | case Build: |
40 | info.arguments.append("all"); |
41 | break; |
42 | case Clean: |
43 | info.arguments.append("clean"); |
44 | break; |
45 | } |
46 | |
47 | return info; |
48 | } |
49 | |
50 | void NinjaBuilderGenerator::appendOutputParser(std::unique_ptr<IOutputParser> &outputParser) |
51 | { |
52 | if (outputParser) { |
53 | outputParser->takeOutputParserChain(); |
54 | outputParser->appendOutputParser(new NinjaParser()); |
55 | } |
56 | } |
57 | |
58 | |
59 | bool NinjaBuilderGenerator::checkCommandValidity(const BuildCommandInfo &info, QString &retMsg) |
60 | { |
61 | if (info.program.trimmed().isEmpty()) { |
62 | retMsg = tr("The build command of %1 project is null! "\ |
63 | "please install it in console with \"sudo apt install ninja-build\", and then restart the tool.") |
64 | .arg(info.kitName.toUpper()); |
65 | return false; |
66 | } |
67 | |
68 | if (!QFileInfo(info.workingDir.trimmed()).exists()) { |
69 | retMsg = tr("The path of \"%1\" is not exist! "\ |
70 | "please check and reopen the project.") |
71 | .arg(info.workingDir); |
72 | return false; |
73 | } |
74 | |
75 | return true; |
76 | } |
77 | |
78 |