-
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
Oct 15, 2021
1 parent
71494a4
commit 2fc9d73
Showing
15 changed files
with
491 additions
and
12 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); |
Oops, something went wrong.