summaryrefslogtreecommitdiff
path: root/compiler/one-cmds/one-profile
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/one-cmds/one-profile')
-rw-r--r--compiler/one-cmds/one-profile120
1 files changed, 101 insertions, 19 deletions
diff --git a/compiler/one-cmds/one-profile b/compiler/one-cmds/one-profile
index 18a0456f4..bc5338dcc 100644
--- a/compiler/one-cmds/one-profile
+++ b/compiler/one-cmds/one-profile
@@ -26,6 +26,7 @@ import itertools
import ntpath
import os
import sys
+from types import SimpleNamespace
import onelib.utils as oneutils
@@ -92,15 +93,46 @@ def _get_parser(backends_list):
return parser
-def _verify_arg(parser, args):
+def _verify_arg(parser, args, cfg_args, backend_args, unknown_args):
"""verify given arguments"""
+ cmd_backend_exist = oneutils.is_valid_attr(args, 'backend')
+ cfg_backend_exist = oneutils.is_valid_attr(cfg_args, 'backend')
+ cfg_backends_exist = oneutils.is_valid_attr(cfg_args, 'backends')
+
# check if required arguments is given
missing = []
- if not oneutils.is_valid_attr(args, 'backend'):
+ if not cmd_backend_exist and not cfg_backend_exist and not cfg_backends_exist:
missing.append('-b/--backend')
if len(missing):
parser.error('the following arguments are required: ' + ' '.join(missing))
+ if not oneutils.is_valid_attr(args, 'config'):
+ if not backend_args and not unknown_args:
+ parser.error('commands for the backend is missing.')
+
+ if cfg_backend_exist and cfg_backends_exist:
+ parser.error(
+ '\'backend\' option and \'backends\' option cannot be used simultaneously.')
+
+ # Check if given backend from command line exists in the configuration file
+ if cmd_backend_exist and cfg_backend_exist:
+ if args.backend != cfg_args.backend:
+ parser.error('Not found the command of given backend')
+
+ if cfg_backend_exist and not oneutils.is_valid_attr(cfg_args, 'command'):
+ parser.error('\'command\' key is missing in the configuration file.')
+
+ if cfg_backends_exist:
+ cfg_backends = getattr(cfg_args, 'backends').split(',')
+ # check if commands of given backends exist
+ for b in cfg_backends:
+ if not oneutils.is_valid_attr(cfg_args, b):
+ parser.error('Not found the command for ' + b)
+ # Check if given backend from command line exists in the configuration file
+ if cmd_backend_exist:
+ if args.backend not in cfg_backends:
+ parser.error('Not found the command of given backend')
+
def _parse_arg(parser):
profile_args = []
@@ -139,25 +171,75 @@ def main():
args, backend_args, unknown_args = _parse_arg(parser)
# parse configuration file
- oneutils.parse_cfg(args.config, 'one-profile', args)
+ cfg_args = SimpleNamespace()
+ oneutils.parse_cfg(args.config, 'one-profile', cfg_args)
# verify arguments
- _verify_arg(parser, args)
-
- # make a command to run given backend driver
- profile_path = None
- backend_base = getattr(args, 'backend') + '-profile'
- for cand in backends_list:
- if ntpath.basename(cand) == backend_base:
- profile_path = cand
- if not profile_path:
- raise FileNotFoundError(backend_base + ' not found')
- profile_cmd = [profile_path] + backend_args + unknown_args
- if oneutils.is_valid_attr(args, 'command'):
- profile_cmd += getattr(args, 'command').split()
-
- # run backend driver
- oneutils.run(profile_cmd, err_prefix=backend_base)
+ _verify_arg(parser, args, cfg_args, backend_args, unknown_args)
+ '''
+ one-profile defines its behavior for below cases.
+
+ [1] one-profile -h
+ [2] one-profile -v
+ [3] one-profile -C ${cfg} (backend, command key in cfg)
+ [4] one-profile -C ${cfg} (backends key in cfg)
+ [5] one-profile -b ${backend} ${command}
+ [6] one-profile -b ${backend} -- ${command}
+ [7] one-profile -b ${backend} -C {cfg} (backend, command key in cfg)
+ [8] one-profile -b ${backend} -C {cfg} (backends key in cfg) (Only 'backend' is invoked,
+ even though cfg file has multiple backends)
+ [9] one-profile -b ${backend} -C ${cfg} -- ${command} (backend, command key in cfg)
+ [10] one-profile -b ${backend} -C ${cfg} -- ${command} (backends key in cfg) (Only 'backend' is invoked,
+ even though cfg file has multiple backends)
+
+ All other cases are not allowed or an undefined behavior.
+ '''
+ cmd_overwrite = False
+ if oneutils.is_valid_attr(args, 'config'):
+ # [9], [10]
+ if backend_args and not unknown_args:
+ given_backends = [args.backend]
+ cmd_overwrite = True
+ else:
+ # [7], [8]
+ if oneutils.is_valid_attr(args, 'backend'):
+ given_backends = [args.backend]
+ if oneutils.is_valid_attr(cfg_args, 'backend'):
+ assert (oneutils.is_valid_attr(cfg_args, 'command'))
+ setattr(cfg_args, args.backend, cfg_args.command)
+ else:
+ # [3]
+ if oneutils.is_valid_attr(cfg_args, 'backend'):
+ assert (oneutils.is_valid_attr(cfg_args, 'command'))
+ given_backends = [cfg_args.backend]
+ setattr(cfg_args, cfg_args.backend, cfg_args.command)
+ # [4]
+ if oneutils.is_valid_attr(cfg_args, 'backends'):
+ given_backends = cfg_args.backends.split(',')
+ # [5], [6]
+ else:
+ assert (backend_args or unknown_args)
+ given_backends = [args.backend]
+
+ for given_backend in given_backends:
+ # make a command to run given backend driver
+ profile_path = None
+ backend_base = given_backend + '-profile'
+ for cand in backends_list:
+ if ntpath.basename(cand) == backend_base:
+ profile_path = cand
+ if not profile_path:
+ raise FileNotFoundError(backend_base + ' not found')
+
+ profile_cmd = [profile_path]
+ if not cmd_overwrite and oneutils.is_valid_attr(cfg_args, given_backend):
+ profile_cmd += getattr(cfg_args, given_backend).split()
+ else:
+ profile_cmd += backend_args
+ profile_cmd += unknown_args
+
+ # run backend driver
+ oneutils.run(profile_cmd, err_prefix=backend_base)
if __name__ == '__main__':