@@ -441,7 +441,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
441
441
bool def = false ;
442
442
bool maxconfigs = false ;
443
443
444
+ ImportProject::Type projectType = ImportProject::Type::NONE;
444
445
ImportProject project;
446
+ std::string vsConfig;
445
447
446
448
bool executorAuto = true ;
447
449
@@ -1160,17 +1162,16 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
1160
1162
1161
1163
// --project
1162
1164
else if (std::strncmp (argv[i], " --project=" , 10 ) == 0 ) {
1163
- if (project. projectType != ImportProject::Type::NONE)
1165
+ if (projectType != ImportProject::Type::NONE)
1164
1166
{
1165
1167
mLogger .printError (" multiple --project options are not supported." );
1166
1168
return Result::Fail;
1167
1169
}
1168
1170
1169
1171
mSettings .checkAllConfigurations = false ; // Can be overridden with --max-configs or --force
1170
1172
std::string projectFile = argv[i]+10 ;
1171
- ImportProject::Type projType = project.import (projectFile, &mSettings , &mSuppressions );
1172
- project.projectType = projType;
1173
- if (projType == ImportProject::Type::CPPCHECK_GUI) {
1173
+ projectType = project.import (projectFile, &mSettings , &mSuppressions );
1174
+ if (projectType == ImportProject::Type::CPPCHECK_GUI) {
1174
1175
for (const std::string &lib : project.guiProject .libraries )
1175
1176
mSettings .libraries .emplace_back (lib);
1176
1177
@@ -1193,38 +1194,43 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
1193
1194
if (!projectFileGui.empty ()) {
1194
1195
// read underlying project
1195
1196
projectFile = projectFileGui;
1196
- projType = project.import (projectFileGui, &mSettings , &mSuppressions );
1197
- if (projType == ImportProject::Type::CPPCHECK_GUI) {
1197
+ projectType = project.import (projectFileGui, &mSettings , &mSuppressions );
1198
+ if (projectType == ImportProject::Type::CPPCHECK_GUI) {
1198
1199
mLogger .printError (" nested Cppcheck GUI projects are not supported." );
1199
1200
return Result::Fail;
1200
1201
}
1201
1202
}
1202
1203
}
1203
- if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
1204
+ if (projectType == ImportProject::Type::VS_SLN || projectType == ImportProject::Type::VS_VCXPROJ) {
1204
1205
if (project.guiProject .analyzeAllVsConfigs == " false" )
1205
1206
project.selectOneVsConfig (mSettings .platform .type );
1206
1207
mSettings .libraries .emplace_back (" windows" );
1207
1208
}
1208
- if (projType == ImportProject::Type::MISSING) {
1209
+ if (projectType == ImportProject::Type::MISSING) {
1209
1210
mLogger .printError (" failed to open project '" + projectFile + " '. The file does not exist." );
1210
1211
return Result::Fail;
1211
1212
}
1212
- if (projType == ImportProject::Type::UNKNOWN) {
1213
+ if (projectType == ImportProject::Type::UNKNOWN) {
1213
1214
mLogger .printError (" failed to load project '" + projectFile + " '. The format is unknown." );
1214
1215
return Result::Fail;
1215
1216
}
1216
- if (projType == ImportProject::Type::FAILURE) {
1217
+ if (projectType == ImportProject::Type::FAILURE) {
1217
1218
mLogger .printError (" failed to load project '" + projectFile + " '. An error occurred." );
1218
1219
return Result::Fail;
1219
1220
}
1220
1221
}
1221
1222
1222
1223
// --project-configuration
1223
1224
else if (std::strncmp (argv[i], " --project-configuration=" , 24 ) == 0 ) {
1224
- mVSConfig = argv[i] + 24 ;
1225
- // TODO: provide error when this does nothing
1226
- if (!mVSConfig .empty () && (project.projectType == ImportProject::Type::VS_SLN || project.projectType == ImportProject::Type::VS_VCXPROJ))
1227
- project.ignoreOtherConfigs (mVSConfig );
1225
+ vsConfig = argv[i] + 24 ;
1226
+ if (vsConfig.empty ()) {
1227
+ mLogger .printError (" --project-configuration parameter is empty." );
1228
+ return Result::Fail;
1229
+ }
1230
+ if (projectType != ImportProject::Type::VS_SLN && projectType != ImportProject::Type::VS_VCXPROJ) {
1231
+ mLogger .printError (" --project-configuration has no effect - no Visual Studio project provided." );
1232
+ return Result::Fail;
1233
+ }
1228
1234
}
1229
1235
1230
1236
// Only print something when there are errors
@@ -1594,11 +1600,15 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
1594
1600
// mLogger.printMessage("whole program analysis requires --cppcheck-build-dir to be active with -j.");
1595
1601
}
1596
1602
1597
- if (!mPathNames .empty () && project. projectType != ImportProject::Type::NONE) {
1603
+ if (!mPathNames .empty () && projectType != ImportProject::Type::NONE) {
1598
1604
mLogger .printError (" --project cannot be used in conjunction with source files." );
1599
1605
return Result::Fail;
1600
1606
}
1601
1607
1608
+ if (!vsConfig.empty ()) {
1609
+ project.ignoreOtherConfigs (vsConfig);
1610
+ }
1611
+
1602
1612
if (!mSettings .buildDir .empty () && !Path::isDirectory (mSettings .buildDir )) {
1603
1613
mLogger .printError (" Directory '" + mSettings .buildDir + " ' specified by --cppcheck-build-dir argument has to be existent." );
1604
1614
return Result::Fail;
0 commit comments