Changeset View
Changeset View
Standalone View
Standalone View
plugins/meson/mesonconfig.cpp
Show All 30 Lines | |||||
31 | using namespace Meson; | 31 | using namespace Meson; | ||
32 | 32 | | |||
33 | static const QString ROOT_CONFIG = QStringLiteral("MesonManager"); | 33 | static const QString ROOT_CONFIG = QStringLiteral("MesonManager"); | ||
34 | static const QString NUM_BUILD_DIRS = QStringLiteral("Number of Build Directories"); | 34 | static const QString NUM_BUILD_DIRS = QStringLiteral("Number of Build Directories"); | ||
35 | static const QString CURRENT_INDEX = QStringLiteral("Current Build Directory Index"); | 35 | static const QString CURRENT_INDEX = QStringLiteral("Current Build Directory Index"); | ||
36 | 36 | | |||
37 | static const QString BUILD_DIR_SEC = QStringLiteral("BuildDir %1"); | 37 | static const QString BUILD_DIR_SEC = QStringLiteral("BuildDir %1"); | ||
38 | static const QString BUILD_DIR_PATH = QStringLiteral("Build Directory Path"); | 38 | static const QString BUILD_DIR_PATH = QStringLiteral("Build Directory Path"); | ||
39 | static const QString INSTALL_PREFIX = QStringLiteral("Installation prefix"); | | |||
40 | static const QString MESON_EXE = QStringLiteral("Meson executable"); | 39 | static const QString MESON_EXE = QStringLiteral("Meson executable"); | ||
41 | static const QString EXTRA_ARGS = QStringLiteral("Additional meson arguments"); | 40 | static const QString EXTRA_ARGS = QStringLiteral("Additional meson arguments"); | ||
42 | static const QString BUILD_TYPE = QStringLiteral("Build type"); | | |||
43 | static const QString BACKEND = QStringLiteral("Meson Generator Backend"); | 41 | static const QString BACKEND = QStringLiteral("Meson Generator Backend"); | ||
44 | 42 | | |||
45 | int MesonConfig::addBuildDir(BuildDir dir) | 43 | int MesonConfig::addBuildDir(BuildDir dir) | ||
46 | { | 44 | { | ||
47 | int newIndex = buildDirs.size(); | 45 | int newIndex = buildDirs.size(); | ||
48 | dir.canonicalizePaths(); | 46 | dir.canonicalizePaths(); | ||
49 | qCDebug(KDEV_Meson) << "BuildDirectories::addBuildDir()=" << dir.buildDir; | 47 | qCDebug(KDEV_Meson) << "BuildDirectories::addBuildDir()=" << dir.buildDir; | ||
50 | buildDirs.push_back(dir); | 48 | buildDirs.push_back(dir); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 91 | for (int i = 0; i < numDirs; ++i) { | |||
94 | QString section = BUILD_DIR_SEC.arg(i); | 92 | QString section = BUILD_DIR_SEC.arg(i); | ||
95 | if (!root.hasGroup(section)) { | 93 | if (!root.hasGroup(section)) { | ||
96 | continue; | 94 | continue; | ||
97 | } | 95 | } | ||
98 | 96 | | |||
99 | KConfigGroup current = root.group(section); | 97 | KConfigGroup current = root.group(section); | ||
100 | BuildDir currBD; | 98 | BuildDir currBD; | ||
101 | currBD.buildDir = Path(current.readEntry(BUILD_DIR_PATH, QString())); | 99 | currBD.buildDir = Path(current.readEntry(BUILD_DIR_PATH, QString())); | ||
102 | currBD.installPrefix = Path(current.readEntry(INSTALL_PREFIX, QString())); | | |||
103 | currBD.mesonExecutable = Path(current.readEntry(MESON_EXE, QString())); | 100 | currBD.mesonExecutable = Path(current.readEntry(MESON_EXE, QString())); | ||
104 | currBD.buildType = current.readEntry(BUILD_TYPE, QStringLiteral("debug")); | | |||
105 | currBD.mesonBackend = current.readEntry(BACKEND, QString()); | 101 | currBD.mesonBackend = current.readEntry(BACKEND, QString()); | ||
106 | currBD.mesonArgs = current.readEntry(EXTRA_ARGS, QString()); | 102 | currBD.mesonArgs = current.readEntry(EXTRA_ARGS, QString()); | ||
107 | 103 | | |||
108 | currBD.canonicalizePaths(); | 104 | currBD.canonicalizePaths(); | ||
109 | 105 | | |||
110 | // Try to find meson if the config is bad | 106 | // Try to find meson if the config is bad | ||
111 | if (currBD.mesonExecutable.isEmpty()) { | 107 | if (currBD.mesonExecutable.isEmpty()) { | ||
112 | Q_ASSERT(project); | 108 | Q_ASSERT(project); | ||
Show All 31 Lines | 129 | { | |||
144 | root.writeEntry(NUM_BUILD_DIRS, cfg.buildDirs.size()); | 140 | root.writeEntry(NUM_BUILD_DIRS, cfg.buildDirs.size()); | ||
145 | root.writeEntry(CURRENT_INDEX, currentIndex); | 141 | root.writeEntry(CURRENT_INDEX, currentIndex); | ||
146 | 142 | | |||
147 | int counter = 0; | 143 | int counter = 0; | ||
148 | for (auto const& i : cfg.buildDirs) { | 144 | for (auto const& i : cfg.buildDirs) { | ||
149 | KConfigGroup current = root.group(BUILD_DIR_SEC.arg(counter++)); | 145 | KConfigGroup current = root.group(BUILD_DIR_SEC.arg(counter++)); | ||
150 | 146 | | |||
151 | current.writeEntry(BUILD_DIR_PATH, i.buildDir.path()); | 147 | current.writeEntry(BUILD_DIR_PATH, i.buildDir.path()); | ||
152 | current.writeEntry(INSTALL_PREFIX, i.installPrefix.path()); | | |||
153 | current.writeEntry(MESON_EXE, i.mesonExecutable.path()); | 148 | current.writeEntry(MESON_EXE, i.mesonExecutable.path()); | ||
154 | current.writeEntry(BUILD_TYPE, i.buildType); | | |||
155 | current.writeEntry(BACKEND, i.mesonBackend); | 149 | current.writeEntry(BACKEND, i.mesonBackend); | ||
156 | current.writeEntry(EXTRA_ARGS, i.mesonArgs); | 150 | current.writeEntry(EXTRA_ARGS, i.mesonArgs); | ||
157 | } | 151 | } | ||
158 | } | 152 | } | ||
159 | 153 | | |||
160 | BuildDir Meson::currentBuildDir(IProject* project) | 154 | BuildDir Meson::currentBuildDir(IProject* project) | ||
161 | { | 155 | { | ||
162 | Q_ASSERT(project); | 156 | Q_ASSERT(project); | ||
Show All 16 Lines | 158 | if (cfg.currentIndex < 0 || cfg.currentIndex >= cfg.buildDirs.size()) { | |||
179 | } | 173 | } | ||
180 | } | 174 | } | ||
181 | 175 | | |||
182 | return cfg.buildDirs[cfg.currentIndex]; | 176 | return cfg.buildDirs[cfg.currentIndex]; | ||
183 | } | 177 | } | ||
184 | 178 | | |||
185 | bool Meson::BuildDir::isValid() const | 179 | bool Meson::BuildDir::isValid() const | ||
186 | { | 180 | { | ||
187 | return !(buildDir.isEmpty() || mesonExecutable.isEmpty() || buildType.isEmpty()); | 181 | return !(buildDir.isEmpty() || mesonExecutable.isEmpty()); | ||
188 | } | 182 | } | ||
189 | 183 | | |||
190 | void Meson::BuildDir::canonicalizePaths() | 184 | void Meson::BuildDir::canonicalizePaths() | ||
191 | { | 185 | { | ||
192 | for (auto* i : { &buildDir, &installPrefix, &mesonExecutable }) { | 186 | for (auto* i : { &buildDir, &mesonExecutable }) { | ||
193 | *i = Path(QFileInfo(i->toLocalFile()).canonicalFilePath()); | 187 | *i = Path(QFileInfo(i->toLocalFile()).canonicalFilePath()); | ||
194 | } | 188 | } | ||
195 | } | 189 | } |