2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Simple tool to generate NMF file by just reformatting given arguments.
8 This tool is similar to native_client_sdk/src/tools/create_nmf.py.
9 create_nmf.py handles most cases, with the exception of Non-SFI nexes.
10 create_nmf.py tries to auto-detect nexe and pexe types based on their contents,
11 but it does not work for Non-SFI nexes (which don't have a marker to
12 distinguish them from SFI nexes).
14 This script simply reformats the command line arguments into NMF JSON format.
25 _PORTABLE_KEY
= 'portable'
26 _PROGRAM_KEY
= 'program'
30 parser
= argparse
.ArgumentParser()
32 '--program', metavar
='FILE', help='Main program nexe')
34 '--arch', metavar
='ARCH', choices
=('x86-32', 'arm'),
35 help='The archtecture of main program nexe')
36 # To keep compatibility with create_nmf.py, we use -x and --extra-files
39 '-x', '--extra-files', action
='append', metavar
='KEY:FILE', default
=[],
40 help=('Add extra key:file tuple to the "files" '
41 'section of the .nmf'))
43 '--output', metavar
='FILE', help='Path to the output nmf file.')
45 return parser
.parse_args()
48 def BuildNmfMap(root_path
, program
, arch
, extra_files
):
49 """Build simple map representing nmf json."""
50 nonsfi_key
= arch
+ '-nonsfi'
54 # The program path is relative to the root_path.
55 _URL_KEY
: os
.path
.relpath(program
, root_path
)
62 for named_file
in extra_files
:
63 name
, path
= named_file
.split(':', 1)
66 # Note: use path as is, unlike program path.
71 result
[_FILES_KEY
] = files
76 def OutputNmf(nmf_map
, output_path
):
77 """Writes the nmf to an output file at given path in JSON format."""
78 with
open(output_path
, 'w') as output
:
79 json
.dump(nmf_map
, output
, indent
=2)
85 logging
.error('--program is not specified.')
88 logging
.error('--arch is not specified.')
91 logging
.error('--output is not specified.')
94 nmf_map
= BuildNmfMap(os
.path
.dirname(args
.output
),
95 args
.program
, args
.arch
, args
.extra_files
)
96 OutputNmf(nmf_map
, args
.output
)
99 if __name__
== '__main__':