Generalize all appropriate arguments and check for file existance

pull/1976/head
Jimmy Brisson 2016-06-21 10:55:01 -05:00
parent 43e036d6e1
commit b98c8c1c33
5 changed files with 45 additions and 52 deletions

View File

@ -35,6 +35,7 @@ from tools.build_api import mcu_toolchain_matrix
from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
from tools.build_api import print_build_results
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
from utils import argparse_filestring_type
if __name__ == '__main__':
start = time()
@ -42,10 +43,10 @@ if __name__ == '__main__':
# Parse Options
parser = get_default_options_parser()
parser.add_argument("--source", dest="source_dir",
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
default=None, help="The source (input) directory", action="append")
parser.add_argument("--build", dest="build_dir",
parser.add_argument("--build", dest="build_dir", type=argparse_filestring_type,
default=None, help="The build (output) directory")
parser.add_argument("--no-archive", dest="no_archive", action="store_true",
@ -160,10 +161,6 @@ if __name__ == '__main__':
# Get target list
if options.mcu:
mcu_list = (options.mcu).split(",")
for mcu in mcu_list:
if mcu not in TARGET_NAMES:
print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES)
sys.exit(1)
targets = mcu_list
else:
targets = TARGET_NAMES
@ -171,10 +168,6 @@ if __name__ == '__main__':
# Get toolchains list
if options.tool:
toolchain_list = (options.tool).split(",")
for tc in toolchain_list:
if tc not in TOOLCHAINS:
print "Given toolchain '%s' not into the supported list:\n%s" % (tc, TOOLCHAINS)
sys.exit(1)
toolchains = toolchain_list
else:
toolchains = TOOLCHAINS

View File

@ -28,6 +28,7 @@ from tools.utils import args_error
from tools.options import get_default_options_parser
from tools.build_api import get_config
from config import Config
from utils import argparse_filestring_type
try:
import tools.private_settings as ps
except:
@ -36,19 +37,15 @@ except:
if __name__ == '__main__':
# Parse Options
parser = get_default_options_parser(add_clean=False, add_options=False)
parser.add_argument("--source", dest="source_dir",
default=None, help="The source (input) directory", action="append")
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
default=[], help="The source (input) directory", action="append")
parser.add_argument("--prefix", dest="prefix", action="append",
default=None, help="Restrict listing to parameters that have this prefix")
default=[], help="Restrict listing to parameters that have this prefix")
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="Verbose diagnostic output")
options = parser.parse_args()
for path in options.source_dir :
if not isdir(path) :
args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
format(path))
# Target
if options.mcu is None :
args_error(parser, "[ERROR] You should specify an MCU")

View File

@ -42,21 +42,38 @@ from tools.targets import TARGET_MAP
from tools.options import get_default_options_parser
from tools.build_api import build_project
from tools.build_api import mcu_toolchain_matrix
from utils import argparse_filestring_type
from argparse import ArgumentTypeError
try:
import tools.private_settings as ps
except:
ps = object()
def test_known(string):
i = int(string)
if i >= 0 and i < len(TESTS) : return i
else : raise ArgumentTypeError("{0} does not index a test".format(i))
def test_name_known(string):
nlist = string.split(',')
for test_id in nlist:
if test_id not in TEST_MAP.keys():
raise ArgumentTypeError("Program with name '%s' not found"% test_id)
return [TEST_MAP[n].n for n in nlist]
if __name__ == '__main__':
# Parse Options
parser = get_default_options_parser()
parser.add_argument("-p",
type=int,
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-p",
type=test_known,
dest="program",
help="The index of the desired test program: [0-%d]" % (len(TESTS)-1))
parser.add_argument("-n",
dest="program_name",
group.add_argument("-n",
type=test_name_known,
dest="program",
help="The name of the desired test program")
parser.add_argument("-j", "--jobs",
@ -104,7 +121,7 @@ if __name__ == '__main__':
default=None, help="Required peripherals")
parser.add_argument("--dep", dest="dependencies",
default=None, help="Dependencies")
parser.add_argument("--source", dest="source_dir",
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
default=None, help="The source (input) directory", action="append")
parser.add_argument("--duration", type=int, dest="duration",
default=None, help="Duration of the test")
@ -174,6 +191,7 @@ if __name__ == '__main__':
# Specify a different linker script
parser.add_argument("-l", "--linker", dest="linker_script",
type=argparse_filestring_type,
default=None, help="use the specified linker script")
options = parser.parse_args()
@ -183,12 +201,6 @@ if __name__ == '__main__':
print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
exit(0)
if options.source_dir:
for path in options.source_dir :
if not isfile(path) and not isdir(path) :
args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
format(path))
# Print available tests in order and exit
if options.list_tests is True:
print '\n'.join(map(str, sorted(TEST_MAP.values())))
@ -197,25 +209,9 @@ if __name__ == '__main__':
# force program to "0" if a source dir is specified
if options.source_dir is not None:
p = 0
n = None
else:
# Program Number or name
p, n = options.program, options.program_name
if n is not None and p is not None:
args_error(parser, "[ERROR] specify either '-n' or '-p', not both")
if n:
# We will transform 'n' to list of 'p' (integers which are test numbers)
nlist = n.split(',')
for test_id in nlist:
if test_id not in TEST_MAP.keys():
args_error(parser, "[ERROR] Program with name '%s' not found"% test_id)
p = [TEST_MAP[n].n for n in nlist]
elif p is None or (p < 0) or (p > (len(TESTS)-1)):
message = "[ERROR] You have to specify one of the following tests:\n"
message += '\n'.join(map(str, sorted(TEST_MAP.values())))
args_error(parser, message)
p = options.program
# If 'p' was set via -n to list of numbers make this a single element integer list
if type(p) != type([]):

