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