@@ -441,7 +441,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
441441 bool def = false ;
442442 bool maxconfigs = false ;
443443
444+ ImportProject::Type projectType = ImportProject::Type::NONE;
444445 ImportProject project;
446+ std::string vsConfig;
445447
446448 bool executorAuto = true ;
447449
@@ -1160,17 +1162,16 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11601162
11611163 // --project
11621164 else if (std::strncmp (argv[i], " --project=" , 10 ) == 0 ) {
1163- if (project. projectType != ImportProject::Type::NONE)
1165+ if (projectType != ImportProject::Type::NONE)
11641166 {
11651167 mLogger .printError (" multiple --project options are not supported." );
11661168 return Result::Fail;
11671169 }
11681170
11691171 mSettings .checkAllConfigurations = false ; // Can be overridden with --max-configs or --force
11701172 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) {
11741175 for (const std::string &lib : project.guiProject .libraries )
11751176 mSettings .libraries .emplace_back (lib);
11761177
@@ -1193,38 +1194,43 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11931194 if (!projectFileGui.empty ()) {
11941195 // read underlying project
11951196 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) {
11981199 mLogger .printError (" nested Cppcheck GUI projects are not supported." );
11991200 return Result::Fail;
12001201 }
12011202 }
12021203 }
1203- if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
1204+ if (projectType == ImportProject::Type::VS_SLN || projectType == ImportProject::Type::VS_VCXPROJ) {
12041205 if (project.guiProject .analyzeAllVsConfigs == " false" )
12051206 project.selectOneVsConfig (mSettings .platform .type );
12061207 mSettings .libraries .emplace_back (" windows" );
12071208 }
1208- if (projType == ImportProject::Type::MISSING) {
1209+ if (projectType == ImportProject::Type::MISSING) {
12091210 mLogger .printError (" failed to open project '" + projectFile + " '. The file does not exist." );
12101211 return Result::Fail;
12111212 }
1212- if (projType == ImportProject::Type::UNKNOWN) {
1213+ if (projectType == ImportProject::Type::UNKNOWN) {
12131214 mLogger .printError (" failed to load project '" + projectFile + " '. The format is unknown." );
12141215 return Result::Fail;
12151216 }
1216- if (projType == ImportProject::Type::FAILURE) {
1217+ if (projectType == ImportProject::Type::FAILURE) {
12171218 mLogger .printError (" failed to load project '" + projectFile + " '. An error occurred." );
12181219 return Result::Fail;
12191220 }
12201221 }
12211222
12221223 // --project-configuration
12231224 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+ }
12281234 }
12291235
12301236 // Only print something when there are errors
@@ -1594,11 +1600,15 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15941600 // mLogger.printMessage("whole program analysis requires --cppcheck-build-dir to be active with -j.");
15951601 }
15961602
1597- if (!mPathNames .empty () && project. projectType != ImportProject::Type::NONE) {
1603+ if (!mPathNames .empty () && projectType != ImportProject::Type::NONE) {
15981604 mLogger .printError (" --project cannot be used in conjunction with source files." );
15991605 return Result::Fail;
16001606 }
16011607
1608+ if (!vsConfig.empty ()) {
1609+ project.ignoreOtherConfigs (vsConfig);
1610+ }
1611+
16021612 if (!mSettings .buildDir .empty () && !Path::isDirectory (mSettings .buildDir )) {
16031613 mLogger .printError (" Directory '" + mSettings .buildDir + " ' specified by --cppcheck-build-dir argument has to be existent." );
16041614 return Result::Fail;
0 commit comments