mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
e0145b4c38
GitHub Actions is by default running the tools updater workflow with Node.js 18. Avoid use of `import.meta.dirname`, which wasn't backported to Node.js 18. PR-URL: https://github.com/nodejs/node/pull/55717 Refs: https://github.com/nodejs/node/pull/55445 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
// Synchronize the sources for our c-ares gyp file from c-ares' Makefiles.
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const srcroot = fileURLToPath(new URL('../../', import.meta.url));
|
|
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);
|
|
}
|