提交 4996dfd9 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Add clang-format stuff.

上级 2d25f18d
...@@ -62,22 +62,34 @@ In order to tun these tasks, `gulp-cli` (version >= 1.2.2) must be globally inst ...@@ -62,22 +62,34 @@ In order to tun these tasks, `gulp-cli` (version >= 1.2.2) must be globally inst
$ npm install -g gulp-cli $ npm install -g gulp-cli
``` ```
### `gulp lint:node`
Validates the Node.js JavaScript code.
### `gulp lint:worker`
Validates the worker C++ code.
### `gulp lint` ### `gulp lint`
Validates the JavaScript code. Runs both the `lint:node` and `lint:worker` gulp tasks.
### `gulp format:worker`
Rewrites all the worker source files and include files in order to satisfy the rules at `worker/.clang-format`.
### `gulp rtpcapabilities` ### `gulp rtpcapabilities`
Reads **mediasoup** [supported RTP capabilities](https://github.com/ibc/mediasoup/blob/master/lib/supportedRtpCapabilities.js) and inserts them into the worker C++ code. After that, `make Release` and/or `make Debug` must be called. Reads **mediasoup** [supported RTP capabilities](https://github.com/ibc/mediasoup/blob/master/lib/supportedRtpCapabilities.js) and inserts them into the worker C++ code. After that, `make Release` and/or `make Debug` must be called.
### `gulp test:api` ### `gulp test:node`
Runs the JavaScript [test units](test/). Before it, it invokes the `make` command. Runs the Node.js [test units](test/). Before it, it invokes the `make` command.
In order to run the JavaScript test units with the mediasoup worker in `Debug` mode the `MEDIASOUP_BUILDTYPE` environment variable must be set to `Debug`: In order to run the JavaScript test units with the mediasoup worker in `Debug` mode the `MEDIASOUP_BUILDTYPE` environment variable must be set to `Debug`:
```bash ```bash
$ MEDIASOUP_BUILDTYPE=Debug gulp test:api $ MEDIASOUP_BUILDTYPE=Debug gulp test:node
``` ```
### `gulp test:worker` ### `gulp test:worker`
...@@ -92,4 +104,4 @@ $ MEDIASOUP_BUILDTYPE=Debug gulp test:worker ...@@ -92,4 +104,4 @@ $ MEDIASOUP_BUILDTYPE=Debug gulp test:worker
### `gulp test` ### `gulp test`
Runs both the `test:api` and `test:worker` gulp tasks. Runs both the `test:node` and `test:worker` gulp tasks.
...@@ -5,8 +5,21 @@ const eslint = require('gulp-eslint'); ...@@ -5,8 +5,21 @@ const eslint = require('gulp-eslint');
const replace = require('gulp-replace'); const replace = require('gulp-replace');
const touch = require('gulp-touch-cmd'); const touch = require('gulp-touch-cmd');
const shell = require('gulp-shell'); const shell = require('gulp-shell');
const clangFormat = require('gulp-clang-format');
let tests = let nodeFiles =
[
'.eslintrc.js',
'gulpfile.js',
'lib/**/*.js',
'test/**/*.js'
];
const workerFiles =
[
'worker/src/**/*.cpp',
'worker/include/**/*.hpp'
];
const nodeTests =
[ [
'test/test_mediasoup.js', 'test/test_mediasoup.js',
'test/test_Server.js', 'test/test_Server.js',
...@@ -19,36 +32,36 @@ let tests = ...@@ -19,36 +32,36 @@ let tests =
// 'test/test_scene_1.js' // 'test/test_scene_1.js'
]; ];
gulp.task('lint', () => gulp.task('lint:node', () =>
{ {
let src = return gulp.src(nodeFiles)
[
'.eslintrc.js',
'gulpfile.js',
'lib/**/*.js',
'test/**/*.js'
];
return gulp.src(src)
.pipe(eslint()) .pipe(eslint())
.pipe(eslint.format()) .pipe(eslint.format())
.pipe(eslint.failAfterError()); .pipe(eslint.failAfterError());
}); });
gulp.task('rtpcapabilities', () => gulp.task('lint:worker', () =>
{ {
let supportedRtpCapabilities = require('./lib/supportedRtpCapabilities'); let src = workerFiles.concat(
// Remove Ragel generated files.
'!worker/src/Utils/IP.cpp'
);
return gulp.src('worker/src/RTC/Room.cpp') return gulp.src(src)
.pipe(replace(/(const std::string supportedRtpCapabilities =).*/, `$1 R"(${JSON.stringify(supportedRtpCapabilities)})";`)) .pipe(clangFormat.checkFormat('file', null, { verbose: true, fail: true }));
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
}); });
gulp.task('test:api', shell.task( gulp.task('format:worker', () =>
{
return gulp.src(workerFiles, { base: '.' })
.pipe(clangFormat.format('file'))
.pipe(gulp.dest('.'));
});
gulp.task('test:node', shell.task(
[ [
'if type make &> /dev/null; then make; fi', 'if type make &> /dev/null; then make; fi',
`tap --bail --color --reporter=spec ${tests.join(' ')}` `tap --bail --color --reporter=spec ${nodeTests.join(' ')}`
], ],
{ {
verbose : true, verbose : true,
...@@ -67,6 +80,18 @@ gulp.task('test:worker', shell.task( ...@@ -67,6 +80,18 @@ gulp.task('test:worker', shell.task(
} }
)); ));
gulp.task('test', gulp.series('test:api', 'test:worker')); gulp.task('rtpcapabilities', () =>
{
let supportedRtpCapabilities = require('./lib/supportedRtpCapabilities');
return gulp.src('worker/src/RTC/Room.cpp')
.pipe(replace(/(const std::string supportedRtpCapabilities =).*/, `$1 R"(${JSON.stringify(supportedRtpCapabilities)})";`))
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
});
gulp.task('lint', gulp.series('lint:node', 'lint:worker'));
gulp.task('test', gulp.series('test:node', 'test:worker'));
gulp.task('default', gulp.series('lint', 'test')); gulp.task('default', gulp.series('lint', 'test'));
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
}, },
"devDependencies": { "devDependencies": {
"gulp": "git://github.com/gulpjs/gulp.git#4.0", "gulp": "git://github.com/gulpjs/gulp.git#4.0",
"gulp-clang-format": "^1.0.23",
"gulp-eslint": "^3.0.1", "gulp-eslint": "^3.0.1",
"gulp-replace": "^0.5.4", "gulp-replace": "^0.5.4",
"gulp-shell": "^0.6.3", "gulp-shell": "^0.6.3",
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论