|
35 | 35 | from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
|
36 | 36 | from tools.build_api import print_build_results
|
37 | 37 | from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
|
| 38 | +from utils import argparse_filestring_type |
38 | 39 |
|
39 | 40 | if __name__ == '__main__':
|
40 | 41 | start = time()
|
41 | 42 |
|
42 | 43 | # Parse Options
|
43 | 44 | parser = get_default_options_parser()
|
44 | 45 |
|
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") |
47 | 48 |
|
48 |
| - parser.add_option("--build", dest="build_dir", |
| 49 | + parser.add_argument("--build", dest="build_dir", |
49 | 50 | default=None, help="The build (output) directory")
|
50 | 51 |
|
51 |
| - parser.add_option("--no-archive", dest="no_archive", action="store_true", |
| 52 | + parser.add_argument("--no-archive", dest="no_archive", action="store_true", |
52 | 53 | default=False, help="Do not produce archive (.ar) file, but rather .o")
|
53 | 54 |
|
54 | 55 | # Extra libraries
|
55 |
| - parser.add_option("-r", "--rtos", |
| 56 | + parser.add_argument("-r", "--rtos", |
56 | 57 | action="store_true",
|
57 | 58 | dest="rtos",
|
58 | 59 | default=False,
|
59 | 60 | help="Compile the rtos")
|
60 | 61 |
|
61 |
| - parser.add_option("--rpc", |
| 62 | + parser.add_argument("--rpc", |
62 | 63 | action="store_true",
|
63 | 64 | dest="rpc",
|
64 | 65 | default=False,
|
65 | 66 | help="Compile the rpc library")
|
66 | 67 |
|
67 |
| - parser.add_option("-e", "--eth", |
| 68 | + parser.add_argument("-e", "--eth", |
68 | 69 | action="store_true", dest="eth",
|
69 | 70 | default=False,
|
70 | 71 | help="Compile the ethernet library")
|
71 | 72 |
|
72 |
| - parser.add_option("-U", "--usb_host", |
| 73 | + parser.add_argument("-U", "--usb_host", |
73 | 74 | action="store_true",
|
74 | 75 | dest="usb_host",
|
75 | 76 | default=False,
|
76 | 77 | help="Compile the USB Host library")
|
77 | 78 |
|
78 |
| - parser.add_option("-u", "--usb", |
| 79 | + parser.add_argument("-u", "--usb", |
79 | 80 | action="store_true",
|
80 | 81 | dest="usb",
|
81 | 82 | default=False,
|
82 | 83 | help="Compile the USB Device library")
|
83 | 84 |
|
84 |
| - parser.add_option("-d", "--dsp", |
| 85 | + parser.add_argument("-d", "--dsp", |
85 | 86 | action="store_true",
|
86 | 87 | dest="dsp",
|
87 | 88 | default=False,
|
88 | 89 | help="Compile the DSP library")
|
89 | 90 |
|
90 |
| - parser.add_option("-F", "--fat", |
| 91 | + parser.add_argument("-F", "--fat", |
91 | 92 | action="store_true",
|
92 | 93 | dest="fat",
|
93 | 94 | default=False,
|
94 | 95 | help="Compile FS and SD card file system library")
|
95 | 96 |
|
96 |
| - parser.add_option("-b", "--ublox", |
| 97 | + parser.add_argument("-b", "--ublox", |
97 | 98 | action="store_true",
|
98 | 99 | dest="ublox",
|
99 | 100 | default=False,
|
100 | 101 | help="Compile the u-blox library")
|
101 | 102 |
|
102 |
| - parser.add_option("", "--cpputest", |
| 103 | + parser.add_argument( "--cpputest", |
103 | 104 | action="store_true",
|
104 | 105 | dest="cpputest_lib",
|
105 | 106 | default=False,
|
106 | 107 | help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
|
107 | 108 |
|
108 |
| - parser.add_option("-D", "", |
| 109 | + parser.add_argument("-D", |
109 | 110 | action="append",
|
110 | 111 | dest="macros",
|
111 | 112 | help="Add a macro definition")
|
112 | 113 |
|
113 |
| - parser.add_option("-S", "--supported-toolchains", |
| 114 | + parser.add_argument("-S", "--supported-toolchains", |
114 | 115 | action="store_true",
|
115 | 116 | dest="supported_toolchains",
|
116 | 117 | default=False,
|
117 | 118 | help="Displays supported matrix of MCUs and toolchains")
|
118 | 119 |
|
119 |
| - parser.add_option('-f', '--filter', |
| 120 | + parser.add_argument('-f', '--filter', |
120 | 121 | dest='general_filter_regex',
|
121 | 122 | default=None,
|
122 | 123 | help='For some commands you can use filter to filter out results')
|
123 | 124 |
|
124 |
| - parser.add_option("", "--cppcheck", |
| 125 | + parser.add_argument("--cppcheck", |
125 | 126 | action="store_true",
|
126 | 127 | dest="cppcheck_validation",
|
127 | 128 | default=False,
|
128 | 129 | help="Forces 'cppcheck' static code analysis")
|
129 | 130 |
|
130 |
| - parser.add_option("-j", "--jobs", type="int", dest="jobs", |
| 131 | + parser.add_argument("-j", "--jobs", type=int, dest="jobs", |
131 | 132 | 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", |
133 | 134 | default=None, help="The built project's name")
|
134 | 135 |
|
135 |
| - parser.add_option("-v", "--verbose", |
| 136 | + parser.add_argument("-v", "--verbose", |
136 | 137 | action="store_true",
|
137 | 138 | dest="verbose",
|
138 | 139 | default=False,
|
139 | 140 | help="Verbose diagnostic output")
|
140 | 141 |
|
141 |
| - parser.add_option("--silent", |
| 142 | + parser.add_argument("--silent", |
142 | 143 | action="store_true",
|
143 | 144 | dest="silent",
|
144 | 145 | default=False,
|
145 | 146 | help="Silent diagnostic output (no copy, compile notification)")
|
146 | 147 |
|
147 |
| - parser.add_option("-x", "--extra-verbose-notifications", |
| 148 | + parser.add_argument("-x", "--extra-verbose-notifications", |
148 | 149 | action="store_true",
|
149 | 150 | dest="extra_verbose_notify",
|
150 | 151 | default=False,
|
151 | 152 | help="Makes compiler more verbose, CI friendly.")
|
152 | 153 |
|
153 |
| - (options, args) = parser.parse_args() |
| 154 | + options = parser.parse_args() |
154 | 155 |
|
155 | 156 | # Only prints matrix of supported toolchains
|
156 | 157 | if options.supported_toolchains:
|
157 | 158 | print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
|
158 | 159 | exit(0)
|
159 | 160 |
|
160 | 161 | # 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 |
170 | 163 |
|
171 | 164 | # 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 |
181 | 166 |
|
182 | 167 | # Get libraries list
|
183 | 168 | libraries = []
|
|
0 commit comments