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 <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
pull/55474/head
Richard Lau 2024-10-18 16:04:25 +00:00 committed by Node.js GitHub Bot
parent b0ffe9ed35
commit 4bf115a9ac
2 changed files with 41 additions and 0 deletions

View File

@ -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(?<files>[\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);
}

View File

@ -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