Skip to content

Commit 0ab1cc6

Browse files
committed
Add github actions
1 parent eb95eaa commit 0ab1cc6

File tree

4 files changed

+122
-66
lines changed

4 files changed

+122
-66
lines changed

.github/workflows/check.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
clang-format:
11+
name: Check clang-format
12+
runs-on: ubuntu-latest
13+
container: archlinux:latest
14+
steps:
15+
- name: Install dependencies
16+
run: |
17+
pacman -Syu --noconfirm git clang diffutils
18+
git config --global --add safe.directory $GITHUB_WORKSPACE
19+
- uses: actions/checkout@v4
20+
- uses: fcitx/github-actions@clang-format
21+
check:
22+
name: Build and test
23+
needs: clang-format
24+
runs-on: ubuntu-latest
25+
container: archlinux:latest
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
compiler: [gcc, clang]
30+
include:
31+
- compiler: gcc
32+
cxx_compiler: g++
33+
- compiler: clang
34+
cxx_compiler: clang++
35+
env:
36+
CC: ${{ matrix.compiler }}
37+
CXX: ${{ matrix.cxx_compiler }}
38+
steps:
39+
- name: Install dependencies
40+
run: |
41+
pacman -Syu --noconfirm base-devel clang cmake ninja extra-cmake-modules qt6-base ktexttemplate
42+
- uses: actions/checkout@v4
43+
- name: Build and Install fcitx5-configtool
44+
uses: fcitx/github-actions@cmake
45+
with:
46+
path: .

src/main.cpp

+34-33
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,47 @@ Q_LOGGING_CATEGORY(generator, "generator");
2121
QtMessageHandler defaultHandler = nullptr;
2222

2323
void logHandler(const QtMsgType type, const QMessageLogContext &context,
24-
const QString &msg) {
25-
defaultHandler(type, context, msg);
26-
if (context.category == QLatin1String("generator") && type == QtCriticalMsg) {
27-
::exit(1);
28-
}
24+
const QString &msg) {
25+
defaultHandler(type, context, msg);
26+
if (context.category == QLatin1String("generator") &&
27+
type == QtCriticalMsg) {
28+
::exit(1);
29+
}
2930
}
3031

3132
int main(int argc, char *argv[]) {
32-
defaultHandler = qInstallMessageHandler(logHandler);
33-
QCoreApplication app(argc, argv);
34-
QCommandLineParser parser;
33+
defaultHandler = qInstallMessageHandler(logHandler);
34+
QCoreApplication app(argc, argv);
35+
QCommandLineParser parser;
3536

36-
parser.addOption(QCommandLineOption(
37-
"includes", "Comma-separated list of extra includes.", "includes"));
38-
parser.addOption(QCommandLineOption(
39-
"namespace", "Namespace for the generated code.", "namespace"));
40-
parser.addOption(
41-
QCommandLineOption("directory", "Output directory.", "directory", "."));
42-
parser.addHelpOption();
43-
parser.addPositionalArgument("files", "Input files.",
44-
"[deps_protocol_file] main_protocol_file");
45-
parser.process(app);
37+
parser.addOption(QCommandLineOption(
38+
"includes", "Comma-separated list of extra includes.", "includes"));
39+
parser.addOption(QCommandLineOption(
40+
"namespace", "Namespace for the generated code.", "namespace"));
41+
parser.addOption(
42+
QCommandLineOption("directory", "Output directory.", "directory", "."));
43+
parser.addHelpOption();
44+
parser.addPositionalArgument("files", "Input files.",
45+
"[deps_protocol_file] main_protocol_file");
46+
parser.process(app);
4647

47-
EmitOptions options;
48-
if (parser.isSet("includes")) {
49-
options.extraIncludes_ = parser.values("includes");
50-
}
51-
if (parser.isSet("namespace")) {
52-
options.namespaces_ = parser.value("namespace").split("::");
53-
}
54-
options.directory_ = parser.value("directory");
48+
EmitOptions options;
49+
if (parser.isSet("includes")) {
50+
options.extraIncludes_ = parser.values("includes");
51+
}
52+
if (parser.isSet("namespace")) {
53+
options.namespaces_ = parser.value("namespace").split("::");
54+
}
55+
options.directory_ = parser.value("directory");
5556

56-
const auto filenames = parser.positionalArguments();
57+
const auto filenames = parser.positionalArguments();
5758

58-
KTextTemplate::registerMetaType<Message>();
59-
KTextTemplate::registerMetaType<Message *>();
60-
KTextTemplate::registerMetaType<Argument>();
59+
KTextTemplate::registerMetaType<Message>();
60+
KTextTemplate::registerMetaType<Message *>();
61+
KTextTemplate::registerMetaType<Argument>();
6162

62-
Protocol protocol(filenames);
63-
protocol.generate(options);
63+
Protocol protocol(filenames);
64+
protocol.generate(options);
6465

65-
return 0;
66+
return 0;
6667
}

