diff --git a/hb_new/resources/args/default/toolargs.json b/hb_new/resources/args/default/toolargs.json index fd9423c8bf33e018840213e3097141a90314e267..999675cdfb6adcc12a444703d79a9f3f162997bd 100644 --- a/hb_new/resources/args/default/toolargs.json +++ b/hb_new/resources/args/default/toolargs.json @@ -2,7 +2,7 @@ "ls": { "argName": "--ls", "argDefault": [], - "argHelp": "Lists all targets matching the given pattern for the given build directory.", + "argHelp": "Lists all targets matching the given pattern for the given build directory. You could use this option like this: 1.'hb tool --ls [] []'", "argPhase": "prebuild", "argType": "subparsers", "argAttribute": { @@ -77,7 +77,7 @@ "desc": { "argName": "--desc", "argDefault": [], - "argHelp": "Displays information about a given target or config.", + "argHelp": "Displays information about a given target or config. You could use this option like this: 1.'hb tool --desc [] []'", "argPhase": "prebuild", "argType": "subparsers", "argAttribute": { @@ -162,7 +162,7 @@ "path": { "argName": "--path", "argDefault": [], - "argHelp": "", + "argHelp": "Finds paths of dependencies between two targets. You could use this option like this: 1.'hb tool --path []'", "argPhase": "prebuild", "argType": "subparsers", "argAttribute": { @@ -178,7 +178,7 @@ "refs": { "argName": "--refs", "argDefault": [], - "argHelp": "", + "argHelp": "Finds reverse dependencies (which targets reference something). You could use this option like this: 1.'hb tool --refs [|] []'", "argPhase": "prebuild", "argType": "subparsers", "argAttribute": { @@ -283,7 +283,7 @@ "format": { "argName": "--format", "argDefault": [], - "argHelp": "", + "argHelp": "Formats .gn file to a standard format. You could use this option like this: 1.'hb tool --format /abspath/some/BUILD.gn []'", "argPhase": "prebuild", "argType": "subparsers", "argAttribute": { @@ -331,7 +331,7 @@ "clean": { "argName": "--clean", "argDefault": "", - "argHelp": "", + "argHelp": "Deletes the contents of the output directory except for args.gn. You could use this option like this: 1.'hb tool --clean '", "argPhase": "prebuild", "argType": "str", "argAttribute": {}, diff --git a/hb_new/resources/status/status.json b/hb_new/resources/status/status.json index 2d10952e8505d063123c893ee146964784d57296..719633fa51e2c9d32fc181a60e6f4376eb421af0 100644 --- a/hb_new/resources/status/status.json +++ b/hb_new/resources/status/status.json @@ -155,6 +155,22 @@ "code": "3002", "solution": "Please check the compile log at out/{compiling product}/build.log, If you could analyze build logs. \n\t\tOr you can try the following steps to solve this problem:\n\t\t 1. cd to OHOS root path\n\t\t 2. run 'hb clean --all' or 'rm -rf out build/resources/args/*.json'.\n\t\t 3. repo sync\n\t\t 4. repo forall -c 'git lfs pull'\n\t\t 5. bash build/prebuilts_download.sh\n\t\t 6. rebuild your product or component\n\n\t\tIf you still cannot solve this problem, you could post this problem on: \n\t\t https://gitee.com/openharmony/build/issues" }, + "3003": { + "code": "3003", + "solution": "Please check your corresponding arg. You can view the corresponding options in the json file('resources/status/status.json'). \n\t\tOr you can run cmd 'hb tool -h' to show usage" + }, + "3004": { + "code": "3004", + "solution": "This command requires an existing build directory. Please check whether the corresponding file('out/{product_name}/args.gn' exists." + }, + "3005": { + "code": "3005", + "solution": "Please check whether the target gn file exists in the corresponding path." + }, + "3006": { + "code": "3006", + "solution": "Please use '=' to connect argument and value." + }, "4000": { "code": "4000", "solution": "Please check the compile log at out/{compiling product}/build.log, If you could analyze build logs. \n\t\tOr you can try the following steps to solve this problem:\n\t\t 1. cd to OHOS root path\n\t\t 2. run 'hb clean --all' or 'rm -rf out build/resources/args/*.json'.\n\t\t 3. repo sync\n\t\t 4. repo forall -c 'git lfs pull'\n\t\t 5. bash build/prebuilts_download.sh\n\t\t 6. rebuild your product or component\n\n\t\tIf you still cannot solve this problem, you could post this problem on: \n\t\t https://gitee.com/openharmony/build/issues" diff --git a/hb_new/services/gn.py b/hb_new/services/gn.py index d39c1cec90900dabe6bdf2eb6ab95bdb640c9cc1..174d9af7a326fe87c2009184ecea748031016989 100644 --- a/hb_new/services/gn.py +++ b/hb_new/services/gn.py @@ -19,7 +19,6 @@ import sys import os -import pandas from enum import Enum from containers.status import throw_exception @@ -143,16 +142,20 @@ class Gn(BuildFileGeneratorInterface): support_sub_options = args_file.get("argAttribute").get("support_sub_options") option_name = option.lstrip('-') option_value = "" - check = False if '=' in option: option_name, option_value = option.lstrip('-').split('=') if option_name in support_sub_options: sub_optional_list = support_sub_options.get(option_name).get("argAttribute").get("optional") if sub_optional_list and option_value not in sub_optional_list: - check = False - else: - check = True - return check + if not len(option_value): + raise OHOSException('ERROR argument "--{}": Invalid choice "{}". ' + 'choose from {}'.format(option_name, option_value, sub_optional_list), '3006') + else: + raise OHOSException('ERROR argument "--{}": Invalid choice "{}". ' + 'choose from {}'.format(option_name, option_value, sub_optional_list), '3003') + else: + raise OHOSException('ERROR argument "{}": Invalid choice "{}". ' + 'choose from {}'.format(args_file.get("argName"), option, list(support_sub_options.keys())), '3003') '''Description: Execute 'gn gen' command using registed args @parameter: kwargs TBD @@ -187,15 +190,16 @@ class Gn(BuildFileGeneratorInterface): if(os.path.exists(os.path.join(out_dir, "args.gn"))): gn_path_cmd = [self.exec, 'path', out_dir] for arg in kwargs.get('args_list'): - if arg.startswith('-') and not self._check_options_validity(arg, args_file): - raise OHOSException('ERROR Invalid value for "{}".'.format(arg)) + if arg.startswith('-'): + self._check_options_validity(arg, args_file) gn_path_cmd.append(arg) gn_path_cmd.extend(default_options) - gn_path_cmd = pandas.Series(gn_path_cmd).unique() + sort_index = gn_path_cmd.index + gn_path_cmd = list(set(gn_path_cmd)) + gn_path_cmd.sort(key=sort_index) SystemUtil.exec_command(gn_path_cmd) else: - raise OHOSException('{} Not a build directory.' - 'This command requires an existing build directory.'.format(out_dir)) + raise OHOSException('"{}" Not a build directory.'.format(out_dir), '3004') '''Description: Execute 'gn desc' command using registed args @parameter: kwargs TBD @@ -210,15 +214,16 @@ class Gn(BuildFileGeneratorInterface): if(os.path.exists(os.path.join(out_dir, "args.gn"))): gn_desc_cmd = [self.exec, 'desc', out_dir] for arg in kwargs.get('args_list'): - if arg.startswith('-') and not self._check_options_validity(arg, args_file): - raise OHOSException('ERROR Invalid value for "{}".'.format(arg)) + if arg.startswith('-'): + self._check_options_validity(arg, args_file) gn_desc_cmd.append(arg) gn_desc_cmd.extend(default_options) - gn_desc_cmd = pandas.Series(gn_desc_cmd).unique() + sort_index = gn_desc_cmd.index + gn_desc_cmd = list(set(gn_desc_cmd)) + gn_desc_cmd.sort(key=sort_index) SystemUtil.exec_command(gn_desc_cmd) else: - raise OHOSException('{} Not a build directory.' - 'This command requires an existing build directory.'.format(out_dir)) + raise OHOSException('"{}" Not a build directory.'.format(out_dir), '3004') '''Description: Execute 'gn ls' command using registed args @parameter: kwargs TBD @@ -232,14 +237,12 @@ class Gn(BuildFileGeneratorInterface): if(os.path.exists(os.path.join(out_dir, "args.gn"))): gn_ls_cmd = [self.exec, 'ls', out_dir] for arg in kwargs.get('args_list'): - if arg.startswith('-') and not self._check_options_validity(arg, args_file): - raise OHOSException('ERROR Invalid value for "{}".'.format(arg)) + if arg.startswith('-'): + self._check_options_validity(arg, args_file) gn_ls_cmd.append(arg) - gn_ls_cmd = pandas.Series(gn_ls_cmd).unique() SystemUtil.exec_command(gn_ls_cmd) else: - raise OHOSException('{} Not a build directory.' - 'This command requires an existing build directory.'.format(out_dir)) + raise OHOSException('"{}" Not a build directory.'.format(out_dir), '3004') '''Description: Execute 'gn refs' command using registed args @parameter: kwargs TBD @@ -253,14 +256,12 @@ class Gn(BuildFileGeneratorInterface): if(os.path.exists(os.path.join(out_dir, "args.gn"))): gn_refs_cmd = [self.exec, 'refs', out_dir] for arg in kwargs.get('args_list'): - if arg.startswith('-') and not self._check_options_validity(arg, args_file): - raise OHOSException('ERROR Invalid value for "{}".'.format(arg)) + if arg.startswith('-'): + self._check_options_validity(arg, args_file) gn_refs_cmd.append(arg) - gn_refs_cmd = pandas.Series(gn_refs_cmd).unique() SystemUtil.exec_command(gn_refs_cmd) else: - raise OHOSException('{} Not a build directory.' - 'This command requires an existing build directory.'.format(out_dir)) + raise OHOSException('"{}" Not a build directory.'.format(out_dir), '3004') '''Description: Execute 'gn format' command using registed args @parameter: kwargs TBD @@ -276,10 +277,10 @@ class Gn(BuildFileGeneratorInterface): if (os.path.exists(arg)): gn_format_cmd.append(arg) else: - raise OHOSException("ERROR Couldn't read '{}'".format(arg)) + raise OHOSException("ERROR Couldn't read '{}'".format(arg), '3005') else: - if arg.startswith('-') and not self._check_options_validity(arg, args_file): - raise OHOSException('ERROR Invalid value for "{}".'.format(arg)) + if arg.startswith('-'): + self._check_options_validity(arg, args_file) gn_format_cmd.append(arg) SystemUtil.exec_command(gn_format_cmd) @@ -295,6 +296,6 @@ class Gn(BuildFileGeneratorInterface): gn_clean_cmd = [self.exec, 'clean', out_dir] SystemUtil.exec_command(gn_clean_cmd) else: - raise OHOSException('{} Not a build directory.' - 'Usage: "gn clean "'.format(out_dir)) + raise OHOSException('"{}" Not a build directory.' + 'Usage: "gn clean "'.format(out_dir), '3004')