Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit c6a51f5

Browse files
committed
support for waved repkg runs and sort rebuilds
1 parent 396964d commit c6a51f5

8 files changed

Lines changed: 101 additions & 38 deletions

File tree

clicontroller.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ void CliController::run()
5252
clear(args);
5353
else if(_parser->enterContext(QStringLiteral("frontend"))) {
5454
testEmpty(args);
55-
if(_parser->isSet(QStringLiteral("set")))
56-
setFrontend(_parser->value(QStringLiteral("set")).split(QLatin1Char(' ')));
57-
else
55+
if(_parser->isSet(QStringLiteral("set"))) {
56+
setFrontend(_parser->value(QStringLiteral("set")).split(QLatin1Char(' ')),
57+
_parser->isSet(QStringLiteral("waved")));
58+
} else
5859
frontend();
5960
} else
6061
throw QStringLiteral("Invalid arguments");
@@ -106,6 +107,11 @@ void CliController::setup()
106107
{QStringLiteral("s"), QStringLiteral("short")},
107108
QStringLiteral("Only display the package names, not the path to the rule file.")
108109
});
110+
rulesNode->addOption({
111+
QStringLiteral("waved"),
112+
QStringLiteral("Instead of passing all packages at once, split the into waves to avoid multiple "
113+
"rebuilds for frontends that do not support orderd parameters.")
114+
});
109115

110116

111117
auto clearNode = _parser->addLeafNode(QStringLiteral("clear"),
@@ -124,7 +130,7 @@ void CliController::setup()
124130

125131
void CliController::rebuild()
126132
{
127-
qApp->exit(_runner->run(_resolver->listPkgs()));
133+
qApp->exit(_runner->run(_resolver->listPkgWaves()));
128134
}
129135

130136
void CliController::update(const QStringList &pks)
@@ -173,13 +179,13 @@ void CliController::clear(const QStringList &pkgs)
173179

174180
void CliController::frontend()
175181
{
176-
qInfo().noquote() << _runner->frontend().join(QStringLiteral(" "));
182+
qInfo().noquote() << _runner->frontendDescription();
177183
qApp->quit();
178184
}
179185

180-
void CliController::setFrontend(const QStringList &frontend)
186+
void CliController::setFrontend(const QStringList &frontend, bool waved)
181187
{
182-
_runner->setFrontend(frontend);
188+
_runner->setFrontend(frontend, waved);
183189
qApp->quit();
184190
}
185191

clicontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private slots:
3333
void listRules(bool listShort);
3434
void clear(const QStringList &pkgs);
3535
void frontend();
36-
void setFrontend(const QStringList &frontend);
36+
void setFrontend(const QStringList &frontend, bool waved);
3737

3838
void testEmpty(const QStringList &args);
3939

completitions/bash/repkg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ function _repkg {
3636
optargs="$optargs -s --short"
3737
;;
3838
frontend)
39-
optargs="$optargs -s --set"
39+
optargs="$optargs -s --set --waved"
4040
;;
4141
esac
42-
42+
4343
## find the prefix: check if prefix was in prev list
4444
if _repkg_contains_element $arg $prefix; then
4545
case "$arg" in
@@ -60,7 +60,7 @@ function _repkg {
6060
COMPREPLY=($(compgen -W "$prefix $optargs" -- $cur))
6161
;;
6262
esac
63-
63+
6464

6565
return 0
6666
}

pacmanrunner.cpp

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,46 @@ PacmanRunner::PacmanRunner(QObject *parent) :
1010
QObject(parent)
1111
{}
1212

13-
QStringList PacmanRunner::frontend() const
13+
std::tuple<QStringList, bool> PacmanRunner::frontend() const
1414
{
1515
QSettings settings;
16-
if(settings.contains(QStringLiteral("frontend")))
17-
return settings.value(QStringLiteral("frontend")).toStringList();
18-
else {
19-
QList<QStringList> defaultFn = {
20-
{QStringLiteral("trizen")},
21-
{QStringLiteral("pacaur"), QStringLiteral("--rebuild")},
22-
{QStringLiteral("yaourt")}
16+
if(settings.contains(QStringLiteral("frontend"))) {
17+
return std::make_tuple(settings.value(QStringLiteral("frontend")).toStringList(),
18+
settings.value(QStringLiteral("frontend/waved"), false).toBool());
19+
} else {
20+
static const QList<std::tuple<QStringList, bool>> defaultFn = {
21+
std::make_tuple(QStringList{QStringLiteral("trizen")}, false),
22+
std::make_tuple(QStringList{QStringLiteral("pacaur"), QStringLiteral("--rebuild")}, false),
23+
std::make_tuple(QStringList{QStringLiteral("yaourt")}, true)
2324
};
2425
for(auto fn : defaultFn) {
25-
if(!QStandardPaths::findExecutable(fn.first()).isNull())
26+
if(!QStandardPaths::findExecutable(std::get<0>(fn).first()).isNull())
2627
return fn;
2728
}
28-
return {QStringLiteral("pacman")};
29+
return std::make_tuple(QStringList{QStringLiteral("pacman")}, true);
2930
}
3031
}
3132

32-
void PacmanRunner::setFrontend(const QStringList &cli)
33+
QString PacmanRunner::frontendDescription() const
34+
{
35+
auto fn = frontend();
36+
return QStringLiteral("%1 (%2)")
37+
.arg(std::get<0>(fn).join(QLatin1Char(' ')))
38+
.arg(std::get<1>(fn) ? QStringLiteral("waved") : QStringLiteral("grouped"));
39+
}
40+
41+
void PacmanRunner::setFrontend(const QStringList &cli, bool waved)
3342
{
3443
QSettings settings;
3544
settings.setValue(QStringLiteral("frontend"), cli);
36-
qDebug() << "Updated pacman frontend to" << cli.first();
45+
settings.setValue(QStringLiteral("frontend/waved"), waved);
46+
qDebug() << "Updated pacman frontend to" << cli.first()
47+
<< (waved ? "(waved)" : "(sorted)");
3748
}
3849

39-
int PacmanRunner::run(const QStringList &pkgs)
50+
int PacmanRunner::run(const QList<QStringList> &waves)
4051
{
41-
if(pkgs.isEmpty()) {
52+
if(waves.isEmpty()) {
4253
qWarning() << "No packages need to be rebuilt";
4354
return EXIT_SUCCESS;
4455
}
@@ -50,7 +61,8 @@ int PacmanRunner::run(const QStringList &pkgs)
5061
throw QStringLiteral("Unable to find pacman binary in PATH");
5162
proc.setProgram(pacman);
5263
QStringList pacArgs {QStringLiteral("-Qi")};
53-
pacArgs.append(pkgs);
64+
for(auto pkgs : waves)
65+
pacArgs.append(pkgs);
5466
proc.setArguments(pacArgs);
5567
proc.setProcessChannelMode(QProcess::ForwardedErrorChannel);
5668
proc.setStandardOutputFile(QProcess::nullDevice());
@@ -62,11 +74,25 @@ int PacmanRunner::run(const QStringList &pkgs)
6274
throw QStringLiteral("Please remove repkg files of uninstalled packages and mark the unchanged via `repkg clear <pkg>`");
6375

6476
// run the frontend to reinstall packages
65-
auto cliArgs = frontend();
77+
QStringList cliArgs;
78+
bool waved;
79+
std::tie(cliArgs, waved) = frontend();
6680
auto bin = QStandardPaths::findExecutable(cliArgs.takeFirst());
6781
if(bin.isNull())
6882
throw QStringLiteral("Unable to find binary \"%1\" in PATH").arg(bin);
6983
cliArgs.append(QStringLiteral("-S"));
70-
cliArgs.append(pkgs);
71-
return QProcess::execute(bin, cliArgs);
84+
if(waved) {
85+
for(auto pkgs : waves) {
86+
auto args = cliArgs;
87+
args.append(pkgs);
88+
auto res = QProcess::execute(bin, args);
89+
if(res != EXIT_SUCCESS)
90+
return res;
91+
}
92+
return EXIT_SUCCESS;
93+
} else {
94+
for(auto pkgs : waves)
95+
cliArgs.append(pkgs);
96+
return QProcess::execute(bin, cliArgs);
97+
}
7298
}

pacmanrunner.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#ifndef PACMANRUNNER_H
22
#define PACMANRUNNER_H
33

4+
#include <tuple>
45
#include <QObject>
56

67
class PacmanRunner : public QObject
78
{
89
Q_OBJECT
10+
911
public:
1012
explicit PacmanRunner(QObject *parent = nullptr);
1113

12-
QStringList frontend() const;
13-
void setFrontend(const QStringList &cli);
14+
std::tuple<QStringList, bool> frontend() const; //(frontend, waved)
15+
QString frontendDescription() const;
16+
void setFrontend(const QStringList &cli, bool waved);
17+
bool isWaved() const;
1418

15-
int run(const QStringList &pkgs);
19+
int run(const QList<QStringList> &pkgs);
1620

1721
private:
1822
void checkInstalled(const QString &pkg);

pkgresolver.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ PkgResolver::PkgResolver(QObject *parent) :
1616

1717
QStringList PkgResolver::listPkgs() const
1818
{
19-
QStringList pkgs;
20-
for(auto pkg : readPkgs().keys())
21-
pkgs.append(pkg);
22-
return pkgs;
19+
return readPkgs().keys();
2320
}
2421

2522
QString PkgResolver::listDetailPkgs() const
@@ -39,6 +36,34 @@ QString PkgResolver::listDetailPkgs() const
3936
return pkgs.join(QLatin1Char('\n'));
4037
}
4138

39+
QList<QStringList> PkgResolver::listPkgWaves() const
40+
{
41+
auto pkgs = readPkgs();
42+
43+
QList<QStringList> waves;
44+
while(!pkgs.isEmpty()) {
45+
//find all packages that dont have a trigger that needs to be rebuild as well
46+
const auto keys = QSet<QString>::fromList(pkgs.keys());
47+
QStringList wave;
48+
for(auto it = pkgs.begin(); it != pkgs.end();) {
49+
if(keys.intersects(it.value()))
50+
it++; //has a trigger dep, postpone for later
51+
else {
52+
wave.append(it.key());
53+
it = pkgs.erase(it);
54+
}
55+
}
56+
if(wave.isEmpty()) {
57+
throw QStringLiteral("Cyclic dependencies detected! Is within packages: %1")
58+
.arg(keys.toList().join(QLatin1Char(' ')));
59+
}
60+
waves.append(wave);
61+
qDebug() << "Calculated wave:" << wave.join(QLatin1Char(' '));
62+
}
63+
64+
return waves;
65+
}
66+
4267
void PkgResolver::updatePkgs(const QStringList &pkgs, RuleController *rules)
4368
{
4469
if(!isRoot())

pkgresolver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class PkgResolver : public QObject
1515

1616
QStringList listPkgs() const;
1717
QString listDetailPkgs() const;
18+
QList<QStringList> listPkgWaves() const;
1819

1920
void updatePkgs(const QStringList &pkgs, RuleController *rules);
2021
void clear(const QStringList &pkgs);
2122

2223
private:
23-
typedef QMap<QString, QSet<QString>> PkgInfos;
24+
typedef QMap<QString, QSet<QString>> PkgInfos; //package -> triggered by
2425

2526
QSettings *_settings;
2627

repkg.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ SOURCES += main.cpp \
4040
DISTFILES += \
4141
README.md \
4242
repkg.sh \
43-
repkg.hook
43+
repkg.hook \
44+
completitions/bash/repkg
4445

4546
unix {
4647
target.path = $$[QT_INSTALL_BINS]

0 commit comments

Comments
 (0)