Merge remote-tracking branch 'origin/3.4'

This commit is contained in:
Eike Ziller
2015-04-23 09:38:36 +02:00
12 changed files with 163 additions and 15 deletions

View File

@@ -64,7 +64,13 @@ QtcPlugin {
"clangstaticanalyzerunittests.cpp",
"clangstaticanalyzerunittests.h",
"clangstaticanalyzerunittests.qrc",
"unit-tests/**/*",
]
}
Group {
name: "Unit test resources"
prefix: "unit-tests/"
fileTags: []
files: ["**/*"]
}
}

View File

@@ -35,8 +35,10 @@
#include <cpptools/cppprojects.h>
#include <cpptools/cppprojectfile.h>
#include <projectexplorer/abi.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
@@ -61,14 +63,32 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
, m_projectInfo(projectInfo)
, m_toolchainType(ProjectExplorer::ToolChainKitInformation
::toolChain(runConfiguration->target()->kit())->type())
, m_wordWidth(runConfiguration->abi().wordWidth())
, m_initialFilesToProcessSize(0)
, m_filesAnalyzed(0)
, m_filesNotAnalyzed(0)
{
}
// Removes (1) filePath (2) -o <somePath>
static QStringList tweakedArguments(const QString &filePath, const QStringList &arguments)
static void prependWordWidthArgumentIfNotIncluded(QStringList *arguments, unsigned char wordWidth)
{
QTC_ASSERT(arguments, return);
const QString m64Argument = QLatin1String("-m64");
const QString m32Argument = QLatin1String("-m32");
const QString argument = wordWidth == 64 ? m64Argument : m32Argument;
if (!arguments->contains(argument))
arguments->prepend(argument);
QTC_CHECK(!arguments->contains(m32Argument) || !arguments->contains(m64Argument));
}
// Removes (1) filePath (2) -o <somePath>.
// Adds -m64/-m32 argument if not already included.
static QStringList tweakedArguments(const QString &filePath,
const QStringList &arguments,
unsigned char wordWidth)
{
QStringList newArguments;
@@ -88,12 +108,15 @@ static QStringList tweakedArguments(const QString &filePath, const QStringList &
}
QTC_CHECK(skip == false);
prependWordWidthArgumentIfNotIncluded(&newArguments, wordWidth);
return newArguments;
}
static QStringList argumentsFromProjectPart(const CppTools::ProjectPart::Ptr &projectPart,
CppTools::ProjectFile::Kind fileKind,
const QString &toolchainType)
const QString &toolchainType,
unsigned char wordWidth)
{
QStringList result;
@@ -112,16 +135,20 @@ static QStringList argumentsFromProjectPart(const CppTools::ProjectPart::Ptr &pr
projectPart->headerPaths,
CompilerOptionsBuilder::IsBlackListed(),
toolchainType);
if (toolchainType == QLatin1String("msvc"))
result += QLatin1String("/EHsc"); // clang-cl does not understand exceptions
else
result += QLatin1String("-fPIC"); // TODO: Remove?
prependWordWidthArgumentIfNotIncluded(&result, wordWidth);
return result;
}
static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyzeFromCompilerCallData(
const ProjectInfo::CompilerCallData &compilerCallData)
const ProjectInfo::CompilerCallData &compilerCallData,
unsigned char wordWidth)
{
typedef ClangStaticAnalyzerRunControl::AnalyzeUnit AnalyzeUnit;
qCDebug(LOG) << "Taking arguments for analyzing from CompilerCallData.";
@@ -134,7 +161,7 @@ static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyzeFromCompi
const QString file = it.key();
const QList<QStringList> compilerCalls = it.value();
foreach (const QStringList &options, compilerCalls) {
const QStringList arguments = tweakedArguments(file, options);
const QStringList arguments = tweakedArguments(file, options, wordWidth);
unitsToAnalyze << AnalyzeUnit(file, arguments);
}
}
@@ -143,7 +170,9 @@ static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyzeFromCompi
}
static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyzeFromProjectParts(
const QList<ProjectPart::Ptr> projectParts, const QString &toolchainType)
const QList<ProjectPart::Ptr> projectParts,
const QString &toolchainType,
unsigned char wordWidth)
{
typedef ClangStaticAnalyzerRunControl::AnalyzeUnit AnalyzeUnit;
qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts.";
@@ -159,8 +188,10 @@ static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyzeFromProje
continue;
QTC_CHECK(file.kind != ProjectFile::Unclassified);
if (ProjectFile::isSource(file.kind)) {
const QStringList arguments
= argumentsFromProjectPart(projectPart, file.kind, toolchainType);
const QStringList arguments = argumentsFromProjectPart(projectPart,
file.kind,
toolchainType,
wordWidth);
unitsToAnalyze << AnalyzeUnit(file.path, arguments);
}
}
@@ -175,8 +206,10 @@ QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> ClangStaticAnalyzerRunControl:
const ProjectInfo::CompilerCallData compilerCallData = m_projectInfo.compilerCallData();
if (!compilerCallData.isEmpty())
return unitsToAnalyzeFromCompilerCallData(compilerCallData);
return unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(), m_toolchainType);
return unitsToAnalyzeFromCompilerCallData(compilerCallData, m_wordWidth);
return unitsToAnalyzeFromProjectParts(m_projectInfo.projectParts(),
m_toolchainType,
m_wordWidth);
}
bool ClangStaticAnalyzerRunControl::startEngine()

