Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: tools/js2c.py

Issue 1113593002: Allow extra library files to be snapshotted (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2012 the V8 project authors. All rights reserved. 3 # Copyright 2012 the V8 project authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 # This is a utility for converting JavaScript source code into C-style 30 # This is a utility for converting JavaScript source code into C-style
31 # char arrays. It is used for embedded JavaScript code in the V8 31 # char arrays. It is used for embedded JavaScript code in the V8
32 # library. 32 # library.
33 33
34 import os, re, sys, string 34 import os, re, sys, string
35 import optparse 35 import argparse
36 import jsmin 36 import jsmin
37 import bz2 37 import bz2
38 import textwrap 38 import textwrap
39 39
40 40
41 class Error(Exception): 41 class Error(Exception):
42 def __init__(self, msg): 42 def __init__(self, msg):
43 Exception.__init__(self, msg) 43 Exception.__init__(self, msg)
44 44
45 45
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 PutStr(output, sources.modules[i]); 524 PutStr(output, sources.modules[i]);
525 525
526 PutInt(output, len(sources.names) - debug_sources) 526 PutInt(output, len(sources.names) - debug_sources)
527 for i in xrange(debug_sources, len(sources.names)): 527 for i in xrange(debug_sources, len(sources.names)):
528 PutStr(output, sources.names[i]); 528 PutStr(output, sources.names[i]);
529 PutStr(output, sources.modules[i]); 529 PutStr(output, sources.modules[i]);
530 530
531 output.close() 531 output.close()
532 532
533 533
534 def JS2C(source, target, native_type, raw_file, startup_blob): 534 def JS2C(source, extraSource, target, native_type, raw_file, startup_blob):
535 sources = PrepareSources(source) 535 # For now we treat source and extraSource the same, but we keep them separate
536 # in the input so that we can start treating them differently in the future.
537 sources = PrepareSources(source + extraSource)
536 sources_bytes = "".join(sources.modules) 538 sources_bytes = "".join(sources.modules)
537 metadata = BuildMetadata(sources, sources_bytes, native_type) 539 metadata = BuildMetadata(sources, sources_bytes, native_type)
538 540
539 # Optionally emit raw file. 541 # Optionally emit raw file.
540 if raw_file: 542 if raw_file:
541 output = open(raw_file, "w") 543 output = open(raw_file, "w")
542 output.write(sources_bytes) 544 output.write(sources_bytes)
543 output.close() 545 output.close()
544 546
545 if startup_blob: 547 if startup_blob:
546 WriteStartupBlob(sources, startup_blob); 548 WriteStartupBlob(sources, startup_blob);
547 549
548 # Emit resulting source file. 550 # Emit resulting source file.
549 output = open(target, "w") 551 output = open(target, "w")
550 output.write(HEADER_TEMPLATE % metadata) 552 output.write(HEADER_TEMPLATE % metadata)
551 output.close() 553 output.close()
552 554
553 555
554 def main(): 556 def main():
555 parser = optparse.OptionParser() 557 parser = argparse.ArgumentParser()
556 parser.add_option("--raw", action="store", 558 parser.add_argument("out.cc",
557 help="file to write the processed sources array to.") 559 help="C code to be generated")
558 parser.add_option("--startup_blob", action="store", 560 parser.add_argument("type",
559 help="file to write the startup blob to.") 561 help="type parameter for NativesCollection template")
560 parser.set_usage("""js2c out.cc type sources.js ... 562 parser.add_argument("sources.js",
561 out.cc: C code to be generated. 563 help="JS internal sources or macros.py.",
562 type: type parameter for NativesCollection template. 564 nargs="+")
563 sources.js: JS internal sources or macros.py.""") 565 parser.add_argument("--raw",
564 (options, args) = parser.parse_args() 566 help="file to write the processed sources array to.")
567 parser.add_argument("--startup_blob",
568 help="file to write the startup blob to.")
569 parser.add_argument("--extra",
570 help="extra JS sources.",
571 nargs="*")
565 572
566 JS2C(args[2:], args[0], args[1], options.raw, options.startup_blob) 573 args = vars(parser.parse_args())
574 JS2C(args["sources.js"], args["extra"] or [], args["out.cc"], args["type"], ar gs["raw"], args["startup_blob"])
567 575
568 576
569 if __name__ == "__main__": 577 if __name__ == "__main__":
570 main() 578 main()
OLDNEW
« no previous file with comments | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698