From 6b6e6a55905c91757ecafa8fcd2483adba168015 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 18 Oct 2024 16:04:25 +0000 Subject: [PATCH] tools: add script to synch c-ares source lists Add step to the updater script for c-ares to synchronize the list of sources in our gyp file with the lists in c-ares' Makefiles. PR-URL: https://github.com/nodejs/node/pull/55445 Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli --- tools/dep_updaters/update-c-ares.mjs | 38 ++++++++++++++++++++++++++++ tools/dep_updaters/update-c-ares.sh | 3 +++ 2 files changed, 41 insertions(+) create mode 100644 tools/dep_updaters/update-c-ares.mjs diff --git a/tools/dep_updaters/update-c-ares.mjs b/tools/dep_updaters/update-c-ares.mjs new file mode 100644 index 00000000000000..c5057e666de70d --- /dev/null +++ b/tools/dep_updaters/update-c-ares.mjs @@ -0,0 +1,38 @@ +// Synchronize the sources for our c-ares gyp file from c-ares' Makefiles. +import { readFileSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; + +const srcroot = join(import.meta.dirname, '..', '..'); +const options = { encoding: 'utf8' }; + +// Extract list of sources from the gyp file. +const gypFile = join(srcroot, 'deps', 'cares', 'cares.gyp'); +const contents = readFileSync(gypFile, options); +const sourcesRE = /^\s+'cares_sources_common':\s+\[\s*\n(?[\s\S]*?)\s+\],$/gm; +const sourcesCommon = sourcesRE.exec(contents); + +// Extract the list of sources from c-ares' Makefile.inc. +const makefile = join(srcroot, 'deps', 'cares', 'src', 'lib', 'Makefile.inc'); +const libSources = readFileSync(makefile, options).split('\n') + // Extract filenames (excludes comments and variable assignment). + .map((line) => line.match(/^(?:.*= |\s*)?([^#\s]*)\s*\\?/)?.[1]) + // Filter out empty lines. + .filter((line) => line !== '') + // Prefix with directory and format as list entry. + .map((line) => ` 'src/lib/${line}',`); + +// Extract include files. +const includeMakefile = join(srcroot, 'deps', 'cares', 'include', 'Makefile.am'); +const includeSources = readFileSync(includeMakefile, options) + .match(/include_HEADERS\s*=\s*(.*)/)[1] + .split(/\s/) + .map((header) => ` 'include/${header}',`); + +// Combine the lists. Alphabetically sort to minimize diffs. +const fileList = includeSources.concat(libSources).sort(); + +// Replace the list of sources. +const newContents = contents.replace(sourcesCommon.groups.files, fileList.join('\n')); +if (newContents !== contents) { + writeFileSync(gypFile, newContents, options); +} diff --git a/tools/dep_updaters/update-c-ares.sh b/tools/dep_updaters/update-c-ares.sh index 66d37ba350c246..f990430d9f6aee 100755 --- a/tools/dep_updaters/update-c-ares.sh +++ b/tools/dep_updaters/update-c-ares.sh @@ -71,6 +71,9 @@ cp "$DEPS_DIR/cares/"*.gn "$DEPS_DIR/cares/"*.gni "$WORKSPACE/cares" echo "Replacing existing c-ares" replace_dir "$DEPS_DIR/cares" "$WORKSPACE/cares" +echo "Updating cares.gyp" +"$NODE" "$ROOT/tools/dep_updaters/update-c-ares.mjs" + # Update the version number on maintaining-dependencies.md # and print the new version as the last line of the script as we need # to add it to $GITHUB_ENV variable