Skip to content

Commit 65936a8

Browse files
richardlauaduh95
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 a12dbf0 commit 65936a8

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
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+
constsrcroot=join(import.meta.dirname,'..','..');
6+
constoptions={encoding: 'utf8'};
7+
8+
// Extract list of sources from the gyp file.
9+
constgypFile=join(srcroot,'deps','cares','cares.gyp');
10+
constcontents=readFileSync(gypFile,options);
11+
constsourcesRE=/^\s+'cares_sources_common':\s+\[\s*\n(?<files>[\s\S]*?)\s+\],$/gm;
12+
constsourcesCommon=sourcesRE.exec(contents);
13+
14+
// Extract the list of sources from c-ares' Makefile.inc.
15+
constmakefile=join(srcroot,'deps','cares','src','lib','Makefile.inc');
16+
constlibSources=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+
constincludeMakefile=join(srcroot,'deps','cares','include','Makefile.am');
26+
constincludeSources=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+
constfileList=includeSources.concat(libSources).sort();
33+
34+
// Replace the list of sources.
35+
constnewContents=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‎

Lines changed: 3 additions & 0 deletions
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)