-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
144 lines (125 loc) · 3.58 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const touch = require('gulp-touch-cmd');
const shell = require('gulp-shell');
const clangFormat = require('gulp-clang-format');
const os = require('os');
const 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-Server.js',
'test/test-Room.js',
'test/test-Peer.js',
'test/test-Transport.js',
'test/test-RtpReceiver.js',
'test/test-extra.js'
];
const workerCompilationDatabaseTemplate = 'worker/compile_commands_template.json';
const workerHeaderFilterRegex =
'(common.hpp|DepLibSRTP.hpp|DepLibUV.hpp|DepOpenSSL.hpp|LogLevel.hpp|Logger.hpp' +
'|Loop.hpp|MediaSoupError.hpp|Settings.hpp|Utils.hpp' +
'|handles/*.hpp|Channel/*.hpp|RTC/**/*.hpp)';
const numCpus = os.cpus().length;
gulp.task('rtpcapabilities', () =>
{
let supportedRtpCapabilities = require('./lib/supportedRtpCapabilities');
return gulp.src('worker/src/RTC/Room.cpp')
// Let's generate valid syntax as expected by clang-format rules.
.pipe(replace(/(const std::string supportedRtpCapabilities =).*\r?\n.*/,
`$1\n\t\t\t R"(${JSON.stringify(supportedRtpCapabilities)})";`))
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
});
gulp.task('lint:node', () =>
{
return gulp.src(nodeFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:worker', () =>
{
let src = workerFiles.concat(
// Remove Ragel generated files.
'!worker/src/Utils/IP.cpp'
);
return gulp.src(src)
.pipe(clangFormat.checkFormat('file', null, { verbose: true, fail: true }));
});
gulp.task('format:worker', () =>
{
let src = workerFiles.concat(
// Remove Ragel generated files.
'!worker/src/Utils/IP.cpp'
);
return gulp.src(src, { base: '.' })
.pipe(clangFormat.format('file'))
.pipe(gulp.dest('.'));
});
gulp.task('tidy:worker:prepare', () =>
{
return gulp.src(workerCompilationDatabaseTemplate)
.pipe(replace(/PATH/gm, __dirname))
.pipe(rename('compile_commands.json'))
.pipe(gulp.dest('worker'))
.pipe(touch());
});
gulp.task('tidy:worker:run', shell.task(
[
'cd worker && ' +
'./scripts/clang-tidy.py ' +
'-clang-tidy-binary=../node_modules/.bin/clang-tidy ' +
'-clang-apply-replacements-binary=../node_modules/.bin/clang-apply-replacements ' +
`-header-filter='${workerHeaderFilterRegex}' ` +
'-p=. ' +
`-j=${numCpus} ` +
`-checks=${process.env.MEDIASOUP_TIDY_CHECKS || ''} ` +
'-quiet ' +
`${process.env.MEDIASOUP_TIDY_FIX === '1' ? '-fix -format' : ''}`
],
{
verbose : true
}
));
gulp.task('tidy:worker', gulp.series('tidy:worker:prepare', 'tidy:worker:run'));
gulp.task('test:node', shell.task(
[
'if type make &> /dev/null; then make; fi',
`tap --bail --color --reporter=spec ${nodeTests.join(' ')}`
],
{
verbose : true,
env : { DEBUG: '*ABORT* *WARN*' }
}
));
gulp.task('test:worker', shell.task(
[
'if type make &> /dev/null; then make test; fi',
`cd worker && ./out/${process.env.MEDIASOUP_BUILDTYPE === 'Debug' ?
'Debug' : 'Release'}/mediasoup-worker-test --invisibles --use-colour=yes`
],
{
verbose : true,
env : { DEBUG: '*ABORT* *WARN*' }
}
));
gulp.task('lint', gulp.series('lint:node', 'lint:worker'));
gulp.task('format', gulp.series('format:worker'));
gulp.task('tidy', gulp.series('tidy:worker'));
gulp.task('test', gulp.series('test:node', 'test:worker'));
gulp.task('default', gulp.series('lint', 'test'));