src/parser.cpp

+35-23
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include <utility>
2424
#include <QDebug>
2525
#include <QFile>
26+
#include <QLoggingCategory>
27+
#include <QStringView>
2628
#include <QXmlStreamReader>
2729
#include <QtLogging>
2830
#include <qdebug.h>
2931
#include <qlogging.h>
30-
#include <QStringView>
31-
#include <QLoggingCategory>
3232
#include "protocol.h"
3333

3434
Q_DECLARE_LOGGING_CATEGORY(generator);
@@ -78,7 +78,8 @@ void ParseContext::startElement(QStringView element_name,
7878
bool ok = false;
7979
version = att.value().toUInt(&ok);
8080
if (!ok) {
81-
qCCritical(generator) << "wrong version (" << att.value() << ")";
81+
qCCritical(generator)
82+
<< "wrong version (" << att.value() << ")";
8283
}
8384
}
8485
if (att.name() == "type") {
@@ -151,8 +152,9 @@ void ParseContext::startElement(QStringView element_name,
151152
if (!ok) {
152153
qCCritical(generator) << "invalid integer (" << since << ")";
153154
} else if (version > interface_->version_) {
154-
qCCritical(generator) << "since (" << version << ") larger than version ("
155-
<< interface_->version_ << ")";
155+
qCCritical(generator)
156+
<< "since (" << version << ") larger than version ("
157+
<< interface_->version_ << ")";
156158
}
157159
} else {
158160
version = 1;
@@ -165,7 +167,8 @@ void ParseContext::startElement(QStringView element_name,
165167
message_->since_ = version;
166168

167169
if (name == "destroy" && !message_->destructor_) {
168-
qCCritical(generator) << "destroy request should be destructor type";
170+
qCCritical(generator)
171+
<< "destroy request should be destructor type";
169172
}
170173
} else if (element_name == "arg") {
171174
if (name.isEmpty()) {
@@ -187,7 +190,8 @@ void ParseContext::startElement(QStringView element_name,
187190
break;
188191
default:
189192
if (!interface_name.isEmpty()) {
190-
qCCritical(generator) << "interface attribute not allowed for type " << type;
193+
qCCritical(generator)
194+
<< "interface attribute not allowed for type " << type;
191195
}
192196
break;
193197
}
@@ -198,13 +202,15 @@ void ParseContext::startElement(QStringView element_name,
198202
} else if (allow_null == "false") {
199203
arg->nullable_ = false;
200204
} else {
201-
qCCritical(generator) << "invalid value for allow-null attribute ("
202-
<< allow_null << ")";
205+
qCCritical(generator)
206+
<< "invalid value for allow-null attribute (" << allow_null
207+
<< ")";
203208
}
204209

205210
if (!arg->isNullableType()) {
206-
qCCritical(generator) << "allow-null is only valid for objects, strings, "
207-
"and arrays";
211+
qCCritical(generator)
212+
<< "allow-null is only valid for objects, strings, "
213+
"and arrays";
208214
}
209215
}
210216

@@ -223,9 +229,10 @@ void ParseContext::startElement(QStringView element_name,
223229
} else if (bitfield == "true") {
224230
enumeration_->bitfield_ = true;
225231
} else {
226-
qCCritical(generator) << "invalid value (" << bitfield
227-
<< ") for bitfield attribute (only true/false "
228-
"are accepted)";
232+
qCCritical(generator)
233+
<< "invalid value (" << bitfield
234+
<< ") for bitfield attribute (only true/false "
235+
"are accepted)";
229236
}
230237
} else if (element_name == "entry") {
231238
if (name.isEmpty()) {
@@ -239,33 +246,37 @@ void ParseContext::startElement(QStringView element_name,
239246
}
240247
}
241248

242-
void ParseContext::verifyArguments(Interface *interface,
243-
std::list<Message> *messages,
244-
std::list<Enumeration> * /*enumerations*/) const {
249+
void ParseContext::verifyArguments(
250+
Interface *interface, std::list<Message> *messages,
251+
std::list<Enumeration> * /*enumerations*/) const {
245252
for (auto &m : *messages) {
246253
for (auto &a : m.argList_) {
247254

248255
if (a.enumerationName_.isEmpty()) {
249256
continue;
250257
}
251258

252-
const auto *e = protocol_->findEnumeration(interface, a.enumerationName_);
259+
const auto *e =
260+
protocol_->findEnumeration(interface, a.enumerationName_);
253261

254262
if (!e) {
255-
qCCritical(generator) << "could not find enumeration " << a.enumerationName_;
263+
qCCritical(generator)
264+
<< "could not find enumeration " << a.enumerationName_;
256265
}
257266

258267
switch (a.type_) {
259268
case INT:
260269
if (e->bitfield_) {
261-
qCCritical(generator) << "bitfield-style enum must only be referenced "
262-
"by uint";
270+
qCCritical(generator)
271+
<< "bitfield-style enum must only be referenced "
272+
"by uint";
263273
}
264274
break;
265275
case UNSIGNED:
266276
break;
267277
default:
268-
qCCritical(generator) << "enumeration-style argument has wrong type";
278+
qCCritical(generator)
279+
<< "enumeration-style argument has wrong type";
269280
}
270281
}
271282
}
@@ -290,7 +301,8 @@ void ParseContext::endElement(QStringView name) {
290301
message_ = nullptr;
291302
} else if (name == "enum") {
292303
if (enumeration_->entryList_.empty()) {
293-
qCCritical(generator) << "enumeration " << enumeration_->name_ << " was empty";
304+
qCCritical(generator)
305+
<< "enumeration " << enumeration_->name_ << " was empty";
294306
}
295307
enumeration_ = nullptr;
296308
} else if (name == "protocol") {

src/parser.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#define _GENERATOR_PARSER_H_
99

1010
#include <list>
11-
#include "protocol.h"
12-
#include "utils.h"
13-
#include <QXmlStreamReader>
1411
#include <QFile>
1512
#include <QStringView>
13+
#include <QXmlStreamReader>
14+
#include "protocol.h"
15+
#include "utils.h"
1616

1717
struct Protocol;
1818
struct Message;
@@ -27,19 +27,16 @@ struct ParseContext {
2727

2828
void parse();
2929

30-
void verifyArguments(Interface *interface, std::list<Message> *messages, std::list<Enumeration> *enumerations) const;
30+
void verifyArguments(Interface *interface, std::list<Message> *messages,
31+
std::list<Enumeration> *enumerations) const;
3132

3233
void startElement(QStringView name, const QXmlStreamAttributes &atts);
3334
void endElement(QStringView name);
3435
void characterData(QStringView text);
3536

36-
void setLineNumber(int lineNumber) {
37-
loc_.lineNumber_ = lineNumber;
38-
}
37+
void setLineNumber(int lineNumber) { loc_.lineNumber_ = lineNumber; }
3938

40-
const Location &location() const {
41-
return loc_;
42-
}
39+
const Location &location() const { return loc_; }
4340

4441
bool main_;
4542
QXmlStreamReader reader_;

0 commit comments

Comments
 (0)