| Index: Source/build/scripts/make_blink_in_javascript.py
|
| diff --git a/Source/build/scripts/xxd.py b/Source/build/scripts/make_blink_in_javascript.py
|
| old mode 100755
|
| new mode 100644
|
| similarity index 58%
|
| copy from Source/build/scripts/xxd.py
|
| copy to Source/build/scripts/make_blink_in_javascript.py
|
| index 858236c9a63b88449bfb0cf7ffbc771c10360046..a6b0cfc059c3095c878aafbe400ed2d1384df8c2
|
| --- a/Source/build/scripts/xxd.py
|
| +++ b/Source/build/scripts/make_blink_in_javascript.py
|
| @@ -26,24 +26,37 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -"""Represent a file as a C++ constant string.
|
| +"""Convert Blink-in-JavaScript sources to C++ constant strings.
|
|
|
| Usage:
|
| -python xxd.py VAR SOURCE DEST
|
| +python make_blink_in_javascript.py DESTINATION_FILE SOURCE_FILES
|
| """
|
|
|
| +import os
|
| import sys
|
|
|
|
|
| def main():
|
| - variable_name, input_filename, output_filename = sys.argv[1:]
|
| - with open(input_filename) as input_file:
|
| - input_text = input_file.read()
|
| - hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text]
|
| - const_declaration = 'const unsigned char %s[] = {\n%s\n};\n' % (
|
| - variable_name, ', '.join(hex_values))
|
| + output_filename = sys.argv[1]
|
| + input_filenames = sys.argv[2:]
|
| + contents = ''
|
| + for input_filename in input_filenames:
|
| + class_name, ext = os.path.splitext(os.path.basename(input_filename))
|
| + with open(input_filename) as input_file:
|
| + input_text = input_file.read()
|
| + hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text]
|
| + contents += 'const unsigned char kSourceOf%s[] = {\n %s\n};\n' % (
|
| + class_name, ', '.join(hex_values))
|
| +
|
| + contents += '\nstruct BlinkInJavaScriptSources {\n const char* name;\n const unsigned char* source;\n size_t size;\n};\n\n'
|
| + contents += 'struct BlinkInJavaScriptSources kBlinkInJavaScriptSources[] = {\n'
|
| + for input_filename in input_filenames:
|
| + class_name, ext = os.path.splitext(os.path.basename(input_filename))
|
| + contents += ' { "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (class_name, class_name, class_name)
|
| + contents += '};\n'
|
| +
|
| with open(output_filename, 'w') as output_file:
|
| - output_file.write(const_declaration)
|
| + output_file.write(contents)
|
|
|
|
|
| if __name__ == '__main__':
|
|
|