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

Unified Diff: tools/js2c.py

Issue 1130993003: Reland: Make V8 extras a separate type of native (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@fix-snapshot
Patch Set: Fix js2c.py's dummy files 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gyp/v8.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/js2c.py
diff --git a/tools/js2c.py b/tools/js2c.py
index 243f5dd58e20eb6ba04bab6970af53a915aaa459..788b2e74d24729cdfa5782dae2a03fd50b705896 100755
--- a/tools/js2c.py
+++ b/tools/js2c.py
@@ -340,9 +340,9 @@ def BuildFilterChain(macro_filename, message_template_file):
macro_filename: Name of the macro file, if any.
Returns:
- A function (string -> string) that reads a source file and processes it.
+ A function (string -> string) that processes a source file.
"""
- filter_chain = [ReadFile]
+ filter_chain = []
if macro_filename:
(consts, macros) = ReadMacros(ReadFile(macro_filename))
@@ -367,7 +367,7 @@ def BuildFilterChain(macro_filename, message_template_file):
return reduce(chain, filter_chain)
def BuildExtraFilterChain():
- return lambda x: RemoveCommentsAndTrailingWhitespace(Validate(ReadFile(x)))
+ return lambda x: RemoveCommentsAndTrailingWhitespace(Validate(x))
class Sources:
def __init__(self):
@@ -386,14 +386,14 @@ def IsMessageTemplateFile(filename):
return filename.endswith("messages.h")
-def PrepareSources(source_files, extra_files, emit_js):
+def PrepareSources(source_files, native_type, emit_js):
"""Read, prepare and assemble the list of source files.
Args:
source_files: List of JavaScript-ish source files. A file named macros.py
will be treated as a list of macros.
- extra_files: List of JavaScript-ish extra source files, passed in
- externally from V8. Will not be minified or macro-ified.
+ native_type: String corresponding to a NativeType enum value, allowing us
+ to treat different types of sources differently.
emit_js: True if we should skip the byte conversion and just leave the
sources as JS strings.
@@ -414,18 +414,30 @@ def PrepareSources(source_files, extra_files, emit_js):
source_files.remove(message_template_files[0])
message_template_file = message_template_files[0]
- filters = BuildFilterChain(macro_file, message_template_file)
- extra_filters = BuildExtraFilterChain()
+ filters = None
+ if native_type == "EXTRA":
+ filters = BuildExtraFilterChain()
+ else:
+ filters = BuildFilterChain(macro_file, message_template_file)
# Sort 'debugger' sources first.
source_files = sorted(source_files,
lambda l,r: IsDebuggerFile(r) - IsDebuggerFile(l))
+ source_files_and_contents = [(f, ReadFile(f)) for f in source_files]
+
+ # Have a single not-quite-empty source file if there are none present;
+ # otherwise you get errors trying to compile an empty C++ array.
+ # It cannot be empty (or whitespace, which gets trimmed to empty), as
+ # the deserialization code assumes each file is nonempty.
+ if not source_files_and_contents:
+ source_files_and_contents = [("dummy.js", "void 0;")]
+
result = Sources()
- for source in source_files:
+ for (source, contents) in source_files_and_contents:
try:
- lines = filters(source)
+ lines = filters(contents)
except Error as e:
raise Error("In file %s:\n%s" % (source, str(e)))
@@ -437,16 +449,6 @@ def PrepareSources(source_files, extra_files, emit_js):
name = os.path.basename(source)[:-3]
result.names.append(name if not is_debugger else name[:-9])
- for extra in extra_files:
- try:
- lines = extra_filters(extra)
- except Error as e:
- raise Error("In file %s:\n%s" % (extra, str(e)))
-
- result.modules.append(lines)
- name = os.path.basename(extra)[:-3]
- result.names.append(name)
-
return result
@@ -550,8 +552,8 @@ def WriteStartupBlob(sources, startup_blob):
output.close()
-def JS2C(sources, extra_sources, target, native_type, raw_file, startup_blob, emitJS):
- prepared_sources = PrepareSources(sources, extra_sources, emitJS)
+def JS2C(sources, target, native_type, raw_file, startup_blob, emit_js):
+ prepared_sources = PrepareSources(sources, native_type, emit_js)
sources_output = "".join(prepared_sources.modules)
metadata = BuildMetadata(prepared_sources, sources_output, native_type)
@@ -566,7 +568,7 @@ def JS2C(sources, extra_sources, target, native_type, raw_file, startup_blob, em
# Emit resulting source file.
output = open(target, "w")
- if emitJS:
+ if emit_js:
output.write(sources_output)
else:
output.write(HEADER_TEMPLATE % metadata)
@@ -578,24 +580,21 @@ def main():
parser.add_argument("out.cc",
help="output filename")
parser.add_argument("type",
- help="type parameter for NativesCollection template")
+ help="type parameter for NativesCollection template " +
+ "(see NativeType enum)")
parser.add_argument("sources.js",
help="JS internal sources or macros.py.",
- nargs="+")
+ nargs="*")
parser.add_argument("--raw",
help="file to write the processed sources array to.")
parser.add_argument("--startup_blob",
help="file to write the startup blob to.")
- parser.add_argument("--extra",
- help="extra JS sources.",
- nargs="*")
parser.add_argument("--js",
help="writes a JS file output instead of a C file",
action="store_true")
args = vars(parser.parse_args())
- JS2C(args["sources.js"], args["extra"] or [], args["out.cc"], args["type"], args["raw"], args["startup_blob"],
- args["js"])
+ JS2C(args["sources.js"], args["out.cc"], args["type"], args["raw"], args["startup_blob"], args["js"])
if __name__ == "__main__":
« 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