Skip to content

Commit 3dceeb8

Browse files
richardlaumarco-ippolito
authored andcommitted
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: #55445 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 64b140d commit 3dceeb8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tools/dep_updaters/update-c-ares.mjs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Synchronize the sources for our c-ares gyp file from c-ares' Makefiles.
2+
import { readFileSync, writeFileSync } from 'node:fs';
3+
import { join } from 'node:path';
4+
5+
const srcroot = join(import.meta.dirname, '..', '..');
6+
const options = { encoding: 'utf8' };
7+
8+
// Extract list of sources from the gyp file.
9+
const gypFile = join(srcroot, 'deps', 'cares', 'cares.gyp');
10+
const contents = readFileSync(gypFile, options);
11+
const sourcesRE = /^\s+'cares_sources_common':\s+\[\s*\n(?<files>[\s\S]*?)\s+\],$/gm;
12+
const sourcesCommon = sourcesRE.exec(contents);
13+
14+
// Extract the list of sources from c-ares' Makefile.inc.
15+
const makefile = join(srcroot, 'deps', 'cares', 'src', 'lib', 'Makefile.inc');
16+
const libSources = readFileSync(makefile, options).split('\n')
17+
// Extract filenames (excludes comments and variable assignment).
18+
.map((line) => line.match(/^(?:.*= |\s*)?([^#\s]*)\s*\\?/)?.[1])
19+
// Filter out empty lines.
20+
.filter((line) => line !== '')
21+
// Prefix with directory and format as list entry.
22+
.map((line) => ` 'src/lib/${line}',`);
23+
24+
// Extract include files.
25+
const includeMakefile = join(srcroot, 'deps', 'cares', 'include', 'Makefile.am');
26+
const includeSources = readFileSync(includeMakefile, options)
27+
.match(/include_HEADERS\s*=\s*(.*)/)[1]
28+
.split(/\s/)
29+
.map((header) => ` 'include/${header}',`);
30+
31+
// Combine the lists. Alphabetically sort to minimize diffs.
32+
const fileList = includeSources.concat(libSources).sort();
33+
34+
// Replace the list of sources.
35+
const newContents = contents.replace(sourcesCommon.groups.files, fileList.join('\n'));
36+
if (newContents !== contents) {
37+
writeFileSync(gypFile, newContents, options);
38+
}

tools/dep_updaters/update-c-ares.sh

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ cp "$DEPS_DIR/cares/"*.gn "$DEPS_DIR/cares/"*.gni "$WORKSPACE/cares"
7171
echo "Replacing existing c-ares"
7272
replace_dir "$DEPS_DIR/cares" "$WORKSPACE/cares"
7373

74+
echo "Updating cares.gyp"
75+
"$NODE" "$ROOT/tools/dep_updaters/update-c-ares.mjs"
76+
7477
# Update the version number on maintaining-dependencies.md
7578
# and print the new version as the last line of the script as we need
7679
# to add it to $GITHUB_ENV variable

0 commit comments

Comments
 (0)