Skip to content

Commit 9e5a779

Browse files
authored
Merge pull request #2010 from theotherjimmy/flag-handling
Fix bug that killed the BOT when argument validation was on
2 parents 57c28a9 + 61c63b3 commit 9e5a779

File tree

14 files changed

+518
-465
lines changed

14 files changed

+518
-465
lines changed

tools/build.py

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,149 +35,134 @@
3535
from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
3636
from tools.build_api import print_build_results
3737
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
38+
from utils import argparse_filestring_type
3839

3940
if __name__ == '__main__':
4041
start = time()
4142

4243
# Parse Options
4344
parser = get_default_options_parser()
4445

45-
parser.add_option("--source", dest="source_dir",
46-
default=None, help="The source (input) directory", action="append")
46+
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
47+
default=None, help="The source (input) directory", action="append")
4748

48-
parser.add_option("--build", dest="build_dir",
49+
parser.add_argument("--build", dest="build_dir",
4950
default=None, help="The build (output) directory")
5051

51-
parser.add_option("--no-archive", dest="no_archive", action="store_true",
52+
parser.add_argument("--no-archive", dest="no_archive", action="store_true",
5253
default=False, help="Do not produce archive (.ar) file, but rather .o")
5354

5455
# Extra libraries
55-
parser.add_option("-r", "--rtos",
56+
parser.add_argument("-r", "--rtos",
5657
action="store_true",
5758
dest="rtos",
5859
default=False,
5960
help="Compile the rtos")
6061

61-
parser.add_option("--rpc",
62+
parser.add_argument("--rpc",
6263
action="store_true",
6364
dest="rpc",
6465
default=False,
6566
help="Compile the rpc library")
6667

67-
parser.add_option("-e", "--eth",
68+
parser.add_argument("-e", "--eth",
6869
action="store_true", dest="eth",
6970
default=False,
7071
help="Compile the ethernet library")
7172

72-
parser.add_option("-U", "--usb_host",
73+
parser.add_argument("-U", "--usb_host",
7374
action="store_true",
7475
dest="usb_host",
7576
default=False,
7677
help="Compile the USB Host library")
7778

78-
parser.add_option("-u", "--usb",
79+
parser.add_argument("-u", "--usb",
7980
action="store_true",
8081
dest="usb",
8182
default=False,
8283
help="Compile the USB Device library")
8384

84-
parser.add_option("-d", "--dsp",
85+
parser.add_argument("-d", "--dsp",
8586
action="store_true",
8687
dest="dsp",
8788
default=False,
8889
help="Compile the DSP library")
8990

90-
parser.add_option("-F", "--fat",
91+
parser.add_argument("-F", "--fat",
9192
action="store_true",
9293
dest="fat",
9394
default=False,
9495
help="Compile FS and SD card file system library")
9596

96-
parser.add_option("-b", "--ublox",
97+
parser.add_argument("-b", "--ublox",
9798
action="store_true",
9899
dest="ublox",
99100
default=False,
100101
help="Compile the u-blox library")
101102

102-
parser.add_option("", "--cpputest",
103+
parser.add_argument( "--cpputest",
103104
action="store_true",
104105
dest="cpputest_lib",
105106
default=False,
106107
help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
107108

108-
parser.add_option("-D", "",
109+
parser.add_argument("-D",
109110
action="append",
110111
dest="macros",
111112
help="Add a macro definition")
112113

113-
parser.add_option("-S", "--supported-toolchains",
114+
parser.add_argument("-S", "--supported-toolchains",
114115
action="store_true",
115116
dest="supported_toolchains",
116117
default=False,
117118
help="Displays supported matrix of MCUs and toolchains")
118119

119-
parser.add_option('-f', '--filter',
120+
parser.add_argument('-f', '--filter',
120121
dest='general_filter_regex',
121122
default=None,
122123
help='For some commands you can use filter to filter out results')
123124

124-
parser.add_option("", "--cppcheck",
125+
parser.add_argument("--cppcheck",
125126
action="store_true",
126127
dest="cppcheck_validation",
127128
default=False,
128129
help="Forces 'cppcheck' static code analysis")
129130

130-
parser.add_option("-j", "--jobs", type="int", dest="jobs",
131+
parser.add_argument("-j", "--jobs", type=int, dest="jobs",
131132
default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
132-
parser.add_option("-N", "--artifact-name", dest="artifact_name",
133+
parser.add_argument("-N", "--artifact-name", dest="artifact_name",
133134
default=None, help="The built project's name")
134135

135-
parser.add_option("-v", "--verbose",
136+
parser.add_argument("-v", "--verbose",
136137
action="store_true",
137138
dest="verbose",
138139
default=False,
139140
help="Verbose diagnostic output")
140141

141-
parser.add_option("--silent",
142+
parser.add_argument("--silent",
142143
action="store_true",
143144
dest="silent",
144145
default=False,
145146
help="Silent diagnostic output (no copy, compile notification)")
146147

147-
parser.add_option("-x", "--extra-verbose-notifications",
148+
parser.add_argument("-x", "--extra-verbose-notifications",
148149
action="store_true",
149150
dest="extra_verbose_notify",
150151
default=False,
151152
help="Makes compiler more verbose, CI friendly.")
152153

153-
(options, args) = parser.parse_args()
154+
options = parser.parse_args()
154155

155156
# Only prints matrix of supported toolchains
156157
if options.supported_toolchains:
157158
print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
158159
exit(0)
159160

160161
# Get target list
161-
if options.mcu:
162-
mcu_list = (options.mcu).split(",")
163-
for mcu in mcu_list:
164-
if mcu not in TARGET_NAMES:
165-
print "Given MCU '%s' not into the supported list:\n%s" % (mcu, TARGET_NAMES)
166-
sys.exit(1)
167-
targets = mcu_list
168-
else:
169-
targets = TARGET_NAMES
162+
targets = options.mcu if options.mcu else TARGET_NAMES
170163

171164
# Get toolchains list
172-
if options.tool:
173-
toolchain_list = (options.tool).split(",")
174-
for tc in toolchain_list:
175-
if tc not in TOOLCHAINS:
176-
print "Given toolchain '%s' not into the supported list:\n%s" % (tc, TOOLCHAINS)
177-
sys.exit(1)
178-
toolchains = toolchain_list
179-
else:
180-
toolchains = TOOLCHAINS
165+
toolchains = options.tool if options.tool else TOOLCHAINS
181166

182167
# Get libraries list
183168
libraries = []

tools/detect_targets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@
4242
# Parse Options
4343
parser = get_default_options_parser()
4444

45-
parser.add_option("-S", "--supported-toolchains",
45+
parser.add_argument("-S", "--supported-toolchains",
4646
action="store_true",
4747
dest="supported_toolchains",
4848
default=False,
4949
help="Displays supported matrix of targets and toolchains")
5050

51-
parser.add_option('-f', '--filter',
51+
parser.add_argument('-f', '--filter',
5252
dest='general_filter_regex',
5353
default=None,
5454
help='Filter targets')
5555

56-
parser.add_option("-v", "--verbose",
56+
parser.add_argument("-v", "--verbose",
5757
action="store_true",
5858
dest="verbose",
5959
default=False,
6060
help="Verbose diagnostic output")
6161

62-
(options, args) = parser.parse_args()
62+
options = parser.parse_args()
6363

6464
# Only prints matrix of supported toolchains
6565
if options.supported_toolchains:

tools/get_config.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from tools.options import get_default_options_parser
2929
from tools.build_api import get_config
3030
from config import Config
31+
from utils import argparse_filestring_type
3132
try:
3233
import tools.private_settings as ps
3334
except:
@@ -36,28 +37,24 @@
3637
if __name__ == '__main__':
3738
# Parse Options
3839
parser = get_default_options_parser(add_clean=False, add_options=False)
39-
parser.add_option("--source", dest="source_dir",
40-
default=None, help="The source (input) directory", action="append")
41-
parser.add_option("--prefix", dest="prefix", action="append",
42-
default=None, help="Restrict listing to parameters that have this prefix")
43-
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
40+
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
41+
default=[], help="The source (input) directory", action="append")
42+
parser.add_argument("--prefix", dest="prefix", action="append",
43+
default=[], help="Restrict listing to parameters that have this prefix")
44+
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
4445
default=False, help="Verbose diagnostic output")
4546

46-
(options, args) = parser.parse_args()
47+
options = parser.parse_args()
4748

48-
for path in options.source_dir :
49-
if not isdir(path) :
50-
args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
51-
format(path))
5249
# Target
5350
if options.mcu is None :
5451
args_error(parser, "[ERROR] You should specify an MCU")
55-
target = options.mcu
52+
target = options.mcu[0]
5653

5754
# Toolchain
5855
if options.tool is None:
5956
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
60-
toolchain = options.tool
57+
toolchain = options.tool[0]
6158

6259
options.prefix = options.prefix or [""]
6360

tools/host_tests/host_tests_plugins/module_copy_smart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from host_test_plugins import HostTestPluginBase
2323

2424
sys.path.append(abspath(join(dirname(__file__), "../../../")))
25-
from tools.test_api import get_autodetected_MUTS_list
25+
import tools.test_api
2626

2727
class HostTestPluginCopyMethod_Smart(HostTestPluginBase):
2828

@@ -74,7 +74,7 @@ def execute(self, capability, *args, **kwargs):
7474

7575
for i in range(0, 60):
7676
print('Looking for %s with MBEDLS' % target_mcu)
77-
muts_list = get_autodetected_MUTS_list(platform_name_filter=platform_name_filter)
77+
muts_list = tools.test_api.get_autodetected_MUTS_list(platform_name_filter=platform_name_filter)
7878

7979
if 1 in muts_list:
8080
mut = muts_list[1]

0 commit comments

Comments
 (0)