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.
24 _PORTABLE_KEY
= 'portable'
25 _PROGRAM_KEY
= 'program'
27 _X86_32_NONSFI_KEY
= 'x86-32-nonsfi'
31 parser
= argparse
.ArgumentParser()
33 '--program', metavar
='FILE', help='Main program nexe')
34 # To keep compatibility with create_nmf.py, we use -x and --extra-files
37 '-x', '--extra-files', action
='append', metavar
='KEY:FILE', default
=[],
38 help=('Add extra key:file tuple to the "files" '
39 'section of the .nmf'))
41 '--output', metavar
='FILE', help='Path to the output nmf file.')
43 return parser
.parse_args()
46 def BuildNmfMap(root_path
, program
, extra_files
):
47 """Build simple map representing nmf json."""
51 # The program path is relative to the root_path.
52 _URL_KEY
: os
.path
.relpath(program
, root_path
)
59 for named_file
in extra_files
:
60 name
, path
= named_file
.split(':', 1)
63 # Note: use path as is, unlike program path.
68 result
[_FILES_KEY
] = files
73 def OutputNmf(nmf_map
, output_path
):
74 """Writes the nmf to an output file at given path in JSON format."""
75 with
open(output_path
, 'w') as output
:
76 json
.dump(nmf_map
, output
, indent
=2)
82 logging
.error('--program is not specified.')
85 logging
.error('--output is not specified.')
88 nmf_map
= BuildNmfMap(os
.path
.dirname(args
.output
),
89 args
.program
, args
.extra_files
)
90 OutputNmf(nmf_map
, args
.output
)
93 if __name__
== '__main__':