Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add script to synch c-ares source lists #55445

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions deps/cares/cares.gyp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
'variables': {
# This list is generated by `tools/dep_updaters/update-c-ares.mjs`.
'cares_sources_common': [
'include/ares.h',
'include/ares_build.h',
'include/ares_dns.h',
'include/ares_dns_record.h',
'include/ares_nameser.h',
Expand Down Expand Up @@ -49,6 +51,8 @@
'src/lib/ares_strerror.c',
'src/lib/ares_sysconfig.c',
'src/lib/ares_sysconfig_files.c',
'src/lib/ares_sysconfig_mac.c',
'src/lib/ares_sysconfig_win.c',
'src/lib/ares_timeout.c',
'src/lib/ares_update_servers.c',
'src/lib/ares_version.c',
Expand Down Expand Up @@ -111,11 +115,11 @@
'src/lib/record/ares_dns_private.h',
'src/lib/record/ares_dns_record.c',
'src/lib/record/ares_dns_write.c',
'src/lib/str/ares__buf.h',
'src/lib/str/ares_buf.c',
'src/lib/str/ares_str.c',
'src/lib/str/ares_strsplit.c',
'src/lib/str/ares_strsplit.h',
'src/lib/thirdparty/apple/dnsinfo.h',
'src/lib/util/ares_iface_ips.c',
'src/lib/util/ares_iface_ips.h',
'src/lib/util/ares_math.c',
Expand All @@ -128,18 +132,10 @@
'src/lib/util/ares_timeval.c',
'src/lib/util/ares_uri.c',
'src/lib/util/ares_uri.h',
'src/tools/ares_getopt.c',
'src/tools/ares_getopt.h',
'src/lib/windows_port.c',
],
'cares_sources_mac': [
'config/darwin/ares_config.h',
'src/lib/ares_sysconfig_mac.c',
'src/lib/thirdparty/apple/dnsinfo.h',
],
'cares_sources_win': [
'src/lib/ares_sysconfig_win.c',
'src/lib/config-win32.h',
'src/lib/windows_port.c',
],
},

Expand Down Expand Up @@ -201,9 +197,6 @@
'_WINSOCK_DEPRECATED_NO_WARNINGS',
],
'include_dirs': [ 'config/win32' ],
'sources': [
'<@(cares_sources_win)',
],
'libraries': [
'-lws2_32.lib',
'-liphlpapi.lib'
Expand Down
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
Loading