-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
- Loading branch information
1 parent
7ed058c
commit 6b6e6a5
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters