Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1072d57

Browse files
committedMar 4, 2025··
Add github actions
1 parent eb95eaa commit 1072d57

File tree

8 files changed

+199
-85
lines changed

8 files changed

+199
-85
lines changed
 

‎.clang-format

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -4
5+
ConstructorInitializerIndentWidth: 4
6+
AlignEscapedNewlinesLeft: false
7+
AlignTrailingComments: true
8+
AllowAllParametersOfDeclarationOnNextLine: true
9+
AllowShortBlocksOnASingleLine: false
10+
AllowShortIfStatementsOnASingleLine: false
11+
AllowShortLoopsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: All
13+
AlwaysBreakTemplateDeclarations: true
14+
AlwaysBreakBeforeMultilineStrings: false
15+
BreakBeforeBinaryOperators: false
16+
BreakBeforeTernaryOperators: true
17+
BreakConstructorInitializersBeforeComma: false
18+
BinPackParameters: true
19+
ColumnLimit: 80
20+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
21+
DerivePointerAlignment: false
22+
ExperimentalAutoDetectBinPacking: false
23+
IndentCaseLabels: false
24+
IndentWrappedFunctionNames: false
25+
IndentFunctionDeclarationAfterType: false
26+
MaxEmptyLinesToKeep: 1
27+
KeepEmptyLinesAtTheStartOfBlocks: true
28+
NamespaceIndentation: None
29+
ObjCSpaceAfterProperty: false
30+
ObjCSpaceBeforeProtocolList: true
31+
PenaltyBreakBeforeFirstCallParameter: 19
32+
PenaltyBreakComment: 300
33+
PenaltyBreakString: 1000
34+
PenaltyBreakFirstLessLess: 120
35+
PenaltyExcessCharacter: 1000000
36+
PenaltyReturnTypeOnItsOwnLine: 60
37+
PointerAlignment: Right
38+
SpacesBeforeTrailingComments: 1
39+
Cpp11BracedListStyle: true
40+
Standard: Cpp11
41+
IndentWidth: 4
42+
TabWidth: 4
43+
UseTab: Never
44+
BreakBeforeBraces: Attach
45+
SpacesInParentheses: false
46+
SpacesInAngles: false
47+
SpaceInEmptyParentheses: false
48+
SpacesInCStyleCastParentheses: false
49+
SpacesInContainerLiterals: true
50+
SpaceBeforeAssignmentOperators: true
51+
ContinuationIndentWidth: 4
52+
CommentPragmas: '^ IWYU pragma:'
53+
ForEachMacros: [ Q_FOREACH, BOOST_FOREACH ]
54+
SpaceBeforeParens: ControlStatements
55+
DisableFormat: false
56+
SortIncludes: true
57+
...
58+

‎.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

+36-35
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,63 @@
55
*
66
*/
77

8-
#include <cstdlib>
8+
#include "protocol.h"
99
#include <QCommandLineOption>
1010
#include <QCommandLineParser>
1111
#include <QCoreApplication>
1212
#include <QLatin1String>
1313
#include <QLoggingCategory>
1414
#include <QtLogging>
15+
#include <cstdlib>
1516
#include <ktexttemplate/metatype.h>
1617
#include <qcontainerfwd.h>
17-
#include "protocol.h"
1818

1919
Q_LOGGING_CATEGORY(generator, "generator");
2020

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

+39-27
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
*/
1919

2020
#include "parser.h"
21-
#include <list>
22-
#include <memory>
23-
#include <utility>
21+
#include "protocol.h"
2422
#include <QDebug>
2523
#include <QFile>
24+
#include <QLoggingCategory>
25+
#include <QStringView>
2626
#include <QXmlStreamReader>
2727
#include <QtLogging>
28+
#include <list>
29+
#include <memory>
2830
#include <qdebug.h>
2931
#include <qlogging.h>
30-
#include <QStringView>
31-
#include <QLoggingCategory>
32-
#include "protocol.h"
32+
#include <utility>
3333

3434
Q_DECLARE_LOGGING_CATEGORY(generator);
3535

@@ -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

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#ifndef _GENERATOR_PARSER_H_
88
#define _GENERATOR_PARSER_H_
99

10-
#include <list>
1110
#include "protocol.h"
1211
#include "utils.h"
13-
#include <QXmlStreamReader>
1412
#include <QFile>
1513
#include <QStringView>
14+
#include <QXmlStreamReader>
15+
#include <list>
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_;

‎src/protocol.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
*/
77

88
#include "protocol.h"
9-
#include <algorithm>
10-
#include <iostream>
11-
#include <list>
12-
#include <set>
13-
#include <vector>
9+
#include "parser.h"
10+
#include "utils.h"
1411
#include <KTextTemplate/Context>
1512
#include <KTextTemplate/Engine>
1613
#include <KTextTemplate/FileSystemTemplateLoader>
@@ -26,9 +23,12 @@
2623
#include <QVariant>
2724
#include <QVariantHash>
2825
#include <QtLogging>
26+
#include <algorithm>
27+
#include <iostream>
28+
#include <list>
2929
#include <qbytearrayview.h>
30-
#include "parser.h"
31-
#include "utils.h"
30+
#include <set>
31+
#include <vector>
3232

3333
using namespace Qt::Literals::StringLiterals;
3434

‎src/protocol.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
#ifndef _GENERATOR_PROTOCOL_H_
88
#define _GENERATOR_PROTOCOL_H_
99

10-
#include <list>
11-
#include <memory>
12-
#include <optional>
13-
#include <set>
14-
#include <utility>
10+
#include "utils.h"
1511
#include <KTextTemplate/MetaType>
1612
#include <KTextTemplate/TypeAccessor>
1713
#include <QMetaType>
1814
#include <QString>
1915
#include <QStringList>
2016
#include <QStringView>
21-
#include "utils.h"
17+
#include <list>
18+
#include <memory>
19+
#include <optional>
20+
#include <set>
21+
#include <utility>
2222

2323
struct Message;
2424
struct Enumeration;

‎src/utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#ifndef _GENERATOR_UTILS_H_
88
#define _GENERATOR_UTILS_H_
99

10+
#include <QString>
1011
#include <cctype>
1112
#include <climits>
1213
#include <cstdarg>
13-
#include <QString>
1414
#include <qtypes.h>
1515

1616
struct Location {

0 commit comments

Comments
 (0)
Please sign in to comment.