2015-02-04 00:46:52 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2015-04-01 11:03:50 +00:00
|
|
|
import contextlib
|
2016-08-20 15:19:14 +00:00
|
|
|
import glob
|
2015-02-04 00:46:52 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2015-04-01 11:03:50 +00:00
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
2015-02-04 00:46:52 +00:00
|
|
|
|
2018-04-13 12:20:04 +00:00
|
|
|
TEMPLATE = """
|
|
|
|
#ifndef ATOM_NATIVES_H_
|
|
|
|
#define ATOM_NATIVES_H_
|
|
|
|
|
|
|
|
namespace node {{
|
|
|
|
|
|
|
|
{definitions}
|
|
|
|
|
|
|
|
}} // namespace node
|
|
|
|
|
|
|
|
#endif // ATOM_NATIVES_H_
|
|
|
|
"""
|
|
|
|
|
2015-02-04 00:46:52 +00:00
|
|
|
|
|
|
|
def main():
|
2015-04-01 11:03:50 +00:00
|
|
|
natives = os.path.abspath(sys.argv[1])
|
2016-08-20 15:19:14 +00:00
|
|
|
js_source_files = glob.glob('{0}/*.js'.format(sys.argv[2]))
|
2015-02-04 00:46:52 +00:00
|
|
|
|
|
|
|
call_js2c(natives, js_source_files)
|
|
|
|
|
|
|
|
|
|
|
|
def call_js2c(natives, js_source_files):
|
|
|
|
js2c = os.path.join(SOURCE_ROOT, 'vendor', 'node', 'tools', 'js2c.py')
|
2015-04-01 11:03:50 +00:00
|
|
|
src_dir = os.path.dirname(js_source_files[0])
|
|
|
|
with scoped_cwd(src_dir):
|
|
|
|
subprocess.check_call(
|
|
|
|
[sys.executable, js2c, natives] +
|
2018-04-13 12:20:04 +00:00
|
|
|
[os.path.basename(source) for source in js_source_files] +
|
|
|
|
['-t', TEMPLATE])
|
2015-04-01 11:03:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def scoped_cwd(path):
|
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(path)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(cwd)
|
2015-02-04 00:46:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|