Commit 16fe343d authored by Martin Kampas's avatar Martin Kampas

Refactorize project files

Every subproject "mysubproject" of type app or lib now contains three qmake
files:

  mysubproject.pro
  mysubproject.pri
  mysubproject_dependencies.pri

Dependency between two projects is satisfied by calling
include(../path/to/dependee/dependee.pri) inside dependent_dependencies.pri.
mysubproject.pri always includes mysubproject_dependencies.pri - this way
dependencies are gathered transitively.

Every mysubproject.pro starts with defining TARGET and including one of the
templates:

  ssuapplication.pri
  ssulibrary.pri

Settings common to both app and lib type of projects comes from

  ssu_common.pri

For tests, there are derived templates inside tests directory

  tests/testapplication.pri
  tests/testlibrary.pri

Common settings similarly comes from

  tests/tests_common.pri

Source code root is added to INCLUDEPATH and DEPENDPATH so it is possible to
include any header file specifying ints path relatively to source code root.
Since all the libs and apps are part of single source tree, I recommend to
express this fact by #including ssu own headers with "" instead of <>.

  #include "libssu/ssu.h"

Projects outside of ssu source tree will still use #include <ssu.h>

For tests, the "tests" dir is also added to INCLUDEPATH and DEPENDPATH so the
"tests/" path component can/should be omitted inside tests code:

  #include "testutils/process.h"

Building:

I have removed the hardcoded build paths (buildpath.pri). It is still possible
to keep source tree clean of build artefacts -- with shadow build:

mkdir build && cd build && qmake ../ssu.pro -r && make

Note that the output directories for app and lib binaries is still hardcoded
as build/{bin,lib}.

When gcov is to be used, simply build without the shadow build and object
files will be placed next to source files.

Other notes:

I found some CONFIG settings having no effect and removed these. Namely

CONFIG += dll - shared libs are build by default
CONFIG -= app_bundle - Mac OS X specific
CONFIG += console - Windows specific
CONFIG += qtestlib - QT+=testlib should be the prefered way

-maybe I am wrong?

