Fixed #9464 (Import compile database; only check given configuration)
This commit is contained in:
parent
16e8016259
commit
81fff2edf1
|
@ -547,6 +547,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// --project
|
// --project
|
||||||
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
|
||||||
|
mSettings->checkAllConfigurations = false; // Can be overriden with --max-configs or --force
|
||||||
const std::string projectFile = argv[i]+10;
|
const std::string projectFile = argv[i]+10;
|
||||||
ImportProject::Type projType = mSettings->project.import(projectFile, mSettings);
|
ImportProject::Type projType = mSettings->project.import(projectFile, mSettings);
|
||||||
if (projType == ImportProject::Type::CPPCHECK_GUI) {
|
if (projType == ImportProject::Type::CPPCHECK_GUI) {
|
||||||
|
@ -899,6 +900,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
mSettings->project.ignorePaths(mIgnoredPaths);
|
mSettings->project.ignorePaths(mIgnoredPaths);
|
||||||
|
|
||||||
|
if (mSettings->force || maxconfigs)
|
||||||
|
mSettings->checkAllConfigurations = true;
|
||||||
|
|
||||||
if (mSettings->force)
|
if (mSettings->force)
|
||||||
mSettings->maxConfigs = ~0U;
|
mSettings->maxConfigs = ~0U;
|
||||||
|
|
||||||
|
|
|
@ -857,6 +857,10 @@ Settings MainWindow::getCppcheckSettings()
|
||||||
if (!defines.isEmpty())
|
if (!defines.isEmpty())
|
||||||
result.maxConfigs = 1;
|
result.maxConfigs = 1;
|
||||||
|
|
||||||
|
// If importing a project, only check the given configuration
|
||||||
|
if (!mProjectFile->getImportProject().isEmpty())
|
||||||
|
result.checkAllConfigurations = false;
|
||||||
|
|
||||||
const QString &buildDir = mProjectFile->getBuildDir();
|
const QString &buildDir = mProjectFile->getBuildDir();
|
||||||
if (!buildDir.isEmpty()) {
|
if (!buildDir.isEmpty()) {
|
||||||
if (QDir(buildDir).isAbsolute()) {
|
if (QDir(buildDir).isAbsolute()) {
|
||||||
|
|
|
@ -386,7 +386,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
preprocessor.setPlatformInfo(&tokens1);
|
preprocessor.setPlatformInfo(&tokens1);
|
||||||
|
|
||||||
// Get configurations..
|
// Get configurations..
|
||||||
if (mSettings.userDefines.empty() || mSettings.force) {
|
if ((mSettings.checkAllConfigurations && mSettings.userDefines.empty()) || mSettings.force) {
|
||||||
Timer t("Preprocessor::getConfigs", mSettings.showtime, &S_timerResults);
|
Timer t("Preprocessor::getConfigs", mSettings.showtime, &S_timerResults);
|
||||||
configurations = preprocessor.getConfigs(tokens1);
|
configurations = preprocessor.getConfigs(tokens1);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -52,6 +52,7 @@ Settings::Settings()
|
||||||
jointSuppressionReport(false),
|
jointSuppressionReport(false),
|
||||||
loadAverage(0),
|
loadAverage(0),
|
||||||
maxConfigs(12),
|
maxConfigs(12),
|
||||||
|
checkAllConfigurations(true),
|
||||||
maxCtuDepth(2),
|
maxCtuDepth(2),
|
||||||
preprocessOnly(false),
|
preprocessOnly(false),
|
||||||
quiet(false),
|
quiet(false),
|
||||||
|
|
|
@ -220,6 +220,9 @@ public:
|
||||||
Default is 12. (--max-configs=N) */
|
Default is 12. (--max-configs=N) */
|
||||||
unsigned int maxConfigs;
|
unsigned int maxConfigs;
|
||||||
|
|
||||||
|
/** @brief --check all configurations */
|
||||||
|
bool checkAllConfigurations;
|
||||||
|
|
||||||
/** @brief --max-ctu-depth */
|
/** @brief --max-ctu-depth */
|
||||||
int maxCtuDepth;
|
int maxCtuDepth;
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,6 @@ int main() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SOME_CONFIG
|
||||||
|
void foo();
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
x = 3 / 0;
|
x = 3 / 0;
|
||||||
|
#ifdef AAA
|
||||||
|
void aa;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -38,14 +38,12 @@ def test_relative_path():
|
||||||
ret, stdout, stderr = cppcheck(['--template=cppcheck1', 'helloworld'])
|
ret, stdout, stderr = cppcheck(['--template=cppcheck1', 'helloworld'])
|
||||||
filename = os.path.join('helloworld', 'main.c')
|
filename = os.path.join('helloworld', 'main.c')
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking %s ...\n' % (filename)
|
|
||||||
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
|
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
|
||||||
|
|
||||||
|
|
||||||
def test_local_path():
|
def test_local_path():
|
||||||
ret, stdout, stderr = cppcheck_local(['--template=cppcheck1', '.'])
|
ret, stdout, stderr = cppcheck_local(['--template=cppcheck1', '.'])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking main.c ...\n'
|
|
||||||
assert stderr == '[main.c:5]: (error) Division by zero.\n'
|
assert stderr == '[main.c:5]: (error) Division by zero.\n'
|
||||||
|
|
||||||
def test_absolute_path():
|
def test_absolute_path():
|
||||||
|
@ -53,13 +51,11 @@ def test_absolute_path():
|
||||||
ret, stdout, stderr = cppcheck(['--template=cppcheck1', prjpath])
|
ret, stdout, stderr = cppcheck(['--template=cppcheck1', prjpath])
|
||||||
filename = os.path.join(prjpath, 'main.c')
|
filename = os.path.join(prjpath, 'main.c')
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking %s ...\n' % (filename)
|
|
||||||
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
|
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
|
||||||
|
|
||||||
def test_addon_local_path():
|
def test_addon_local_path():
|
||||||
ret, stdout, stderr = cppcheck_local(['--addon=misra', '--template=cppcheck1', '.'])
|
ret, stdout, stderr = cppcheck_local(['--addon=misra', '--template=cppcheck1', '.'])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking main.c ...\n'
|
|
||||||
assert stderr == ('[main.c:5]: (error) Division by zero.\n'
|
assert stderr == ('[main.c:5]: (error) Division by zero.\n'
|
||||||
'[main.c:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n')
|
'[main.c:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n')
|
||||||
|
|
||||||
|
@ -68,7 +64,6 @@ def test_addon_absolute_path():
|
||||||
ret, stdout, stderr = cppcheck(['--addon=misra', '--template=cppcheck1', prjpath])
|
ret, stdout, stderr = cppcheck(['--addon=misra', '--template=cppcheck1', prjpath])
|
||||||
filename = os.path.join(prjpath, 'main.c')
|
filename = os.path.join(prjpath, 'main.c')
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking %s ...\n' % (filename)
|
|
||||||
assert stderr == ('[%s:5]: (error) Division by zero.\n'
|
assert stderr == ('[%s:5]: (error) Division by zero.\n'
|
||||||
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
|
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
|
||||||
|
|
||||||
|
@ -96,7 +91,6 @@ def test_basepath_relative_path():
|
||||||
ret, stdout, stderr = cppcheck([prjpath, '--template=cppcheck1', '-rp=' + prjpath])
|
ret, stdout, stderr = cppcheck([prjpath, '--template=cppcheck1', '-rp=' + prjpath])
|
||||||
filename = os.path.join(prjpath, 'main.c')
|
filename = os.path.join(prjpath, 'main.c')
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking %s ...\n' % (filename)
|
|
||||||
assert stderr == '[main.c:5]: (error) Division by zero.\n'
|
assert stderr == '[main.c:5]: (error) Division by zero.\n'
|
||||||
|
|
||||||
def test_basepath_absolute_path():
|
def test_basepath_absolute_path():
|
||||||
|
@ -104,7 +98,6 @@ def test_basepath_absolute_path():
|
||||||
ret, stdout, stderr = cppcheck(['--template=cppcheck1', prjpath, '-rp=' + prjpath])
|
ret, stdout, stderr = cppcheck(['--template=cppcheck1', prjpath, '-rp=' + prjpath])
|
||||||
filename = os.path.join(prjpath, 'main.c')
|
filename = os.path.join(prjpath, 'main.c')
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert stdout == 'Checking %s ...\n' % (filename)
|
|
||||||
assert stderr == '[main.c:5]: (error) Division by zero.\n'
|
assert stderr == '[main.c:5]: (error) Division by zero.\n'
|
||||||
|
|
||||||
def test_vs_project_local_path():
|
def test_vs_project_local_path():
|
||||||
|
|
|
@ -40,6 +40,24 @@ def test_local_path():
|
||||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||||
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
||||||
|
|
||||||
|
def test_local_path_force():
|
||||||
|
create_compile_commands()
|
||||||
|
ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json', '--force'])
|
||||||
|
cwd = os.getcwd()
|
||||||
|
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||||
|
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||||
|
assert ret == 0
|
||||||
|
assert stdout.find('AAA') >= 0
|
||||||
|
|
||||||
|
def test_local_path_maxconfigs():
|
||||||
|
create_compile_commands()
|
||||||
|
ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json', '--max-configs=2'])
|
||||||
|
cwd = os.getcwd()
|
||||||
|
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||||
|
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||||
|
assert ret == 0
|
||||||
|
assert stdout.find('AAA') >= 0
|
||||||
|
|
||||||
def test_relative_path():
|
def test_relative_path():
|
||||||
create_compile_commands()
|
create_compile_commands()
|
||||||
ret, stdout, stderr = cppcheck(['--project=' + COMPILE_COMMANDS_JSON])
|
ret, stdout, stderr = cppcheck(['--project=' + COMPILE_COMMANDS_JSON])
|
||||||
|
|
Loading…
Reference in New Issue