2016-08-13 10:50:03 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2016-08-13 10:50:03 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifndef importprojectH
|
|
|
|
#define importprojectH
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2016-12-06 20:02:43 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "platform.h"
|
2017-09-30 11:25:46 +02:00
|
|
|
#include "utils.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
|
2022-01-27 19:03:20 +01:00
|
|
|
#include <iosfwd>
|
2016-08-13 10:50:03 +02:00
|
|
|
#include <list>
|
2016-11-11 16:22:14 +01:00
|
|
|
#include <map>
|
2016-08-13 10:50:03 +02:00
|
|
|
#include <set>
|
2017-05-27 04:33:47 +02:00
|
|
|
#include <string>
|
2016-08-13 10:50:03 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
2017-09-24 22:36:20 +02:00
|
|
|
namespace cppcheck {
|
2017-09-24 22:57:24 +02:00
|
|
|
struct stricmp {
|
|
|
|
bool operator()(const std::string &lhs, const std::string &rhs) const {
|
2017-09-30 11:25:46 +02:00
|
|
|
return caseInsensitiveStringCompare(lhs,rhs) < 0;
|
2017-09-24 22:36:20 +02:00
|
|
|
}
|
2017-09-24 22:57:24 +02:00
|
|
|
};
|
2017-09-24 22:36:20 +02:00
|
|
|
}
|
|
|
|
|
2019-01-31 20:40:15 +01:00
|
|
|
class Settings;
|
|
|
|
|
2016-08-13 10:50:03 +02:00
|
|
|
/**
|
|
|
|
* @brief Importing project settings.
|
|
|
|
*/
|
|
|
|
class CPPCHECKLIB ImportProject {
|
|
|
|
public:
|
2019-01-31 20:40:15 +01:00
|
|
|
enum class Type {
|
2023-10-05 21:36:44 +02:00
|
|
|
NONE,
|
2018-07-25 16:26:25 +02:00
|
|
|
UNKNOWN,
|
|
|
|
MISSING,
|
2021-12-19 12:36:11 +01:00
|
|
|
FAILURE,
|
2018-07-25 16:26:25 +02:00
|
|
|
COMPILE_DB,
|
|
|
|
VS_SLN,
|
|
|
|
VS_VCXPROJ,
|
2019-01-31 20:40:15 +01:00
|
|
|
BORLAND,
|
|
|
|
CPPCHECK_GUI
|
2018-07-25 16:26:25 +02:00
|
|
|
};
|
|
|
|
|
2016-08-13 10:50:03 +02:00
|
|
|
/** File settings. Multiple configurations for a file is allowed. */
|
2017-11-11 11:13:18 +01:00
|
|
|
struct CPPCHECKLIB FileSettings {
|
2016-08-13 10:50:03 +02:00
|
|
|
std::string cfg;
|
|
|
|
std::string filename;
|
|
|
|
std::string defines;
|
2017-08-08 22:26:42 +02:00
|
|
|
std::string cppcheckDefines() const {
|
2017-08-08 22:57:11 +02:00
|
|
|
return defines + (msc ? ";_MSC_VER=1900" : "") + (useMfc ? ";__AFXWIN_H__=1" : "");
|
2017-08-08 22:26:42 +02:00
|
|
|
}
|
2016-08-13 10:50:03 +02:00
|
|
|
std::set<std::string> undefs;
|
|
|
|
std::list<std::string> includePaths;
|
2017-08-03 20:38:24 +02:00
|
|
|
std::list<std::string> systemIncludePaths;
|
|
|
|
std::string standard;
|
2023-10-13 16:02:04 +02:00
|
|
|
Platform::Type platformType = Platform::Type::Unspecified;
|
2023-08-08 11:05:02 +02:00
|
|
|
bool msc{};
|
|
|
|
bool useMfc{};
|
2016-08-13 10:50:03 +02:00
|
|
|
|
2023-03-30 07:24:23 +02:00
|
|
|
void parseCommand(const std::string& command);
|
2016-08-13 10:50:03 +02:00
|
|
|
void setDefines(std::string defs);
|
2017-09-24 22:36:20 +02:00
|
|
|
void setIncludePaths(const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string, cppcheck::stricmp> &variables);
|
2016-08-13 10:50:03 +02:00
|
|
|
};
|
|
|
|
std::list<FileSettings> fileSettings;
|
2023-10-05 21:36:44 +02:00
|
|
|
Type projectType{Type::NONE};
|
2020-04-19 18:19:28 +02:00
|
|
|
|
2023-10-05 21:36:44 +02:00
|
|
|
ImportProject() = default;
|
2022-09-29 21:59:02 +02:00
|
|
|
virtual ~ImportProject() = default;
|
2023-03-02 21:02:29 +01:00
|
|
|
ImportProject(const ImportProject&) = default;
|
|
|
|
ImportProject& operator=(const ImportProject&) = default;
|
2016-08-13 10:50:03 +02:00
|
|
|
|
2023-10-13 16:02:04 +02:00
|
|
|
void selectOneVsConfig(Platform::Type platform);
|
|
|
|
void selectVsConfigurations(Platform::Type platform, const std::vector<std::string> &configurations);
|
2019-04-13 20:01:40 +02:00
|
|
|
|
2020-01-31 07:08:38 +01:00
|
|
|
std::list<std::string> getVSConfigs();
|
|
|
|
|
2019-01-31 20:40:15 +01:00
|
|
|
// Cppcheck GUI output
|
|
|
|
struct {
|
2019-04-13 20:01:40 +02:00
|
|
|
std::string analyzeAllVsConfigs;
|
2019-01-31 20:40:15 +01:00
|
|
|
std::vector<std::string> pathNames;
|
|
|
|
std::list<std::string> libraries;
|
2019-04-07 12:31:52 +02:00
|
|
|
std::list<std::string> excludedPaths;
|
2020-01-31 07:08:38 +01:00
|
|
|
std::list<std::string> checkVsConfigs;
|
2019-01-31 20:40:15 +01:00
|
|
|
std::string projectFile;
|
|
|
|
std::string platform;
|
|
|
|
} guiProject;
|
|
|
|
|
2016-12-06 20:02:43 +01:00
|
|
|
void ignorePaths(const std::vector<std::string> &ipaths);
|
2016-08-21 15:57:38 +02:00
|
|
|
void ignoreOtherConfigs(const std::string &cfg);
|
2016-08-13 10:50:03 +02:00
|
|
|
|
2019-01-31 23:52:48 +01:00
|
|
|
Type import(const std::string &filename, Settings *settings=nullptr);
|
2017-12-26 13:04:27 +01:00
|
|
|
protected:
|
2021-12-19 12:36:11 +01:00
|
|
|
bool importCompileCommands(std::istream &istr);
|
2019-01-31 20:40:15 +01:00
|
|
|
bool importCppcheckGuiProject(std::istream &istr, Settings *settings);
|
2021-12-19 12:36:11 +01:00
|
|
|
virtual bool sourceFileExists(const std::string &file);
|
2017-12-26 13:04:27 +01:00
|
|
|
private:
|
2021-12-19 12:36:11 +01:00
|
|
|
bool importSln(std::istream &istr, const std::string &path, const std::vector<std::string> &fileFilters);
|
|
|
|
bool importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::vector<std::string> &fileFilters);
|
|
|
|
bool importBcb6Prj(const std::string &projectFilename);
|
|
|
|
|
2022-03-02 07:46:47 +01:00
|
|
|
static void printError(const std::string &message);
|
2019-04-11 18:46:57 +02:00
|
|
|
|
2021-06-12 11:10:35 +02:00
|
|
|
void setRelativePaths(const std::string &filename);
|
|
|
|
|
2019-04-11 18:46:57 +02:00
|
|
|
std::string mPath;
|
2020-01-31 07:08:38 +01:00
|
|
|
std::set<std::string> mAllVSConfigs;
|
2016-08-13 10:50:03 +02:00
|
|
|
};
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
|
|
|
|
namespace CppcheckXml {
|
2023-10-02 20:32:51 +02:00
|
|
|
static constexpr char ProjectElementName[] = "project";
|
|
|
|
static constexpr char ProjectVersionAttrib[] = "version";
|
|
|
|
static constexpr char ProjectFileVersion[] = "1";
|
|
|
|
static constexpr char BuildDirElementName[] = "builddir";
|
|
|
|
static constexpr char ImportProjectElementName[] = "importproject";
|
|
|
|
static constexpr char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
|
|
|
|
static constexpr char Parser[] = "parser";
|
|
|
|
static constexpr char IncludeDirElementName[] = "includedir";
|
|
|
|
static constexpr char DirElementName[] = "dir";
|
|
|
|
static constexpr char DirNameAttrib[] = "name";
|
|
|
|
static constexpr char DefinesElementName[] = "defines";
|
|
|
|
static constexpr char DefineName[] = "define";
|
|
|
|
static constexpr char DefineNameAttrib[] = "name";
|
|
|
|
static constexpr char UndefinesElementName[] = "undefines";
|
|
|
|
static constexpr char UndefineName[] = "undefine";
|
|
|
|
static constexpr char PathsElementName[] = "paths";
|
|
|
|
static constexpr char PathName[] = "dir";
|
|
|
|
static constexpr char PathNameAttrib[] = "name";
|
|
|
|
static constexpr char RootPathName[] = "root";
|
|
|
|
static constexpr char RootPathNameAttrib[] = "name";
|
|
|
|
static constexpr char IgnoreElementName[] = "ignore";
|
|
|
|
static constexpr char IgnorePathName[] = "path";
|
|
|
|
static constexpr char IgnorePathNameAttrib[] = "name";
|
|
|
|
static constexpr char ExcludeElementName[] = "exclude";
|
|
|
|
static constexpr char ExcludePathName[] = "path";
|
|
|
|
static constexpr char ExcludePathNameAttrib[] = "name";
|
|
|
|
static constexpr char FunctionContracts[] = "function-contracts";
|
|
|
|
static constexpr char VariableContractsElementName[] = "variable-contracts";
|
|
|
|
static constexpr char LibrariesElementName[] = "libraries";
|
|
|
|
static constexpr char LibraryElementName[] = "library";
|
|
|
|
static constexpr char PlatformElementName[] = "platform";
|
|
|
|
static constexpr char SuppressionsElementName[] = "suppressions";
|
|
|
|
static constexpr char SuppressionElementName[] = "suppression";
|
|
|
|
static constexpr char AddonElementName[] = "addon";
|
|
|
|
static constexpr char AddonsElementName[] = "addons";
|
|
|
|
static constexpr char ToolElementName[] = "tool";
|
|
|
|
static constexpr char ToolsElementName[] = "tools";
|
|
|
|
static constexpr char TagsElementName[] = "tags";
|
|
|
|
static constexpr char TagElementName[] = "tag";
|
|
|
|
static constexpr char TagWarningsElementName[] = "tag-warnings";
|
|
|
|
static constexpr char TagAttributeName[] = "tag";
|
|
|
|
static constexpr char WarningElementName[] = "warning";
|
|
|
|
static constexpr char HashAttributeName[] = "hash";
|
|
|
|
static constexpr char CheckLevelExhaustiveElementName[] = "check-level-exhaustive";
|
|
|
|
static constexpr char CheckHeadersElementName[] = "check-headers";
|
|
|
|
static constexpr char CheckUnusedTemplatesElementName[] = "check-unused-templates";
|
|
|
|
static constexpr char MaxCtuDepthElementName[] = "max-ctu-depth";
|
|
|
|
static constexpr char MaxTemplateRecursionElementName[] = "max-template-recursion";
|
|
|
|
static constexpr char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values";
|
|
|
|
static constexpr char ClangTidy[] = "clang-tidy";
|
|
|
|
static constexpr char Name[] = "name";
|
|
|
|
static constexpr char VSConfigurationElementName[] = "vs-configurations";
|
|
|
|
static constexpr char VSConfigurationName[] = "config";
|
2022-08-22 21:11:28 +02:00
|
|
|
// Cppcheck Premium
|
2023-10-02 20:32:51 +02:00
|
|
|
static constexpr char BughuntingElementName[] = "bug-hunting";
|
|
|
|
static constexpr char CodingStandardsElementName[] = "coding-standards";
|
|
|
|
static constexpr char CodingStandardElementName[] = "coding-standard";
|
|
|
|
static constexpr char CertIntPrecisionElementName[] = "cert-c-int-precision";
|
|
|
|
static constexpr char ProjectNameElementName[] = "project-name";
|
2019-08-09 21:15:02 +02:00
|
|
|
}
|
|
|
|
|
2016-08-13 10:50:03 +02:00
|
|
|
/// @}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif // importprojectH
|