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

Unified Diff: ppapi/tests/create_nonsfi_test_nmf.py

Issue 294593005: Introduce create_nonsfi_test_nmf.py to simplify nacl_test_data.gyp (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« ppapi/ppapi_nacl_test_common.gypi ('K') | « ppapi/ppapi_nacl_test_common.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/create_nonsfi_test_nmf.py
diff --git a/ppapi/tests/create_nonsfi_test_nmf.py b/ppapi/tests/create_nonsfi_test_nmf.py
new file mode 100755
index 0000000000000000000000000000000000000000..7f04019b102bde9496b6496b4a99ac10495da398
--- /dev/null
+++ b/ppapi/tests/create_nonsfi_test_nmf.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+# Copyright 2014 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.
+
+"""Simple tool to generate NMF file from given arguments for nonsfi."""
+
+import argparse
+import collections
+import json
+import logging
+import os
+
+_FILES_KEY = 'files'
+_PORTABLE_KEY = 'portable'
+_PROGRAM_KEY = 'program'
+_URL_KEY = 'url'
+_X86_32_NONSFI_KEY = 'x86-32-nonsfi'
+
+
+def ParseArgs():
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ '--program', metavar='FILE', help='Main program nexe')
+ # To keep compatibility with create_nmf.py, we use -x and --extra-files
+ # as flags.
+ parser.add_argument(
+ '-x', '--extra-files', action='append', metavar='KEY:FILE', default=[],
+ help=('Add extra key:file tuple to the "files" '
+ 'section of the .nmf'))
+ parser.add_argument(
+ '--output', metavar='FILE', help='Path to the output nmf file.')
+
+ return parser.parse_args()
+
+
+def BuildNmfMap(root_path, program, extra_files):
+ """Build simple map representing nmf json."""
+ result = {
+ _PROGRAM_KEY: {
+ _X86_32_NONSFI_KEY: {
+ # The program path is relative to the root_path.
+ _URL_KEY: os.path.relpath(program, root_path)
+ }
+ }
+ }
+
+ if extra_files:
+ files = {}
+ for named_file in extra_files:
+ name, path = named_file.split(':', 1)
+ files[name] = {
+ _PORTABLE_KEY: {
+ # Note: use path as is, unlike program path.
+ _URL_KEY: path
+ }
+ }
+ if files:
+ result[_FILES_KEY] = files
+
+ return result
+
+
+def OutputNmf(nmf_map, output_path):
+ """Writes the nmf to an output file at given path in JSON format."""
+ with open(output_path, 'w') as output:
+ json.dump(nmf_map, output, indent=2)
+
+
+def main():
+ args = ParseArgs()
+ if not args.program:
+ logging.error('--program is not specified.')
+ sys.exit(1)
+ if not args.output:
+ logging.error('--output is not specified.')
+ sys.exit(1)
+
+ nmf_map = BuildNmfMap(os.path.dirname(args.output),
+ args.program, args.extra_files)
+ OutputNmf(nmf_map, args.output)
+
+
+if __name__ == '__main__':
+ main()
« ppapi/ppapi_nacl_test_common.gypi ('K') | « ppapi/ppapi_nacl_test_common.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698