The 'unix' conditional was not used consistently. Similar issue with
$${PREFIX}. As it is not much useful at the moment, I rather removed it.
parent 8cfafdfb
isEmpty(BUILD){
isEmpty(TARGETDIR){
BUILD = $$PWD/build/$$TARGET
} else {
BUILD = $$PWD/build/$$TARGETDIR
}
}
isEmpty(DESTDIR){
DESTDIR = $$BUILD
}
OBJECTS_DIR = $$BUILD
MOC_DIR = $$BUILD
UI_DIR = $$BUILD
UI_HEADERS_DIR = $$BUILD
UI_SOURCES_DIR = $$BUILD
RCC_DIR = $$BUILD
# This definitely needs to be refactorized somehow (the common module{.pro,.pri,_dependencies.pri}
# approach would do a good job here)
LIBS += -L$$PWD/build/libssu
LIBS += -L$$PWD/build/testutils
LD_LIBRARY_PATH = $$PWD/build/libssu:$$PWD/build/testutils
INCLUDEPATH += $$PWD/libssu
include(libssu_dependencies.pri)
LIBS *= -lssu
BUILD = ../build/libssu
HEADERS = ssu.h \
TARGET = ssu
include(../ssulibrary.pri)
# TODO: which headers are public? i.e. to be installed
public_headers = \
ssu.h \
HEADERS = \
$${public_headers} \
ssucoreconfig.h \
ssudeviceinfo.h \
ssulog.h \
ssuvariables.h \
ssusettings.h \
ssurepomanager.h \
../constants.h
SOURCES = ssu.cpp \
SOURCES = \
ssu.cpp \
ssucoreconfig.cpp \
ssudeviceinfo.cpp \
ssulog.cpp \
ssuvariables.cpp \
ssurepomanager.cpp \
ssusettings.cpp
TEMPLATE = lib
TARGET = ssu
CONFIG += dll mobility link_pkgconfig
QT -= gui
CONFIG += mobility link_pkgconfig
QT += network xml
MOBILITY += systeminfo
PKGCONFIG += libsystemd-journal
headers.files = ssu.h
headers.path = /usr/include
unix:target.path = $${PREFIX}/usr/lib
INSTALLS += target headers
install_headers.files = $${public_headers}
ssuconfhack {
DEFINES += SSUCONFHACK
}
!include( ../buildpath.pri ) { error("Unable to find build path specification") }
# no dependencies so far
......@@ -5,6 +5,7 @@
* @date 2012
*/
#include <QtNetwork>
#include <QtXml/QDomDocument>
#include "ssu.h"
......
......@@ -8,15 +8,17 @@
#ifndef _Ssu_H
#define _Ssu_H
#include <QDateTime>
#include <QObject>
#include <QSettings>
#include <QDebug>
#include <QtNetwork>
#include <QtXml/QDomDocument>
#include <ssudeviceinfo.h>
#include "ssudeviceinfo.h"
class QNetworkAccessManager;
class QNetworkReply;
class Ssu: public QObject {
Q_OBJECT
......
......@@ -11,8 +11,8 @@
#include <QObject>
#include <QSettings>
#include <ssusettings.h>
#include <ssu.h>
#include "ssusettings.h"
#include "ssu.h"
#ifndef SSU_CONFIGURATION
/// Path to the main SSU configuration file
......
......@@ -11,7 +11,7 @@
#include <QObject>
#include <QSettings>
#include <ssusettings.h>
#include "ssusettings.h"
class SsuDeviceInfo: public QObject {
Q_OBJECT
......
......@@ -6,6 +6,7 @@
*/
#include <QDeclarativeContext>
#include <QDir>
#include <QGraphicsObject>
#include <QApplication>
......
......@@ -11,7 +11,7 @@
#include <QMainWindow>
#include <QtDeclarative/QDeclarativeView>
#include <ssu.h>
#include "libssu/ssu.h"
namespace Ui {
class RndRegisterUi;
......
TARGET = rndregisterui
include(../ssuapplication.pri)
include(rndregisterui_dependencies.pri)
HEADERS = rndregisterui.h
SOURCES = main.cpp \
rndregisterui.cpp
RESOURCES = resources.qrc
TEMPLATE = app
TARGET = rndregisterui
LIBS += -lssu
CONFIG += qdeclarative-boostable
CONFIG -= app_bundle
QT += core gui declarative network
QT += gui declarative
OTHER_FILES += \
resources/qml/rndregisterui.qml \
resources/qml/RndSsuPage.qml
unix:target.path = $${PREFIX}/usr/bin
desktop.files = rndregisterui.desktop
desktop.path = /usr/share/applications/
INSTALLS += target desktop
!include( ../buildpath.pri ) { error("Unable to find build path specification") }
INSTALLS += desktop
......@@ -9,6 +9,7 @@
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include <QTimer>
#include "rndssucli.h"
int main(int argc, char** argv){
......
......@@ -9,9 +9,9 @@
#include <termios.h>
#include <ssudeviceinfo.h>
#include <ssurepomanager.h>
#include <ssucoreconfig.h>
#include "libssu/ssudeviceinfo.h"
#include "libssu/ssurepomanager.h"
#include "libssu/ssucoreconfig.h"
#include <QDebug>
......
......@@ -10,9 +10,10 @@
#include <QObject>
#include <QSettings>
#include <QStringList>
#include <QDebug>
#include <ssu.h>
#include "libssu/ssu.h"
class RndSsuCli: public QObject {
Q_OBJECT
......
TARGET = ssu
include(../ssuapplication.pri)
include(rndssucli_dependencies.pri)
HEADERS = rndssucli.h
SOURCES = main.cpp \
rndssucli.cpp
#RESOURCES = rndregister.qrc
TEMPLATE = app
TARGET = ssu
TARGETDIR = ssucli
LIBS += -lssu
CONFIG -= app_bundle
CONFIG += console
QT -= gui
QT += network
unix:target.path = $${PREFIX}/usr/bin
INSTALLS += target
!include( ../buildpath.pri ) { error("Unable to find build path specification") }
include(../libssu/libssu.pri)
CONFIG -= gui
INCLUDEPATH *= $$PWD
DEPENDPATH *= $$PWD
# TODO: determine build dir automatically
SSU_BUILD_DIR = $$PWD/build
DESTDIR_BIN = $$SSU_BUILD_DIR/bin
DESTDIR_LIB = $$SSU_BUILD_DIR/lib
LIBS += -L$$DESTDIR_LIB
isEmpty(TARGET):error("TARGET must be set before this file is included")
include(ssu_common.pri)
TEMPLATE = app
DESTDIR = $$DESTDIR_BIN
target.path = /usr/bin
INSTALLS += target
TEMPLATE = app
TARGET = ssuconfperm
include(../ssuapplication.pri)
SOURCES = ssuconfperm.c
HEADERS = ../constants.h
CONFIG -= qt
!include(../buildpath.pri){ error("Unable to find build path configuration")}
unix:target.path = $${PREFIX}/usr/bin
INSTALLS += target
......@@ -12,8 +12,8 @@
#include <QSettings>
#include <QHash>
#include <ssudeviceinfo.h>
#include <ssu.h>
#include "libssu/ssudeviceinfo.h"
#include "libssu/ssu.h"
/*
class Q_CORE_EXPORT SsuKickstarter: public QObject {
......
TARGET = ssuks
include(../ssuapplication.pri)
include(ssuks_dependencies.pri)
HEADERS = ssuks.h \
ssukickstarter.h
SOURCES = ssuks.cpp \
ssukickstarter.cpp
TEMPLATE = app
TARGET = ssuks
LIBS += -lssu
CONFIG -= app_bundle
CONFIG += console
QT -= gui
QT += network
unix:target.path = $${PREFIX}/usr/bin
INSTALLS += target
!include( ../buildpath.pri ) { error("Unable to find build path specification") }
include(../libssu/libssu.pri)
isEmpty(TARGET):error("TARGET must be set before this file is included")
include(ssu_common.pri)
TEMPLATE = lib
DESTDIR = $$DESTDIR_LIB
target.path = /usr/lib
INSTALLS += target
install_headers.path = /usr/include
INSTALLS += install_headers
......@@ -9,6 +9,7 @@
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include <QTimer>
#include "ssuurlresolver.h"
int main(int argc, char** argv){
......
......@@ -5,11 +5,14 @@
* @date 2012
*/
#include "ssuurlresolver.h"
#include <QCoreApplication>
#include <QFileInfo>
#include <QStringList>
#include <systemd/sd-journal.h>
#include "ssuurlresolver.h"
#include "ssulog.h"
#include "libssu/ssulog.h"
SsuUrlResolver::SsuUrlResolver(): QObject(){
QObject::connect(this,SIGNAL(done()),
......
......@@ -11,12 +11,13 @@
#include <QObject>
#include <QSettings>
#include <QDebug>
#include <QEventLoop>
#include <QFile>
#include <iostream>
#include <zypp/PluginFrame.h>
#include <ssu.h>
#include "libssu/ssu.h"
// quick hack for waiting for a signal
class SignalWait: public QObject {
......
TARGET = ssu
include(../ssuapplication.pri)
include(ssuurlresolver_dependencies.pri)
# We do not build a typical application - override defaults from ../ssuapplication.pri
DESTDIR = $$DESTDIR_LIB/zypp/plugins/urlresolver
target.path = /usr/lib/zypp/plugins/urlresolver
HEADERS = ssuurlresolver.h
SOURCES = main.cpp \
ssuurlresolver.cpp
TEMPLATE = app
TARGET = ssu
LIBS += -lssu
CONFIG -= app_bundle
CONFIG += console link_pkgconfig
QT -= gui
QT += network
PKGCONFIG += libzypp libsystemd-journal
unix:target.path = $${PREFIX}/usr/lib/zypp/plugins/urlresolver
INSTALLS += target
!include( ../buildpath.pri ) { error("Unable to find build path specification") }
CONFIG += link_pkgconfig
PKGCONFIG += libzypp libsystemd-journal
include(../ssuapplication.pri)
include(tests_common.pri)
QT += testlib
test_data_etc.path = $${TESTS_DATA_PATH}/configroot/etc/ssu
test_data_usr_share.path = $${TESTS_DATA_PATH}/configroot/usr/share/ssu
INSTALLS += test_data_etc test_data_usr_share
include(../ssulibrary.pri)
include(tests_common.pri)
TEMPLATE = subdirs
CONFIG += qt ordered coverage debug
CONFIG += ordered coverage debug
SUBDIRS = \
testutils \
testutils/sandboxhook.pro \
......@@ -9,8 +9,7 @@ SUBDIRS = \
ut_urlresolver \
ut_variables \
!include( tests.pri ) { error("Unable to find tests include") }
include(tests_common.pri)
tests.files = tests.xml
tests.path = $$TESTS_PATH
INSTALLS += tests
DEPENDPATH *= $${PWD}/testutils
isEmpty(TARGET):error("TARGET must be defined before this file is included")
INCLUDEPATH *= $${PWD}
DEPENDPATH *= $${PWD}
TESTS_PATH = /opt/tests/ssu
DEFINES += TESTS_PATH="'\"$${TESTS_PATH}\"'"
isEmpty(TARGET):error("TARGET must be defined before this file is included")
TESTS_DATA_PATH = /opt/tests/ssu/data/$${TARGET}
DEFINES += TESTS_DATA_PATH="'\"$${TESTS_DATA_PATH}\"'"
target.path = $${TESTS_PATH}
......@@ -13,8 +13,9 @@
#include <QtCore/QProcessEnvironment>
#include <QtCore/QSet>
#include <ssucoreconfig.h>
#include "../../constants.h"
#include "libssu/ssucoreconfig.h"
// TODO: rename to ssuconstants.h?
#include "constants.h"
/**
* @class SandboxFileEngineHandler
......
SOURCES = sandboxhook.cpp
TEMPLATE = lib
TARGET = sandboxhook
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
LIBS += -ltestutils
include(../testlibrary.pri)
include(sandboxhook_dependencies.pri)
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target
!include( ../../buildpath.pri ) { error("Unable to find build path specification") }
SOURCES = sandboxhook.cpp
include(../testutils/testutils.pri)
include(testutils_dependencies.pri)
LIBS *= -lssu-testutils
TARGET = ssu-testutils
include(../testlibrary.pri)
HEADERS = \
process.h \
sandboxfileenginehandler.h \
......@@ -6,22 +9,6 @@ SOURCES = \
process.cpp \
sandboxfileenginehandler.cpp \
TEMPLATE = lib
TARGET = testutils
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
LIBS += -lssu
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target
exec_wrapper.path = $${PREFIX}/$$TESTS_PATH
exec_wrapper.files = $${PWD}/runtest.sh
exec_wrapper.path = $$TESTS_PATH
exec_wrapper.files = runtest.sh
INSTALLS += exec_wrapper
!include( ../../buildpath.pri ) { error("Unable to find build path specification") }
include(../../libssu/libssu.pri)
......@@ -12,7 +12,7 @@
#include <QtTest/QtTest>
#include "../testutils/process.h"
#include "testutils/process.h"
typedef QStringList Args; // improve readability
......
TARGET = ut_rndssucli
include(../testapplication.pri)
include(ut_rndssucli_dependencies.pri)
HEADERS = \
rndssuclitest.h \
......@@ -5,33 +9,10 @@ SOURCES = \
main.cpp \
rndssuclitest.cpp \
TEMPLATE = app
TARGET = ut_rndssucli
LIBS += \
-lssu \
-ltestutils \
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target
test_data_etc.path = $${TESTS_DATA_PATH}/configroot/etc/ssu
test_data_etc.files = \
$${PWD}/testdata/ssu.ini \
testdata/ssu.ini \
test_data_usr_share.path = $${TESTS_DATA_PATH}/configroot/usr/share/ssu
test_data_usr_share.files = \
$${PWD}/testdata/ssu-defaults.ini \
$${PWD}/testdata/repos.ini \
$${PWD}/testdata/board-mappings.ini \
INSTALLS += test_data_etc test_data_usr_share
!include( ../../buildpath.pri ) { error("Unable to find build path specification") }
testdata/ssu-defaults.ini \
testdata/repos.ini \
testdata/board-mappings.ini \
include(../../libssu/libssu.pri)
include(../testutils/testutils.pri)
......@@ -9,8 +9,7 @@
#include <QtTest/QtTest>
#include <ssusettings.h>
#include "libssu/ssusettings.h"
#include "upgradetesthelper.h"
void SettingsTest::initTestCase(){
......
......@@ -13,7 +13,7 @@
#include <QtCore/QTemporaryFile>
#include <QtCore/QTextStream>
#include <ssusettings.h>
#include "libssu/ssusettings.h"
/**
* @class UpgradeTestHelper
......
TARGET = ut_settings
include(../testapplication.pri)
include(ut_settings_dependencies.pri)
HEADERS = \
settingstest.h \
upgradetesthelper.h \
......@@ -8,25 +12,11 @@ SOURCES = \
upgradetesthelper.cpp \
RESOURCES = testdata.qrc
TEMPLATE = app
TARGET = ut_settings
LIBS += -lssu
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target
!include( ../../buildpath.pri ) { error("Unable to find build path specification") }
update_upgrade_test_recipe.target = update-upgrade-test-recipe
update_upgrade_test_recipe.depends = first
update_upgrade_test_recipe.commands = \
LD_LIBRARY_PATH="$${LD_LIBRARY_PATH}:${LD_LIBRARY_PATH}" \
LD_LIBRARY_PATH="$${DESTDIR_LIB}:${LD_LIBRARY_PATH}" \
$${DESTDIR}/$${TARGET} -generate-upgrade-test-recipe \
2>/dev/null > $${PWD}/testdata/upgrade/recipe
update_upgrade_test_recipe.CONFIG += phony
......
include(../../libssu/libssu.pri)
include(../testutils/testutils.pri)
TARGET = ut_ssuurlresolver
include(../testapplication.pri)
include(ut_ssuurlresolver_dependencies.pri)
CONFIG += link_pkgconfig
PKGCONFIG += libzypp
HEADERS = \
ssuurlresolvertest.h \
......@@ -5,33 +12,10 @@ SOURCES = \
main.cpp \
ssuurlresolvertest.cpp \
TEMPLATE = app
TARGET = ut_ssuurlresolver
LIBS += \
-lssu \
-lzypp \
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target
test_data_etc.path = $${TESTS_DATA_PATH}/configroot/etc/ssu
test_data_etc.files = \
$${PWD}/testdata/ssu.ini \
testdata/ssu.ini \
test_data_usr_share.path = $${TESTS_DATA_PATH}/configroot/usr/share/ssu
test_data_usr_share.files = \
$${PWD}/testdata/ssu-defaults.ini \
$${PWD}/testdata/repos.ini \
$${PWD}/testdata/board-mappings.ini \
INSTALLS += test_data_etc test_data_usr_share
!include( ../../buildpath.pri ) { error("Unable to find build path specification") }
testdata/ssu-defaults.ini \
testdata/repos.ini \
testdata/board-mappings.ini \
......@@ -7,7 +7,7 @@
#include <QtTest/QtTest>
#include "../testutils/sandboxfileenginehandler.h"
#include "testutils/sandboxfileenginehandler.h"
#include "urlresolvertest.cpp"
int main(int argc, char **argv){
......
......@@ -12,7 +12,7 @@
#include <QtTest/QtTest>
#include <QHash>
#include <ssu.h>
#include "libssu/ssu.h"
class UrlResolverTest: public QObject {
Q_OBJECT
......
TARGET = ut_urlresolver
include(../testapplication.pri)
include(ut_urlresolver_dependencies.pri)
HEADERS = urlresolvertest.h
SOURCES = main.cpp \
urlresolvertest.cpp
TEMPLATE = app
TARGET = ut_urlresolver
LIBS += -lssu -ltestutils
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target