summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-03 00:49:12 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-11 06:40:09 +0800
commit44a5fe145759a2fa43247da2f40a55df23572944 (patch)
tree74c346b396e14f5da4fbc85d4a48bd974b2a3432 /tools
parent9fb4fa8ded0504f63c89ed969640e5a2df8d0d59 (diff)
downloadandroid-node-v8-44a5fe145759a2fa43247da2f40a55df23572944.tar.gz
android-node-v8-44a5fe145759a2fa43247da2f40a55df23572944.tar.bz2
android-node-v8-44a5fe145759a2fa43247da2f40a55df23572944.zip
process: specialize building and storage of process.config
Instead of treating config.gypi as a JavaScript file, specialize the processing in js2c and make the serialized result a real JSON string (with 'true' and 'false' converted to boolean values) so we don't have to use a custom deserializer during bootstrap. In addition, store the JSON string separately in NativeModuleLoader, and keep it separate from the map of the builtin source code, so we don't have to put it onto `NativeModule._source` and delete it later, though we still preserve it in `process.binding('natives')`, which we don't use anymore. This patch also makes the map of builtin source code and the config.gypi string available through side-effect-free getters in C++. PR-URL: https://github.com/nodejs/node/pull/24816 Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/js2c.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/tools/js2c.py b/tools/js2c.py
index e9a5204773..d103a3d236 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -193,6 +193,10 @@ void NativeModuleLoader::LoadJavaScriptHash() {{
{hash_initializers}
}}
+UnionBytes NativeModuleLoader::GetConfig() {{
+ return UnionBytes(config_raw, arraysize(config_raw)); // config.gypi
+}}
+
}} // namespace native_module
}} // namespace node
@@ -248,21 +252,23 @@ def JS2C(source, target):
definitions = []
initializers = []
hash_initializers = []
+ config_initializers = []
- def AddModule(module, source):
- var = '%s_raw' % (module.replace('-', '_').replace('/', '_'))
- source_hash = hashlib.sha256(source).hexdigest()
-
+ def GetDefinition(var, source):
# Treat non-ASCII as UTF-8 and convert it to UTF-16.
if any(ord(c) > 127 for c in source):
source = map(ord, source.decode('utf-8').encode('utf-16be'))
source = [source[i] * 256 + source[i+1] for i in xrange(0, len(source), 2)]
source = ToCArray(source)
- definition = TWO_BYTE_STRING.format(var=var, data=source)
+ return TWO_BYTE_STRING.format(var=var, data=source)
else:
source = ToCArray(map(ord, source), step=20)
- definition = ONE_BYTE_STRING.format(var=var, data=source)
+ return ONE_BYTE_STRING.format(var=var, data=source)
+ def AddModule(module, source):
+ var = '%s_raw' % (module.replace('-', '_').replace('/', '_'))
+ source_hash = hashlib.sha256(source).hexdigest()
+ definition = GetDefinition(var, source)
initializer = INITIALIZER.format(module=module,
var=var)
hash_initializer = HASH_INITIALIZER.format(module=module,
@@ -292,11 +298,17 @@ def JS2C(source, target):
# if its a gypi file we're going to want it as json
# later on anyway, so get it out of the way now
- if name.endswith(".gypi"):
+ if name.endswith('.gypi'):
+ # Currently only config.gypi is allowed
+ assert name == 'config.gypi'
+ lines = re.sub(r'\'true\'', 'true', lines)
+ lines = re.sub(r'\'false\'', 'false', lines)
lines = re.sub(r'#.*?\n', '', lines)
lines = re.sub(r'\'', '"', lines)
-
- AddModule(name.split('.', 1)[0], lines)
+ definition = GetDefinition('config_raw', lines)
+ definitions.append(definition)
+ else:
+ AddModule(name.split('.', 1)[0], lines)
# Add deprecated aliases for deps without 'deps/'
if deprecated_deps is not None:
@@ -306,9 +318,11 @@ def JS2C(source, target):
# Emit result
output = open(str(target[0]), "w")
- output.write(TEMPLATE.format(definitions=''.join(definitions),
- initializers=''.join(initializers),
- hash_initializers=''.join(hash_initializers)))
+ output.write(
+ TEMPLATE.format(definitions=''.join(definitions),
+ initializers=''.join(initializers),
+ hash_initializers=''.join(hash_initializers),
+ config_initializers=''.join(config_initializers)))
output.close()
def main():