fix, compact, refactor
This commit is contained in:
parent
7a64bdce34
commit
1ce2fcee9b
101
README.md
101
README.md
|
@ -6,7 +6,7 @@
|
||||||
This is a set of helpers for simplification and standardization of addons and
|
This is a set of helpers for simplification and standardization of addons and
|
||||||
dependency packages.
|
dependency packages.
|
||||||
|
|
||||||
* Contains helpers of following types: GYP, C++, JS, BAT(Windows).
|
* Contains helpers of following types: GYP, C++, JS, BAT (Windows).
|
||||||
* Platforms: win x32/x64, linux x32/x64, mac x64.
|
* Platforms: win x32/x64, linux x32/x64, mac x64.
|
||||||
* Useful links: [V8 Ref](https://v8docs.nodesource.com/node-0.8/d2/dc3/namespacev8.html),
|
* Useful links: [V8 Ref](https://v8docs.nodesource.com/node-0.8/d2/dc3/namespacev8.html),
|
||||||
[Nan Docs](https://github.com/nodejs/nan#api),
|
[Nan Docs](https://github.com/nodejs/nan#api),
|
||||||
|
@ -28,7 +28,7 @@ dependency packages.
|
||||||
|
|
||||||
[index.js](#indexjs)
|
[index.js](#indexjs)
|
||||||
|
|
||||||
[Crossplatform commands](#crossplatform-commands)
|
[Cross-platform commands](#cross-platform-commands)
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -38,12 +38,13 @@ dependency packages.
|
||||||
|
|
||||||
### binding.gyp
|
### binding.gyp
|
||||||
|
|
||||||
* For Windows custom file/folder removers/creators are present, you can put them into variables.
|
* Cross-platform file/folder removers/creators are present, you can put them into variables for later use.
|
||||||
|
|
||||||
```
|
```
|
||||||
'variables': {
|
'variables': {
|
||||||
'rmrf' : '<!(node -e "console.log(require(\'addon-tools-raub\').rmrf)")',
|
'rm' : '<!(node -e "console.log(require(\'addon-tools-raub\').rm)")',
|
||||||
'mkdirp' : '<!(node -e "console.log(require(\'addon-tools-raub\').mkdirp)")',
|
'cp' : '<!(node -e "console.log(require(\'addon-tools-raub\').cp)")',
|
||||||
|
'mkdir' : '<!(node -e "console.log(require(\'addon-tools-raub\').mkdir)")',
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -52,27 +53,25 @@ are accessible as shown below.
|
||||||
|
|
||||||
```
|
```
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'<!(node -e "require(\'addon-tools-raub\').printNan()")',
|
'<!@(node -e "require(\'addon-tools-raub\').include()")',
|
||||||
'<!(node -e "console.log(require(\'addon-tools-raub\').include)")',
|
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
* Intermediate files can be removed in a separate build-step with `rm` on
|
* Intermediate files can be removed in a separate build-step with `<(rm)`.
|
||||||
Unix systems and custom remover on Windows.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
[ 'OS=="linux"', { 'action' : [
|
[ 'OS=="linux"', { 'action' : [
|
||||||
'rm',
|
'<(rm)',
|
||||||
'<(module_root_dir)/build/Release/obj.target/addon/cpp/addon.o',
|
'<(module_root_dir)/build/Release/obj.target/addon/cpp/addon.o',
|
||||||
'<(module_root_dir)/build/Release/addon.node'
|
'<(module_root_dir)/build/Release/addon.node'
|
||||||
] } ],
|
] } ],
|
||||||
[ 'OS=="mac"', { 'action' : [
|
[ 'OS=="mac"', { 'action' : [
|
||||||
'rm',
|
'<(rm)',
|
||||||
'<(module_root_dir)/build/Release/obj.target/addon/cpp/addon.o',
|
'<(module_root_dir)/build/Release/obj.target/addon/cpp/addon.o',
|
||||||
'<(module_root_dir)/build/Release/addon.node'
|
'<(module_root_dir)/build/Release/addon.node'
|
||||||
] } ],
|
] } ],
|
||||||
[ 'OS=="win"', { 'action' : [
|
[ 'OS=="win"', { 'action' : [
|
||||||
'<(_del)',
|
'<(rm)',
|
||||||
'<(module_root_dir)/build/Release/addon.*',
|
'<(module_root_dir)/build/Release/addon.*',
|
||||||
'<(module_root_dir)/build/Release/obj/addon/*.*'
|
'<(module_root_dir)/build/Release/obj/addon/*.*'
|
||||||
] } ],
|
] } ],
|
||||||
|
@ -103,7 +102,7 @@ module.exports = require('addon-tools-raub').paths(__dirname);
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
'variables': {
|
'variables': {
|
||||||
'_rd' : '<!(node -e "console.log(require(\'addon-tools-raub\')._rd)")',
|
'rm' : '<!(node -e "console.log(require(\'addon-tools-raub\').rm)")',
|
||||||
'rem' : '<!(node -e "console.log(require(\'.\').rem)")',
|
'rem' : '<!(node -e "console.log(require(\'.\').rem)")',
|
||||||
},
|
},
|
||||||
'targets': [
|
'targets': [
|
||||||
|
@ -113,17 +112,12 @@ module.exports = require('addon-tools-raub').paths(__dirname);
|
||||||
'actions' : [
|
'actions' : [
|
||||||
{
|
{
|
||||||
'action_name' : 'Unnecessary binaries removed.',
|
'action_name' : 'Unnecessary binaries removed.',
|
||||||
'inputs' : ['<@(rem)'],
|
'inputs' : [],
|
||||||
'outputs' : ['build'],
|
'outputs' : ['build'],
|
||||||
'conditions' : [
|
'action' : ['<(rm)', '-rf', '<@(rem)'],
|
||||||
[ 'OS=="linux"', { 'action' : [ 'rm', '-rf', '<@(_inputs)' ] } ],
|
|
||||||
[ 'OS=="mac"' , { 'action' : [ 'rm', '-rf', '<@(_inputs)' ] } ],
|
|
||||||
[ 'OS=="win"' , { 'action' : [ '<(_rd)', '<@(_inputs)' ] } ],
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,11 +139,7 @@ If you always copy your compiled addon to the `binary` directory, it will be eas
|
||||||
'action_name' : 'Directory created.',
|
'action_name' : 'Directory created.',
|
||||||
'inputs' : [],
|
'inputs' : [],
|
||||||
'outputs' : ['build'],
|
'outputs' : ['build'],
|
||||||
'conditions' : [
|
'action': ['<(mkdir)', '-p', 'binary']
|
||||||
[ 'OS=="linux"', { 'action': ['mkdir', '-p', 'binary'] } ],
|
|
||||||
[ 'OS=="mac"', { 'action': ['mkdir', '-p', 'binary'] } ],
|
|
||||||
[ 'OS=="win"', { 'action': ['<(_md)', 'binary'] } ],
|
|
||||||
],
|
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -160,23 +150,7 @@ If you always copy your compiled addon to the `binary` directory, it will be eas
|
||||||
'action_name' : 'Module copied.',
|
'action_name' : 'Module copied.',
|
||||||
'inputs' : [],
|
'inputs' : [],
|
||||||
'outputs' : ['binary'],
|
'outputs' : ['binary'],
|
||||||
'conditions' : [
|
'action' : ['<(cp)', 'build/Release/MY_ADDON.node', 'binary/MY_ADDON.node'],
|
||||||
[ 'OS=="linux"', { 'action' : [
|
|
||||||
'cp',
|
|
||||||
'<(module_root_dir)/build/Release/MY_ADDON.node',
|
|
||||||
'<(module_root_dir)/binary/MY_ADDON.node'
|
|
||||||
] } ],
|
|
||||||
[ 'OS=="mac"', { 'action' : [
|
|
||||||
'cp',
|
|
||||||
'<(module_root_dir)/build/Release/MY_ADDON.node',
|
|
||||||
'<(module_root_dir)/binary/MY_ADDON.node'
|
|
||||||
] } ],
|
|
||||||
[ 'OS=="win"', { 'action' : [
|
|
||||||
'copy',
|
|
||||||
'<(module_root_dir)/build/Release/MY_ADDON.node' +
|
|
||||||
'<(module_root_dir)/binary/MY_ADDON.node'
|
|
||||||
] } ],
|
|
||||||
],
|
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
@ -201,8 +175,9 @@ module.exports = require('./binary/addon');
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
'variables': {
|
'variables': {
|
||||||
'_del' : '<!(node -e "console.log(require(\'addon-tools-raub\')._del)")',
|
'rm' : '<!(node -e "console.log(require(\'addon-tools-raub\').rm)")',
|
||||||
'_md' : '<!(node -e "console.log(require(\'addon-tools-raub\')._md)")',
|
'cp' : '<!(node -e "console.log(require(\'addon-tools-raub\').cp)")',
|
||||||
|
'mkdir' : '<!(node -e "console.log(require(\'addon-tools-raub\').mkdir)")',
|
||||||
'EXT_LIB_include' : '<!(node -e "console.log(require(\'node-deps-EXT_LIB-raub\').include)")',
|
'EXT_LIB_include' : '<!(node -e "console.log(require(\'node-deps-EXT_LIB-raub\').include)")',
|
||||||
'EXT_LIB_bin' : '<!(node -e "console.log(require(\'node-deps-EXT_LIB-raub\').bin)")',
|
'EXT_LIB_bin' : '<!(node -e "console.log(require(\'node-deps-EXT_LIB-raub\').bin)")',
|
||||||
},
|
},
|
||||||
|
@ -210,12 +185,10 @@ module.exports = require('./binary/addon');
|
||||||
{
|
{
|
||||||
'target_name': 'MY_ADDON',
|
'target_name': 'MY_ADDON',
|
||||||
'sources': [
|
'sources': [
|
||||||
'cpp/bindings.cpp',
|
|
||||||
'cpp/MY_ADDON.cpp',
|
'cpp/MY_ADDON.cpp',
|
||||||
],
|
],
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'<!(node -e "require(\'addon-tools-raub\').printNan()")',
|
'<!(node -e "require(\'addon-tools-raub\').include()")',
|
||||||
'<!(node -e "console.log(require(\'addon-tools-raub\').include)")',
|
|
||||||
'<(EXT_LIB_include)',
|
'<(EXT_LIB_include)',
|
||||||
'<(module_root_dir)/include',
|
'<(module_root_dir)/include',
|
||||||
],
|
],
|
||||||
|
@ -263,6 +236,7 @@ module.exports = require('./binary/addon');
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
'target_name' : 'make_directory',
|
'target_name' : 'make_directory',
|
||||||
'type' : 'none',
|
'type' : 'none',
|
||||||
|
@ -271,11 +245,7 @@ module.exports = require('./binary/addon');
|
||||||
'action_name' : 'Directory created.',
|
'action_name' : 'Directory created.',
|
||||||
'inputs' : [],
|
'inputs' : [],
|
||||||
'outputs' : ['build'],
|
'outputs' : ['build'],
|
||||||
'conditions' : [
|
'action': ['<(mkdir)', '-p', 'binary']
|
||||||
[ 'OS=="linux"', { 'action': ['mkdir', '-p', 'binary'] } ],
|
|
||||||
[ 'OS=="mac"', { 'action': ['mkdir', '-p', 'binary'] } ],
|
|
||||||
[ 'OS=="win"', { 'action': ['<(_md)', 'binary'] } ],
|
|
||||||
],
|
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -286,22 +256,7 @@ module.exports = require('./binary/addon');
|
||||||
'action_name' : 'Module copied.',
|
'action_name' : 'Module copied.',
|
||||||
'inputs' : [],
|
'inputs' : [],
|
||||||
'outputs' : ['binary'],
|
'outputs' : ['binary'],
|
||||||
'conditions' : [
|
'action' : ['<(cp)', 'build/Release/MY_ADDON.node', 'binary/MY_ADDON.node'],
|
||||||
[ 'OS=="linux"', { 'action' : [
|
|
||||||
'cp',
|
|
||||||
'<(module_root_dir)/build/Release/MY_ADDON.node',
|
|
||||||
'<(module_root_dir)/binary/MY_ADDON.node'
|
|
||||||
] } ],
|
|
||||||
[ 'OS=="mac"', { 'action' : [
|
|
||||||
'cp',
|
|
||||||
'<(module_root_dir)/build/Release/MY_ADDON.node',
|
|
||||||
'<(module_root_dir)/binary/MY_ADDON.node'
|
|
||||||
] } ],
|
|
||||||
[ 'OS=="win"', { 'action' : [
|
|
||||||
'copy "<(module_root_dir)/build/Release/MY_ADDON.node"' +
|
|
||||||
' "<(module_root_dir)/binary/MY_ADDON.node"'
|
|
||||||
] } ],
|
|
||||||
],
|
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -532,9 +487,11 @@ input `dir`.
|
||||||
* `rem` - a space-separated list of binary paths to be cleaned on this platform.
|
* `rem` - a space-separated list of binary paths to be cleaned on this platform.
|
||||||
* `include` - include directory for this `dir`.
|
* `include` - include directory for this `dir`.
|
||||||
* `root` - where `'addon-tools-raub'` module is situated.
|
* `root` - where `'addon-tools-raub'` module is situated.
|
||||||
* `include` - `'addon-tools-raub'` own 'include' directory.
|
* `include()` - prints both `'addon-tools-raub'` and `'nan'` include paths. Use with
|
||||||
* `rmrf` - the location of `'rmrf.bat'` file.
|
`node -e` through list context command expansion `<!@(...)`
|
||||||
* `mkdirp` - the location of `'mkdirp.bat'` file.
|
* `rm` - the location of `'_rm.bat'` file on Windows and plain `rm` on Unix.
|
||||||
|
* `cp` - the location of `'_cp.bat'` file on Windows and plain `cp` on Unix.
|
||||||
|
* `mkdir` - the location of `'_mkdir.bat'` file on Windows and plain `mkdir` on Unix.
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
for %%x in (%*) do (
|
for %%x in (%*) do (
|
||||||
|
|
||||||
if %%x=="-p" goto continue
|
if not %%x=="-p" if not exist %%x md %%x
|
||||||
|
|
||||||
if not exist %%x md %%x
|
|
||||||
|
|
||||||
:continue
|
|
||||||
rem
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
11
_rm.bat
11
_rm.bat
|
@ -1,13 +1,6 @@
|
||||||
for %%x in (%*) do (
|
for %%x in (%*) do (
|
||||||
|
|
||||||
if %%x=="-r" goto continue
|
if not %%x=="-rf" if not %%x=="-r" if not %%x=="-f" if exist %%~x\ rd /s /q %%x
|
||||||
if %%x=="-f" goto continue
|
if not %%x=="-rf" if not %%x=="-r" if not %%x=="-f" if not exist %%~x\ if exist %%x del /f /q %%x
|
||||||
if %%x=="-rf" goto continue
|
|
||||||
|
|
||||||
if exist %%~x\ rd /s /q %%x
|
|
||||||
if not exist %%~x\ if exist %%x del /f /q %%x
|
|
||||||
|
|
||||||
:continue
|
|
||||||
rem
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
15
index.js
15
index.js
|
@ -1,8 +1,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
|
||||||
const thisDir = __dirname.replace(/\\/g, '/');
|
const thisDir = __dirname.replace(/\\/g, '/');
|
||||||
|
|
||||||
|
const nanInclude = path.dirname(require.resolve('nan')).replace(/\\/g, '/');
|
||||||
|
const thisInclude = `${thisDir}/include`;
|
||||||
|
|
||||||
|
|
||||||
const names = ['win32', 'win64', 'linux32', 'linux64', 'mac64'];
|
const names = ['win32', 'win64', 'linux32', 'linux64', 'mac64'];
|
||||||
|
|
||||||
const prefixName = name => `bin-${name}`;
|
const prefixName = name => `bin-${name}`;
|
||||||
|
@ -16,8 +22,8 @@ const getPlatformDir = platform => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentDir = prefixName(getPlatformDir(process.platform));
|
|
||||||
|
|
||||||
|
const currentDir = prefixName(getPlatformDir(process.platform));
|
||||||
const remDirs = names.map(prefixName).filter(n => n !== currentDir);
|
const remDirs = names.map(prefixName).filter(n => n !== currentDir);
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,12 +51,11 @@ module.exports = {
|
||||||
paths,
|
paths,
|
||||||
|
|
||||||
root : thisDir,
|
root : thisDir,
|
||||||
include : `${thisDir}/include`,
|
|
||||||
|
|
||||||
printNan() { require('nan'); },
|
include() { console.log(`${nanInclude} ${thisInclude}`); },
|
||||||
|
|
||||||
mkdir : process.platform === 'win32' ? `${thisDir}/_mkdir.bat` : 'mkdir',
|
mkdir : process.platform === 'win32' ? `${thisDir}/_mkdir.bat` : 'mkdir',
|
||||||
rm : process.platform === 'win32' ? `${thisDir}/_rm.bat` : 'rm',
|
rm : process.platform === 'win32' ? `${thisDir}/_rm.bat` : 'rm',
|
||||||
cp : process.platform === 'win32' ? `${thisDir}/_cp.bat` : 'cp',
|
cp : process.platform === 'win32' ? `${thisDir}/_cp.bat` : 'cp',
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue