| Index: Source/platform/streams/js2c.py
|
| diff --git a/Source/platform/streams/js2c.py b/Source/platform/streams/js2c.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d716404b1cca1a152a20817971cdafbb4777e229
|
| --- /dev/null
|
| +++ b/Source/platform/streams/js2c.py
|
| @@ -0,0 +1,62 @@
|
| +#!/usr/bin/env python
|
| +#
|
| +# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +
|
| +import optparse
|
| +import textwrap
|
| +
|
| +TEMPLATE = """\
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// This file was generated from .js source files by GYP. If you
|
| +// want to make changes to this file you should either change the
|
| +// javascript source files or the GYP script.
|
| +
|
| +namespace %(namespace)s {
|
| +
|
| +const char %(var_name)s[] = {
|
| +%(c_array)s
|
| +};
|
| +
|
| +} // namespace %(namespace)s
|
| +"""
|
| +
|
| +
|
| +def ToCArray(byte_sequence):
|
| + result = []
|
| + for chr in byte_sequence:
|
| + result.append(str(ord(chr)))
|
| + joined = ", ".join(result)
|
| + return textwrap.fill(joined, 80)
|
| +
|
| +
|
| +def JS2C(source, target, namespace, var_name):
|
| + input = open(source, "r")
|
| + source_bytes = input.read()
|
| +
|
| + template_params = {
|
| + "namespace": namespace,
|
| + "var_name": var_name,
|
| + "c_array": ToCArray(source_bytes)
|
| + }
|
| +
|
| + output = open(target, "wb") # don't output CRLF on Windows
|
| + output.write(TEMPLATE % template_params)
|
| + output.close()
|
| +
|
| +
|
| +parser = optparse.OptionParser()
|
| +parser.set_usage("""js2c source.js out.cpp namespace var_name
|
| + sources.js: input JS file.
|
| + out.cpp: C++ code to be generated.
|
| + namespace: namespace the array will be declared in.
|
| + varName: the name of the variable for the array.
|
| + """)
|
| +(options, args) = parser.parse_args()
|
| +
|
| +JS2C(args[0], args[1], args[2], args[3])
|
|
|