Skip to content

Commit c5c57f6

Browse files
josephperrottalxhub
authored andcommitted
build: update to clang 1.4.0 and only run clang format on changed files (angular#36203)
Update to clang@1.4.0 to gain support for optional changing and nullish coalescing. Because this would trigger a change on >1800 files in the repository, also changes our format enforcement to only be run against changed files. This will allow us to incramentally roll out the value add of the upgraded clang format. PR Close angular#36203
1 parent 51a89c3 commit c5c57f6

File tree

6 files changed

+60
-41
lines changed

6 files changed

+60
-41
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ jobs:
278278
- run: 'yarn bazel:lint ||
279279
(echo -e "\n.bzl files have lint errors. Please run ''yarn bazel:lint-fix''"; exit 1)'
280280

281-
- run: yarn lint
281+
- run: yarn lint --branch $CI_GIT_BASE_REVISION
282282
- run: yarn ts-circular-deps:check
283283
- run: yarn -s ng-dev pullapprove:verify
284284

.circleci/env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ else
3030
setPublicVar CI_COMMIT "$CIRCLE_SHA1";
3131
# `CI_COMMIT_RANGE` is only used on push builds (a.k.a. non-PR, non-scheduled builds and rerun
3232
# workflows of such builds).
33+
setPublicVar CI_GIT_BASE_REVISION "${CIRCLE_GIT_BASE_REVISION}";
34+
setPublicVar CI_GIT_REVISION "${CIRCLE_GIT_REVISION}";
3335
setPublicVar CI_COMMIT_RANGE "$CIRCLE_GIT_BASE_REVISION..$CIRCLE_GIT_REVISION";
3436
setPublicVar CI_PULL_REQUEST "${CIRCLE_PR_NUMBER:-false}";
3537
setPublicVar CI_REPO_NAME "$CIRCLE_PROJECT_REPONAME";

gulpfile.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,30 @@ function loadTask(fileName, taskName) {
2626
return task(gulp);
2727
}
2828

29-
// Check source code for formatting errors in all source files.
30-
gulp.task('format:enforce', loadTask('format', 'enforce'));
29+
//#######################################################
30+
// A format and enforce task for different sets of files.
31+
//#######################################################
3132

32-
// Format all source files.
33+
// All source files.
3334
gulp.task('format:all', loadTask('format', 'format'));
35+
gulp.task('format:all:enforce', loadTask('format', 'enforce'));
3436

35-
// Format only untracked source code files.
37+
// Untracked source code files.
3638
gulp.task('format:untracked', loadTask('format', 'format-untracked'));
39+
gulp.task('format:untracked:enforce', loadTask('format', 'enforce-untracked'));
3740

38-
// Format only the changed, tracked source code files.
41+
// Changed, tracked source code files.
3942
gulp.task('format:diff', loadTask('format', 'format-diff'));
43+
gulp.task('format:diff:enforce', loadTask('format', 'enforce-diff'));
4044

41-
// Format only changed lines based on the diff from the provided --branch
42-
// argument (or `master` by default).
45+
// Changed, both tracked and untracked, source code files.
4346
gulp.task('format:changed', ['format:untracked', 'format:diff']);
47+
gulp.task('format:changed:enforce', ['format:untracked:enforce', 'format:diff:enforce']);
4448

4549
// Alias for `format:changed` that formerly formatted all files.
4650
gulp.task('format', ['format:changed']);
4751

48-
gulp.task('lint', ['format:enforce', 'validate-commit-messages']);
52+
gulp.task('lint', ['format:changed:enforce', 'validate-commit-messages']);
4953
gulp.task('validate-commit-messages', loadTask('validate-commit-message'));
5054
gulp.task('source-map-test', loadTask('source-map-test'));
5155
gulp.task('changelog', loadTask('changelog'));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"@yarnpkg/lockfile": "^1.1.0",
158158
"browserstacktunnel-wrapper": "2.0.1",
159159
"check-side-effects": "0.0.21",
160-
"clang-format": "1.0.41",
160+
"clang-format": "^1.4.0",
161161
"cldr": "4.10.0",
162162
"cldr-data": "36.0.0",
163163
"cldrjs": "0.5.0",
@@ -167,7 +167,7 @@
167167
"firefox-profile": "1.0.3",
168168
"glob": "7.1.2",
169169
"gulp": "3.9.1",
170-
"gulp-clang-format": "1.0.23",
170+
"gulp-clang-format": "^1.0.27",
171171
"gulp-conventional-changelog": "^2.0.3",
172172
"gulp-filter": "^5.1.0",
173173
"gulp-git": "^2.7.0",

tools/gulp-tasks/format.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,42 @@ function gulpStatus() {
8585
}
8686

8787
module.exports = {
88-
// Check source code for formatting errors (clang-format)
88+
// Check source code for formatting errors with clang-format
8989
enforce: (gulp) => () => {
9090
const format = require('gulp-clang-format');
9191
const clangFormat = require('clang-format');
9292
return gulp.src(srcsToFmt).pipe(
9393
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
9494
},
9595

96+
// Check only the untracked source code files for formatting errors with .clang-format
97+
'enforce-untracked': (gulp) => () => {
98+
const format = require('gulp-clang-format');
99+
const clangFormat = require('clang-format');
100+
const gulpFilter = require('gulp-filter');
101+
102+
return gulpStatus()
103+
.pipe(gulpFilter(srcsToFmt))
104+
.pipe(format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
105+
},
106+
107+
// Check only the changed source code files diffed from the provided branch for formatting
108+
// errors with clang-format
109+
'enforce-diff': (gulp) => () => {
110+
const format = require('gulp-clang-format');
111+
const clangFormat = require('clang-format');
112+
const gulpFilter = require('gulp-filter');
113+
const minimist = require('minimist');
114+
const gulpGit = require('gulp-git');
115+
116+
const args = minimist(process.argv.slice(2));
117+
const branch = args.branch || 'master';
118+
119+
return gulpGit.diff(branch, {log: false})
120+
.pipe(gulpFilter(srcsToFmt))
121+
.pipe(format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
122+
},
123+
96124
// Format the source code with clang-format (see .clang-format)
97125
format: (gulp) => () => {
98126
const format = require('gulp-clang-format');

yarn.lock

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,19 +3570,10 @@ cjson@^0.3.1:
35703570
dependencies:
35713571
json-parse-helpfulerror "^1.0.3"
35723572

3573-
clang-format@1.0.41:
3574-
version "1.0.41"
3575-
resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.0.41.tgz#28552e50b0c9e44d23f85aebe3d2fbd06c93620c"
3576-
integrity sha1-KFUuULDJ5E0j+Frr49L70GyTYgw=
3577-
dependencies:
3578-
async "^1.5.2"
3579-
glob "^7.0.0"
3580-
resolve "^1.1.6"
3581-
3582-
clang-format@^1.0.32:
3583-
version "1.2.3"
3584-
resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.2.3.tgz#2763561aa7449c43737480f8df3a2b5b66e6cf37"
3585-
integrity sha512-x90Hac4ERacGDcZSvHKK58Ga0STuMD+Doi5g0iG2zf7wlJef5Huvhs/3BvMRFxwRYyYSdl6mpQNrtfMxE8MQzw==
3573+
clang-format@^1.0.32, clang-format@^1.4.0:
3574+
version "1.4.0"
3575+
resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.4.0.tgz#1ee2f10637eb5bb0bd7d0b82c949af68e848367e"
3576+
integrity sha512-NrdyUnHJOGvMa60vbWk7GJTvOdhibj3uK5C0FlwdNG4301OUvqEJTFce9I9x8qw2odBbIVrJ+9xbsFS3a4FbDA==
35863577
dependencies:
35873578
async "^1.5.2"
35883579
glob "^7.0.0"
@@ -7020,18 +7011,17 @@ gtoken@^4.1.0:
70207011
jws "^4.0.0"
70217012
mime "^2.2.0"
70227013

7023-
gulp-clang-format@1.0.23:
7024-
version "1.0.23"
7025-
resolved "https://registry.yarnpkg.com/gulp-clang-format/-/gulp-clang-format-1.0.23.tgz#fe258586b83998491e632fc0c4fc0ecdfa10c89f"
7026-
integrity sha1-/iWFhrg5mEkeYy/AxPwOzfoQyJ8=
7014+
gulp-clang-format@^1.0.27:
7015+
version "1.0.27"
7016+
resolved "https://registry.yarnpkg.com/gulp-clang-format/-/gulp-clang-format-1.0.27.tgz#c89716c26745703356c4ff3f2b0964393c73969e"
7017+
integrity sha512-Jj4PGuNXKdqVCh9fijvL7wdzma5TQRJz1vv8FjOjnSkfq3s/mvbdE/jq+5HG1c/q+jcYkXTEGkYT3CrdnJOLaQ==
70277018
dependencies:
70287019
clang-format "^1.0.32"
7020+
fancy-log "^1.3.2"
70297021
gulp-diff "^1.0.0"
7030-
gulp-util "^3.0.4"
7031-
pkginfo "^0.3.0"
7022+
plugin-error "^1.0.1"
70327023
stream-combiner2 "^1.1.1"
7033-
stream-equal "0.1.6"
7034-
through2 "^0.6.3"
7024+
through2 "^2.0.3"
70357025

70367026
gulp-conventional-changelog@^2.0.3:
70377027
version "2.0.3"
@@ -7089,7 +7079,7 @@ gulp-tslint@8.1.2:
70897079
map-stream "~0.0.7"
70907080
through "~2.3.8"
70917081

7092-
gulp-util@^3.0.0, gulp-util@^3.0.4, gulp-util@^3.0.6, gulp-util@~3.0.8:
7082+
gulp-util@^3.0.0, gulp-util@^3.0.6, gulp-util@~3.0.8:
70937083
version "3.0.8"
70947084
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f"
70957085
integrity sha1-AFTh50RQLifATBh8PsxQXdVLu08=
@@ -11459,7 +11449,7 @@ pkg-dir@^4.1.0:
1145911449
dependencies:
1146011450
find-up "^4.0.0"
1146111451

11462-
pkginfo@0.3.x, pkginfo@^0.3.0:
11452+
pkginfo@0.3.x:
1146311453
version "0.3.1"
1146411454
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.3.1.tgz#5b29f6a81f70717142e09e765bbeab97b4f81e21"
1146511455
integrity sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE=
@@ -13853,11 +13843,6 @@ stream-each@^1.1.0:
1385313843
end-of-stream "^1.1.0"
1385413844
stream-shift "^1.0.0"
1385513845

13856-
stream-equal@0.1.6:
13857-
version "0.1.6"
13858-
resolved "https://registry.yarnpkg.com/stream-equal/-/stream-equal-0.1.6.tgz#cc522fab38516012e4d4ee47513b147b72359019"
13859-
integrity sha1-zFIvqzhRYBLk1O5HUTsUe3I1kBk=
13860-
1386113846
stream-http@^2.7.2:
1386213847
version "2.8.3"
1386313848
resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.8.3.tgz#b2d242469288a5a27ec4fe8933acf623de6514fc"
@@ -14445,7 +14430,7 @@ through2@2.0.1:
1444514430
readable-stream "~2.0.0"
1444614431
xtend "~4.0.0"
1444714432

14448-
through2@^0.6.1, through2@^0.6.3:
14433+
through2@^0.6.1:
1444914434
version "0.6.5"
1445014435
resolved "https://registry.yarnpkg.com/through2/-/through2-0.6.5.tgz#41ab9c67b29d57209071410e1d7a7a968cd3ad48"
1445114436
integrity sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=

0 commit comments

Comments
 (0)