Unverified 提交 31917af5 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Modernize clang-format (#1221)

上级 262dba06
......@@ -68,8 +68,9 @@ jobs:
- name: npm ci
run: npm ci --ignore-scripts --omit=dev
- name: npm run install-clang-tools
run: npm run install-clang-tools
# We need to install deps on worker/scripts/package.json.
- name: npm run install-worker-dev-tools
run: npm run install-worker-dev-tools
# TODO: Maybe fix this one day.
if: runner.os != 'Windows'
......
......@@ -192,7 +192,7 @@ async function run()
break;
}
case 'install-clang-tools':
case 'install-worker-dev-tools':
{
executeCmd('npm ci --prefix worker/scripts');
......@@ -353,7 +353,7 @@ function lintNode()
{
logInfo('lintNode()');
executeCmd('eslint -c node/.eslintrc.js --ignore-path node/.eslintignore --max-warnings 0 node/src node/.eslintrc.js npm-scripts.mjs worker/scripts/gulpfile.mjs');
executeCmd('eslint -c node/.eslintrc.js --ignore-path node/.eslintignore --max-warnings 0 node/src node/.eslintrc.js npm-scripts.mjs worker/scripts/clang-format.mjs');
}
function lintWorker()
......@@ -744,19 +744,19 @@ function executeCmd(command, exitOnError = true)
function logInfo(message)
{
// eslint-disable-next-line no-console
console.log(`npm-scripts \x1b[36m[INFO] [${task}]\x1b\[0m`, message);
console.log(`npm-scripts.mjs \x1b[36m[INFO] [${task}]\x1b\[0m`, message);
}
function logWarn(message)
{
// eslint-disable-next-line no-console
console.warn(`npm-scripts \x1b[33m[WARN] [${task}]\x1b\[0m`, message);
console.warn(`npm-scripts.mjs \x1b[33m[WARN] [${task}]\x1b\[0m`, message);
}
function logError(message)
{
// eslint-disable-next-line no-console
console.error(`npm-scripts \x1b[31m[ERROR] [${task}]\x1b\[0m`, message);
console.error(`npm-scripts.mjs \x1b[31m[ERROR] [${task}]\x1b\[0m`, message);
}
function exitWithError()
......
......@@ -67,7 +67,7 @@
"test:worker": "node npm-scripts.mjs test:worker",
"coverage:node": "node npm-scripts.mjs coverage:node",
"install-deps:node": "node npm-scripts.mjs install-deps:node",
"install-clang-tools": "node npm-scripts.mjs install-clang-tools",
"install-worker-dev-tools": "node npm-scripts.mjs install-worker-dev-tools",
"release:check": "node npm-scripts.mjs release:check",
"release": "node npm-scripts.mjs release",
"release:upload-mac-arm-prebuilt-worker": "node npm-scripts.mjs release:upload-mac-arm-prebuilt-worker"
......
......@@ -61,6 +61,7 @@ IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: true
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
......
......@@ -13,7 +13,6 @@ MEDIASOUP_OUT_DIR ?= $(shell pwd)/out
# Check the meaning of useful macros in the `worker/include/Logger.hpp` header
# file if you want to enable tracing or other debug information.
MEDIASOUP_BUILDTYPE ?= Release
GULP = ./scripts/node_modules/.bin/gulp
LCOV = ./deps/lcov/bin/lcov
DOCKER ?= docker
PIP_DIR = $(MEDIASOUP_OUT_DIR)/pip
......@@ -213,10 +212,10 @@ xcode: setup
$(MESON) setup --buildtype debug --backend xcode $(MEDIASOUP_OUT_DIR)/xcode
lint:
$(GULP) --gulpfile ./scripts/gulpfile.mjs lint:worker
npm run lint --prefix scripts/
format:
$(GULP) --gulpfile ./scripts/gulpfile.mjs format:worker
npm run format --prefix scripts/
test: setup flatc
$(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-test
......
......@@ -15,7 +15,9 @@ namespace RTC
{
// data size must be >= header.
if (Item::HeaderSize > len)
{
return nullptr;
}
auto* header =
const_cast<typename Item::Header*>(reinterpret_cast<const typename Item::Header*>(data));
......
import { execSync } from 'node:child_process';
import { glob } from 'glob';
import clangFormat from 'clang-format';
const task = process.argv.slice(2).join(' ');
run();
async function run()
{
const clangFormatNativeBinary = clangFormat.getNativeBinary();
const workerFiles = await glob(
[
'../src/**/*.cpp',
'../include/**/*.hpp',
'../test/src/**/*.cpp',
'../test/include/helpers.hpp',
'../fuzzer/src/**/*.cpp',
'../fuzzer/include/**/*.hpp'
]
);
switch (task)
{
case 'lint':
{
executeCmd(
`${clangFormatNativeBinary} --Werror --dry-run ${workerFiles.join(' ')}`
);
break;
}
case 'format':
{
executeCmd(
`${clangFormatNativeBinary} --Werror -i ${workerFiles.join(' ')}`
);
break;
}
default:
{
logError('unknown task');
exitWithError();
}
}
}
function executeCmd(command)
{
try
{
execSync(command, { stdio: [ 'ignore', process.stdout, process.stderr ] });
}
catch (error)
{
logError('executeCmd() failed');
exitWithError();
}
}
// eslint-disable-next-line no-unused-vars
function logInfo(message)
{
// eslint-disable-next-line no-console
console.log(`clang-format.mjs \x1b[36m[INFO] [${task}]\x1b\[0m`, message);
}
// eslint-disable-next-line no-unused-vars
function logWarn(message)
{
// eslint-disable-next-line no-console
console.warn(`clang-format.mjs \x1b[33m[WARN] [${task}]\x1b\[0m`, message);
}
function logError(message)
{
// eslint-disable-next-line no-console
console.error(`clang-format.mjs \x1b[31m[ERROR] [${task}]\x1b\[0m`, message);
}
function exitWithError()
{
process.exit(1);
}
import gulp from 'gulp';
import clangFormat from 'gulp-clang-format';
const workerFiles =
[
'../src/**/*.cpp',
'../include/**/*.hpp',
'../test/src/**/*.cpp',
'../test/include/helpers.hpp',
'../fuzzer/src/**/*.cpp',
'../fuzzer/include/**/*.hpp'
];
gulp.task('lint:worker', () =>
{
return gulp.src(workerFiles)
.pipe(clangFormat.checkFormat('file', null, { verbose: true, fail: true }));
});
gulp.task('format:worker', () =>
{
return gulp.src(workerFiles, { base: '.' })
.pipe(clangFormat.format('file'))
.pipe(gulp.dest('.'));
});
......@@ -2,12 +2,13 @@
"name": "mediasoup-worker-dev-tools",
"version": "0.0.1",
"description": "mediasoup worker dev tools",
"devDependencies": {
"clang-tools-prebuilt": "^0.1.4",
"gulp": "^4.0.2",
"gulp-clang-format": "^1.0.27"
"scripts": {
"lint": "node clang-format.mjs lint",
"format": "node clang-format.mjs format"
},
"peerDependencies": {
"uuid": "^3.3.2"
"dependencies": {
"clang-format": "^1.8.0",
"clang-tools-prebuilt": "^0.1.4",
"glob": "^10.3.10"
}
}
......@@ -129,13 +129,19 @@ namespace RTC
// Add the items into the packet.
for (auto* report : senderReports)
{
this->senderReportPacket.AddReport(report);
}
for (auto* chunk : sdesChunks)
{
this->sdesPacket.AddChunk(chunk);
}
for (auto* report : delaySinceLastRrReports)
{
this->xrPacket.AddReport(report);
}
// New items can hold in the packet, report it.
if (GetSize() <= MaxSize)
......@@ -174,7 +180,9 @@ namespace RTC
// Add the items into the packet.
for (auto* report : receiverReports)
{
this->receiverReportPacket.AddReport(report);
}
if (receiverReferenceTimeReport)
{
......
......@@ -97,7 +97,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
packet->SetFeedbackPacketCount(1);
for (auto& input : inputs)
{
packet->AddPacket(input.sequenceNumber, input.timestamp, input.maxPacketSize);
}
REQUIRE(packet->GetLatestSequenceNumber() == 1013);
REQUIRE(packet->GetLatestTimestamp() == 1000000013);
......@@ -170,7 +172,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
packet->SetFeedbackPacketCount(10);
for (auto& input : inputs)
{
packet->AddPacket(input.sequenceNumber, input.timestamp, input.maxPacketSize);
}
packet->Finish();
validate(inputs, packet->GetPacketResults());
......@@ -233,7 +237,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
packet->SetFeedbackPacketCount(1);
for (auto& input : inputs)
{
packet->AddPacket(input.sequenceNumber, input.timestamp, input.maxPacketSize);
}
packet->Finish();
validate(inputs, packet->GetPacketResults());
......@@ -289,7 +295,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
packet->SetFeedbackPacketCount(1);
for (auto& input : inputs)
{
packet->AddPacket(input.sequenceNumber, input.timestamp, input.maxPacketSize);
}
packet->Finish();
validate(inputs, packet->GetPacketResults());
......@@ -354,7 +362,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
packet->SetFeedbackPacketCount(1);
for (auto& input : inputs)
{
packet->AddPacket(input.sequenceNumber, input.timestamp, input.maxPacketSize);
}
packet->Finish();
validate(inputs, packet->GetPacketResults());
......@@ -413,7 +423,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
packet2->SetFeedbackPacketCount(2);
for (auto& input : inputs2)
{
packet2->AddPacket(input.sequenceNumber, input.timestamp, input.maxPacketSize);
}
packet2->Finish();
validate(inputs2, packet2->GetPacketResults());
......@@ -593,8 +605,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
.packetStatusCount = 1,
.deltas = std::vector<int16_t>{ 57 },
.buffer = std::vector<uint8_t>{ 0xaf, 0xcd, 0x00, 0x05, 0xfa, 0x17, 0xfa, 0x17,
0x00, 0x00, 0x04, 0xd2, 0x00, 0x0d, 0x00, 0x01,
0x00, 0x8A, 0xB0, 0x00, 0x20, 0x01, 0xE4, 0x01 } },
0x00, 0x00, 0x04, 0xd2, 0x00, 0x0d, 0x00, 0x01,
0x00, 0x8A, 0xB0, 0x00, 0x20, 0x01, 0xE4, 0x01 } },
{ .baseTimeRaw = 35504,
.baseTimeMs = 1076014080,
.baseSequence = 14,
......@@ -630,8 +642,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
.packetStatusCount = 2,
.deltas = std::vector<int16_t>{ 35, 17 },
.buffer = std::vector<uint8_t>{ 0x8F, 0xCD, 0x00, 0x05, 0xFA, 0x17, 0xFA, 0x17,
0x39, 0xE9, 0x42, 0x38, 0x00, 0x01, 0x00, 0x02,
0xBD, 0x57, 0xAA, 0x00, 0x20, 0x02, 0x8C, 0x44 } },
0x39, 0xE9, 0x42, 0x38, 0x00, 0x01, 0x00, 0x02,
0xBD, 0x57, 0xAA, 0x00, 0x20, 0x02, 0x8C, 0x44 } },
{ .baseTimeRaw = 818995,
.baseTimeMs = 1126157504,
......@@ -690,16 +702,16 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]"
.packetStatusCount = 2,
.deltas = std::vector<int16_t>{ 44, 18 },
.buffer = std::vector<uint8_t>{ 0x8F, 0xCD, 0x00, 0x05, 0xFA, 0x17, 0xFA, 0x17,
0x08, 0xEB, 0x06, 0xD7, 0x00, 0x11, 0x00, 0x02,
0x0C, 0x89, 0x14, 0x01, 0x20, 0x02, 0xB0, 0x48 } },
0x08, 0xEB, 0x06, 0xD7, 0x00, 0x11, 0x00, 0x02,
0x0C, 0x89, 0x14, 0x01, 0x20, 0x02, 0xB0, 0x48 } },
{ .baseTimeRaw = 821524,
.baseTimeMs = 1126319360,
.baseSequence = 17,
.packetStatusCount = 1,
.deltas = std::vector<int16_t>{ 62 },
.buffer = std::vector<uint8_t>{ 0xAF, 0xCD, 0x00, 0x05, 0xFA, 0x17, 0xFA, 0x17,
0x20, 0x92, 0x5E, 0xB7, 0x00, 0x11, 0x00, 0x01,
0x0C, 0x89, 0x14, 0x00, 0x20, 0x01, 0xF8, 0x01 } },
0x20, 0x92, 0x5E, 0xB7, 0x00, 0x11, 0x00, 0x01,
0x0C, 0x89, 0x14, 0x00, 0x20, 0x01, 0xF8, 0x01 } },
{ .baseTimeRaw = 821526,
.baseTimeMs = 1126319488,
.baseSequence = 19,
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论