From 18a9aafdfaf5691244ac12945c2352daa7148abd Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 20 Jan 2018 01:00:34 +0100 Subject: [PATCH] build,tools: check freshness of doc addons Add a `--check` flag to `tools/doc/addon-verify.js` and use that in the `make test` target to determine if the generated files in `test/addons` are fresh or stale. PR-URL: https://github.com/nodejs/node/pull/17407 Reviewed-By: Richard Lau --- Makefile | 6 +++++- tools/doc/addon-verify.js | 31 ++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f988bb4e3681f6..6efb50950e1501 100644 --- a/Makefile +++ b/Makefile @@ -225,7 +225,7 @@ v8: .PHONY: test # This does not run tests of third-party libraries inside deps. -test: all build-addons ## Runs default tests, linters, and builds docs. +test: all check-doc-addons build-addons ## Runs default tests, linters, and builds docs. $(MAKE) -s doc-only $(MAKE) -s lint $(MAKE) -s cctest @@ -234,6 +234,10 @@ test: all build-addons ## Runs default tests, linters, and builds docs. $(CI_NATIVE_SUITES) \ $(CI_DOC) +.PHONY: check-doc-addons +check-doc-addons: $(NODE) + $(NODE) tools/doc/addon-verify.js --check + .PHONY: test-only test-only: all build-addons ## For a quick test, does not run linter or build docs. $(MAKE) cctest diff --git a/tools/doc/addon-verify.js b/tools/doc/addon-verify.js index 51ba75ca45ac68..e9b43a2b60cfff 100644 --- a/tools/doc/addon-verify.js +++ b/tools/doc/addon-verify.js @@ -10,6 +10,9 @@ const rootDir = path.resolve(__dirname, '..', '..'); const doc = path.resolve(rootDir, 'doc', 'api', 'addons.md'); const verifyDir = path.resolve(rootDir, 'test', 'addons'); +const changed = []; +const checkOnly = process.argv.includes('--check'); + let id = 0; let currentHeader; @@ -76,12 +79,6 @@ for (const header in addons) { }) }); - try { - fs.mkdirSync(dir); - } catch (e) { - strictEqual(e.code, 'EEXIST'); - } - for (const file of files) { let content; try { @@ -91,13 +88,29 @@ for (const header in addons) { } // Only update when file content has changed to prevent unneeded rebuilds. - if (content !== file.content) { - fs.writeFileSync(file.path, file.content); - console.log('wrote', file.path); + if (content === file.content) continue; + changed.push(file); + + if (checkOnly) continue; + + try { + fs.mkdirSync(dir); + } catch (e) { + strictEqual(e.code, 'EEXIST'); } + + fs.writeFileSync(file.path, file.content); + console.log('wrote', file.path); } } +if (checkOnly && changed.length > 0) { + console.error('The following files are out of date:'); + for (const { path } of changed) console.error(' ', path); + console.error('Run `node tools/doc/addon-verify.js` to update.'); + process.exit(1); +} + function boilerplate(name, content) { return `'use strict'; const common = require('../../common');