View File

@ -32,14 +32,14 @@ from tools.build_api import build_project, build_library
from tools.targets import TARGET_MAP
from tools.utils import mkdir, ToolException, NotSupportedException
from tools.test_exporters import ReportExporter, ResultExporterType
from utils import argparse_lowercase_type
from utils import argparse_filestring_type, argparse_lowercase_type
if __name__ == '__main__':
try:
# Parse Options
parser = get_default_options_parser()
parser.add_argument("-D", "",
parser.add_argument("-D",
action="append",
dest="macros",
help="Add a macro definition")
@ -51,6 +51,7 @@ if __name__ == '__main__':
help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
parser.add_argument("--source", dest="source_dir",
type=argparse_filestring_type,
default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append")
parser.add_argument("--build", dest="build_dir",
@ -60,18 +61,20 @@ if __name__ == '__main__':
default=False, help="List (recursively) available tests in order and exit")
parser.add_argument("-p", "--paths", dest="paths",
type=argparse_filestring_type, nargs="*"
default=None, help="Limit the tests to those within the specified comma separated list of paths")
format_choices = ["list", "json"]
format_default_choice = "list"
format_help = "Change the format in which tests are listed. Choices include: %s. Default: %s" % (", ".join(format_choices), format_default_choice)
parser.add_argument("-f", "--format", type=argparse_lowercase_type(format_coices,"format"), dest="format",
default=format_default_choice, help=format_help)
parser.add_argument("-f", "--format", dest="format",
type=argparse_lowercase_type(format_choices, "format"),
default=format_default_choice, help=format_help)
parser.add_argument("--continue-on-build-fail", action="store_true", dest="continue_on_build_fail",
default=None, help="Continue trying to build all tests if a build failure occurs")
parser.add_argument("-n", "--names", dest="names",
parser.add_argument("-n", "--names", dest="names", nargs="*"
default=None, help="Limit the tests to a comma separated list of names")
parser.add_argument("--test-spec", dest="test_spec",
@ -90,7 +93,7 @@ if __name__ == '__main__':
# Filter tests by path if specified
if options.paths:
all_paths = options.paths.split(",")
all_paths = options.paths
else:
all_paths = ["."]
@ -103,7 +106,7 @@ if __name__ == '__main__':
# Filter tests by name if specified
if options.names:
all_names = options.names.split(",")
all_names = options.names
all_names = [x.lower() for x in all_names]
for name in all_names:

View File

@ -217,3 +217,7 @@ argparse_uppercase_type = argparse_list_type(str.upper, False)
argparse_lowercase_type = argparse_list_type(str.lower, False)
argparse_uppercase_hyphen_type = argparse_list_type(str.upper, True)
argparse_lowercase_hyphen_type = argparse_list_type(str.lower, True)
def argparse_filestring_type(string) :
if exists(string) : return string
else : raise argparse.ArgumentTypeError("{0} does not exist in the filesystem.".format(string))