Skip to content

Commit

Permalink
tools: add script to synch c-ares source lists
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
richardlau authored and ruyadorno committed Nov 27, 2024
1 parent 7ed058c commit 6b6e6a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tools/dep_updaters/update-c-ares.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
3 changes: 3 additions & 0 deletions tools/dep_updaters/update-c-ares.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b6e6a5

Please sign in to comment.