| Index: tools/js2c.py
|
| diff --git a/tools/js2c.py b/tools/js2c.py
|
| index 3e56667552721d1b4e478593f67a4bb754fa7a02..bda4656ea09497cd6a65a746683408702819b204 100755
|
| --- a/tools/js2c.py
|
| +++ b/tools/js2c.py
|
| @@ -397,7 +397,7 @@ def PrepareSources(source_files):
|
| return result
|
|
|
|
|
| -def BuildMetadata(sources, source_bytes, native_type):
|
| +def BuildMetadata(sources, source_bytes, native_type, omit):
|
| """Build the meta data required to generate a libaries file.
|
|
|
| Args:
|
| @@ -405,6 +405,7 @@ def BuildMetadata(sources, source_bytes, native_type):
|
| source_bytes: A list of source bytes.
|
| (The concatenation of all sources; might be compressed.)
|
| native_type: The parameter for the NativesCollection template.
|
| + omit: bool, whether we should omit the sources in the output.
|
|
|
| Returns:
|
| A dictionary for use with HEADER_TEMPLATE.
|
| @@ -437,7 +438,7 @@ def BuildMetadata(sources, source_bytes, native_type):
|
| assert offset == len(raw_sources)
|
|
|
| # If we have the raw sources we can declare them accordingly.
|
| - have_raw_sources = source_bytes == raw_sources
|
| + have_raw_sources = source_bytes == raw_sources and not omit
|
| raw_sources_declaration = (RAW_SOURCES_DECLARATION
|
| if have_raw_sources else RAW_SOURCES_COMPRESSION_DECLARATION)
|
|
|
| @@ -445,6 +446,7 @@ def BuildMetadata(sources, source_bytes, native_type):
|
| "builtin_count": len(sources.modules),
|
| "debugger_count": sum(sources.is_debugger_id),
|
| "sources_declaration": SOURCES_DECLARATION % ToCArray(source_bytes),
|
| + "sources_data": ToCArray(source_bytes) if not omit else "",
|
| "raw_sources_declaration": raw_sources_declaration,
|
| "raw_total_length": sum(map(len, sources.modules)),
|
| "total_length": total_length,
|
| @@ -475,51 +477,10 @@ def CompressMaybe(sources, compression_type):
|
| raise Error("Unknown compression type %s." % compression_type)
|
|
|
|
|
| -def PutInt(blob_file, value):
|
| - assert(value >= 0 and value < (1 << 20))
|
| - size = 1 if (value < 1 << 6) else (2 if (value < 1 << 14) else 3)
|
| - value_with_length = (value << 2) | size
|
| -
|
| - byte_sequence = bytearray()
|
| - for i in xrange(size):
|
| - byte_sequence.append(value_with_length & 255)
|
| - value_with_length >>= 8;
|
| - blob_file.write(byte_sequence)
|
| -
|
| -
|
| -def PutStr(blob_file, value):
|
| - PutInt(blob_file, len(value));
|
| - blob_file.write(value);
|
| -
|
| -
|
| -def WriteStartupBlob(sources, startup_blob):
|
| - """Write a startup blob, as expected by V8 Initialize ...
|
| - TODO(vogelheim): Add proper method name.
|
| -
|
| - Args:
|
| - sources: A Sources instance with the prepared sources.
|
| - startup_blob_file: Name of file to write the blob to.
|
| - """
|
| - output = open(startup_blob, "wb")
|
| -
|
| - debug_sources = sum(sources.is_debugger_id);
|
| - PutInt(output, debug_sources)
|
| - for i in xrange(debug_sources):
|
| - PutStr(output, sources.names[i]);
|
| - PutStr(output, sources.modules[i]);
|
| -
|
| - PutInt(output, len(sources.names) - debug_sources)
|
| - for i in xrange(debug_sources, len(sources.names)):
|
| - PutStr(output, sources.names[i]);
|
| - PutStr(output, sources.modules[i]);
|
| -
|
| - output.close()
|
| -
|
| -
|
| -def JS2C(source, target, native_type, compression_type, raw_file, startup_blob):
|
| +def JS2C(source, target, native_type, compression_type, raw_file, omit):
|
| sources = PrepareSources(source)
|
| sources_bytes = CompressMaybe(sources, compression_type)
|
| - metadata = BuildMetadata(sources, sources_bytes, native_type)
|
| + metadata = BuildMetadata(sources, sources_bytes, native_type, omit)
|
|
|
| # Optionally emit raw file.
|
| if raw_file:
|
| @@ -527,9 +488,6 @@ def JS2C(source, target, native_type, compression_type, raw_file, startup_blob):
|
| output.write(sources_bytes)
|
| output.close()
|
|
|
| - if startup_blob:
|
| - WriteStartupBlob(sources, startup_blob);
|
| -
|
| # Emit resulting source file.
|
| output = open(target, "w")
|
| output.write(HEADER_TEMPLATE % metadata)
|
| @@ -539,9 +497,9 @@ def JS2C(source, target, native_type, compression_type, raw_file, startup_blob):
|
| def main():
|
| parser = optparse.OptionParser()
|
| parser.add_option("--raw", action="store",
|
| - help="file to write the processed sources array to.")
|
| - parser.add_option("--startup_blob", action="store",
|
| - help="file to write the startup blob to.")
|
| + help="file to write the processed sources array to.")
|
| + parser.add_option("--omit", dest="omit", action="store_true",
|
| + help="Omit the raw sources from the generated code.")
|
| parser.set_usage("""js2c out.cc type compression sources.js ...
|
| out.cc: C code to be generated.
|
| type: type parameter for NativesCollection template.
|
| @@ -549,7 +507,7 @@ def main():
|
| sources.js: JS internal sources or macros.py.""")
|
| (options, args) = parser.parse_args()
|
|
|
| - JS2C(args[3:], args[0], args[1], args[2], options.raw, options.startup_blob)
|
| + JS2C(args[3:], args[0], args[1], args[2], options.raw, options.omit)
|
|
|
|
|
| if __name__ == "__main__":
|
|
|