View File

@@ -70,6 +70,7 @@ private:
private:
const CppTools::ProjectInfo m_projectInfo;
const QString m_toolchainType;
const unsigned char m_wordWidth;
QString m_clangExecutable;
QString m_clangLogFileDir;

View File

@@ -70,8 +70,6 @@ RunControl *ClangStaticAnalyzerRunControlFactory::create(RunConfiguration *runCo
RunMode runMode,
QString *errorMessage)
{
Q_UNUSED(runMode);
using namespace CppTools;
const ProjectInfo projectInfoBeforeBuild = m_tool->projectInfoBeforeBuild();
QTC_ASSERT(projectInfoBeforeBuild.isValid(), return 0);

View File

@@ -94,10 +94,16 @@ void ClangStaticAnalyzerUnitTests::testProject_data()
{
QTest::addColumn<QString>("projectFilePath");
QTest::addColumn<int>("expectedDiagCount");
QTest::newRow("qbs project")
QTest::newRow("simple qbs project")
<< QString(m_tmpDir->path() + QLatin1String("/simple/simple.qbs")) << 1;
QTest::newRow("qmake project")
QTest::newRow("simple qmake project")
<< QString(m_tmpDir->path() + QLatin1String("/simple/simple.pro")) << 1;
QTest::newRow("qt-widgets-app qbs project")
<< QString(m_tmpDir->path() + QLatin1String("/qt-widgets-app/qt-widgets-app.qbs")) << 0;
QTest::newRow("qt-widgets-app qmake project")
<< QString(m_tmpDir->path() + QLatin1String("/qt-widgets-app/qt-widgets-app.pro")) << 0;
}
} // namespace Internal

View File

@@ -3,5 +3,11 @@
<file>unit-tests/simple/main.cpp</file>
<file>unit-tests/simple/simple.qbs</file>
<file>unit-tests/simple/simple.pro</file>
<file>unit-tests/qt-widgets-app/main.cpp</file>
<file>unit-tests/qt-widgets-app/mainwindow.cpp</file>
<file>unit-tests/qt-widgets-app/mainwindow.h</file>
<file>unit-tests/qt-widgets-app/mainwindow.ui</file>
<file>unit-tests/qt-widgets-app/qt-widgets-app.pro</file>
<file>unit-tests/qt-widgets-app/qt-widgets-app.qbs</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@@ -0,0 +1,14 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}

View File

@@ -0,0 +1,24 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@@ -0,0 +1,24 @@
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>MainWindow</string>
</property>
<widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,8 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qt-widgets-app
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui

View File

@@ -0,0 +1,17 @@
import qbs 1.0
QtApplication {
name : "Qt Widgets Application"
Depends {
name: "Qt"
submodules: [ "widgets" ]
}
files : [
"main.cpp",
"mainwindow.cpp",
"mainwindow.h",
"mainwindow.ui"
]
}