-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Deepak Rajamohan
committed
Sep 23, 2021
1 parent
22a2f3c
commit 5f3f131
Showing
15 changed files
with
452 additions
and
14 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
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
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
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
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,3 @@ | ||
/node_modules | ||
/build | ||
/generated |
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,27 @@ | ||
module.exports.generateFileContent = function(configs) { | ||
const content = []; | ||
const inits = []; | ||
const exports = []; | ||
|
||
for (let config of configs) { | ||
inits.push(`Object Init${config.objectName}(Env env);`); | ||
exports.push(`exports.Set(\"${config.propertyName}\", Init${config.objectName}(env));`); | ||
} | ||
|
||
content.push("#include \"napi.h\""); | ||
content.push("using namespace Napi;"); | ||
|
||
//content.push("Object InitName(Env env);"); | ||
inits.forEach(init => content.push(init)); | ||
|
||
content.push("Object Init(Env env, Object exports) {"); | ||
|
||
//content.push("exports.Set(\"name\", InitName(env));"); | ||
exports.forEach(exp => content.push(exp)); | ||
|
||
content.push("return exports;"); | ||
content.push("}"); | ||
content.push("NODE_API_MODULE(addon, Init);"); | ||
|
||
return Promise.resolve(content.join('\r\n')); | ||
} |
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,64 @@ | ||
{ | ||
'target_defaults': { | ||
'includes': ['common.gypi'], | ||
'include_dirs': ['../test/common'], | ||
'variables': { | ||
'build_sources': [ | ||
"<!@(node -p \"require('./injectTestParams').filesToCompile()\")", | ||
] | ||
}, | ||
}, | ||
'targets': [ | ||
{ | ||
"target_name": "generateBindingCC", | ||
"type": "none", | ||
"actions": [ { | ||
"action_name": "generateBindingCC", | ||
"message": "Generating binding cc file", | ||
"outputs": ["generated/binding.cc"], | ||
"conditions": [ | ||
[ "'true'=='true'", { | ||
"inputs": [""], | ||
"action": [ | ||
"node", | ||
"generate-binding-cc.js", | ||
"<!@(node -p \"require('./injectTestParams').filesForBinding()\" )" | ||
] | ||
} ] | ||
] | ||
} ] | ||
}, | ||
{ | ||
'target_name': 'binding', | ||
'includes': ['../except.gypi'], | ||
'sources': ['>@(build_sources)'], | ||
'dependencies': [ 'generateBindingCC' ] | ||
}, | ||
{ | ||
'target_name': 'binding_noexcept', | ||
'includes': ['../noexcept.gypi'], | ||
'sources': ['>@(build_sources)'], | ||
'dependencies': [ 'generateBindingCC' ] | ||
}, | ||
{ | ||
'target_name': 'binding_noexcept_maybe', | ||
'includes': ['../noexcept.gypi'], | ||
'sources': ['>@(build_sources)'], | ||
'defines': ['NODE_ADDON_API_ENABLE_MAYBE'] | ||
}, | ||
{ | ||
'target_name': 'binding_swallowexcept', | ||
'includes': ['../except.gypi'], | ||
'sources': ['>@(build_sources)'], | ||
'defines': ['NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'], | ||
'dependencies': [ 'generateBindingCC' ] | ||
}, | ||
{ | ||
'target_name': 'binding_swallowexcept_noexcept', | ||
'includes': ['../noexcept.gypi'], | ||
'sources': ['>@(build_sources)'], | ||
'defines': ['NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'], | ||
'dependencies': [ 'generateBindingCC' ] | ||
}, | ||
], | ||
} |
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,21 @@ | ||
{ | ||
'variables': { | ||
'NAPI_VERSION%': "<!(node -p \"process.versions.napi\")", | ||
'disable_deprecated': "<!(node -p \"process.env['npm_config_disable_deprecated']\")" | ||
}, | ||
'conditions': [ | ||
['NAPI_VERSION!=""', { 'defines': ['NAPI_VERSION=<@(NAPI_VERSION)'] } ], | ||
['disable_deprecated=="true"', { | ||
'defines': ['NODE_ADDON_API_DISABLE_DEPRECATED'] | ||
}], | ||
['OS=="mac"', { | ||
'cflags+': ['-fvisibility=hidden'], | ||
'xcode_settings': { | ||
'OTHER_CFLAGS': ['-fvisibility=hidden'] | ||
} | ||
}] | ||
], | ||
'include_dirs': ["<!(node -p \"require('../').include_dir\")", "./generated"], | ||
'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ], | ||
'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ] | ||
} |
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,20 @@ | ||
module.exports = { | ||
'nouns': { | ||
'constructor': 'constructor', | ||
'threadsafe': 'threadSafe', | ||
'objectwrap': 'objectWrap', | ||
}, | ||
'exportNames': { | ||
'AsyncWorkerPersistent': 'PersistentAsyncWorker', | ||
}, | ||
'propertyNames': { | ||
'async_worker_persistent': 'persistentasyncworker', | ||
'objectwrap_constructor_exception':'objectwrapConstructorException', | ||
}, | ||
'skipBinding': [ | ||
'global_object_delete_property', | ||
'global_object_get_property', | ||
'global_object_has_own_property', | ||
'global_object_set_property', | ||
] | ||
}; |
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,41 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const listOfTestModules = require('./listOfTestModules'); | ||
const exceptions = require('./exceptions'); | ||
const generateFileContent = require('./binding-file-template').generateFileContent; | ||
|
||
const buildDirs = listOfTestModules.dirs; | ||
const buildFiles = listOfTestModules.files; | ||
|
||
function generateBindingConfigurations() { | ||
const configs = []; | ||
|
||
const testFilesToBind = process.argv.slice(2); | ||
console.log('test modules to bind: ', testFilesToBind); | ||
|
||
testFilesToBind.forEach((file) => { | ||
const configName = file.split('.cc')[0]; | ||
|
||
if (buildDirs[configName]) { | ||
for (let file of buildDirs[configName]) { | ||
if (exceptions.skipBinding.includes(file)) continue; | ||
configs.push(buildFiles[file]); | ||
} | ||
} else if (buildFiles[configName]) { | ||
configs.push(buildFiles[configName]); | ||
} else { | ||
console.log('not found', file, configName); | ||
} | ||
}); | ||
|
||
return Promise.resolve(configs); | ||
} | ||
|
||
function writeToBindingFile(content) { | ||
const generatedFilePath = path.join(__dirname, 'generated', 'binding.cc' ); | ||
fs.writeFileSync(generatedFilePath , "" ); | ||
fs.writeFileSync(generatedFilePath, content, { flag: "a" } ); | ||
console.log('generated binding file ', generatedFilePath, new Date()); | ||
} | ||
|
||
generateBindingConfigurations().then(generateFileContent).then(writeToBindingFile); |
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,69 @@ | ||
const fs = require('fs'); | ||
const listOfTestModules = require('./listOfTestModules'); | ||
|
||
const buildDirs = listOfTestModules.dirs; | ||
const buildFiles = listOfTestModules.files; | ||
|
||
module.exports.filesToCompile = function () { | ||
const filterCondition = require('./matchModules').matchWildCards(process.env.filter || ''); | ||
let files_to_compile = './generated/binding.cc test_helper.h'; | ||
let conditions = filterCondition.split(' ').length ? filterCondition.split(' ') : [filterCondition]; | ||
let files = []; | ||
|
||
for (let matchCondition of conditions) { | ||
if (buildDirs[matchCondition.toLowerCase()]) { | ||
for (let file of buildDirs[matchCondition.toLowerCase()] ) { | ||
const config = buildFiles[file]; | ||
const separator = config.dir.length ? '/' : '' | ||
files.push(config.dir + separator + file); | ||
} | ||
} else if (buildFiles[matchCondition.toLowerCase()]) { | ||
const config = buildFiles[matchCondition.toLowerCase()]; | ||
const separator = config.dir.length ? '/' : '' | ||
files.push(config.dir + separator + matchCondition.toLowerCase()); | ||
} | ||
} | ||
|
||
let addedFiles = ''; | ||
files.forEach((file) => { | ||
addedFiles = `${addedFiles} ../test/${file}.cc`; | ||
}); | ||
fs.writeFileSync(__dirname + '/generated/compilelist', `${files_to_compile} ${addedFiles}`); | ||
return `${files_to_compile} ${addedFiles}`; | ||
}; | ||
|
||
module.exports.filesForBinding = function () { | ||
const filterCondition = require('./matchModules').matchWildCards(process.env.filter || ''); | ||
fs.writeFileSync(__dirname + '/generated/bindingList', filterCondition); | ||
return filterCondition; | ||
}; | ||
|
||
|
||
if (require.main === module) { | ||
const assert = require('assert'); | ||
|
||
const setEnvAndCall = (fn, filterCondition) => { process.env.filter = filterCondition; return fn(); }; | ||
|
||
assert.strictEqual(setEnvAndCall(exports.filesToCompile, 'typed*ex*'), './generated/binding.cc test_helper.h ../test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc'); | ||
|
||
const expectedFilesToMatch = [ | ||
'./generated/binding.cc test_helper.h ', | ||
'../test/threadsafe_function/threadsafe_function.cc', | ||
'../test/threadsafe_function/threadsafe_function_ctx.cc', | ||
'../test/threadsafe_function/threadsafe_function_existing_tsfn.cc', | ||
'../test/threadsafe_function/threadsafe_function_ptr.cc', | ||
'../test/threadsafe_function/threadsafe_function_sum.cc', | ||
'../test/threadsafe_function/threadsafe_function_unref.cc', | ||
'../test/typed_threadsafe_function/typed_threadsafe_function.cc', | ||
'../test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc', | ||
'../test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc', | ||
'../test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc', | ||
'../test/typed_threadsafe_function/typed_threadsafe_function_sum.cc', | ||
'../test/typed_threadsafe_function/typed_threadsafe_function_unref.cc' | ||
] | ||
assert.strictEqual(setEnvAndCall(exports.filesToCompile, 'threadsafe_function typed_threadsafe_function'), expectedFilesToMatch.join(' ')); | ||
|
||
assert.strictEqual(setEnvAndCall(exports.filesToCompile, 'objectwrap'), './generated/binding.cc test_helper.h ../test/objectwrap.cc'); | ||
|
||
console.log('ALL tests passed') | ||
} |
Oops, something went wrong.