Skip to content

Generalize flag handling #1976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 27 additions & 42 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,149 +35,134 @@
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()

# Parse Options
parser = get_default_options_parser()

parser.add_option("--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=None, help="The source (input) directory", nargs="*")

parser.add_option("--build", dest="build_dir",
parser.add_argument("--build", dest="build_dir", type=argparse_filestring_type,
default=None, help="The build (output) directory")

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

# Extra libraries
parser.add_option("-r", "--rtos",
parser.add_argument("-r", "--rtos",
action="store_true",
dest="rtos",
default=False,
help="Compile the rtos")

parser.add_option("--rpc",
parser.add_argument("--rpc",
action="store_true",
dest="rpc",
default=False,
help="Compile the rpc library")

parser.add_option("-e", "--eth",
parser.add_argument("-e", "--eth",
action="store_true", dest="eth",
default=False,
help="Compile the ethernet library")

parser.add_option("-U", "--usb_host",
parser.add_argument("-U", "--usb_host",
action="store_true",
dest="usb_host",
default=False,
help="Compile the USB Host library")

parser.add_option("-u", "--usb",
parser.add_argument("-u", "--usb",
action="store_true",
dest="usb",
default=False,
help="Compile the USB Device library")

parser.add_option("-d", "--dsp",
parser.add_argument("-d", "--dsp",
action="store_true",
dest="dsp",
default=False,
help="Compile the DSP library")

parser.add_option("-F", "--fat",
parser.add_argument("-F", "--fat",
action="store_true",
dest="fat",
default=False,
help="Compile FS and SD card file system library")

parser.add_option("-b", "--ublox",
parser.add_argument("-b", "--ublox",
action="store_true",
dest="ublox",
default=False,
help="Compile the u-blox library")

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

parser.add_option("-D", "",
action="append",
parser.add_argument("-D",
nargs="*",
dest="macros",
help="Add a macro definition")

parser.add_option("-S", "--supported-toolchains",
parser.add_argument("-S", "--supported-toolchains",
action="store_true",
dest="supported_toolchains",
default=False,
help="Displays supported matrix of MCUs and toolchains")

parser.add_option('-f', '--filter',
parser.add_argument('-f', '--filter',
dest='general_filter_regex',
default=None,
help='For some commands you can use filter to filter out results')

parser.add_option("", "--cppcheck",
parser.add_argument("--cppcheck",
action="store_true",
dest="cppcheck_validation",
default=False,
help="Forces 'cppcheck' static code analysis")

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

parser.add_option("-v", "--verbose",
parser.add_argument("-v", "--verbose",
action="store_true",
dest="verbose",
default=False,
help="Verbose diagnostic output")

parser.add_option("--silent",
parser.add_argument("--silent",
action="store_true",
dest="silent",
default=False,
help="Silent diagnostic output (no copy, compile notification)")

parser.add_option("-x", "--extra-verbose-notifications",
parser.add_argument("-x", "--extra-verbose-notifications",
action="store_true",
dest="extra_verbose_notify",
default=False,
help="Makes compiler more verbose, CI friendly.")

(options, args) = parser.parse_args()
options = parser.parse_args()

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

# 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
targets = options.mcu if options.mcu else TARGET_NAMES

# 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
toolchains = options.tool if options.tool else TOOLCHAINS

# Get libraries list
libraries = []
Expand Down
8 changes: 4 additions & 4 deletions tools/detect_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@
# Parse Options
parser = get_default_options_parser()
Copy link
Contributor

@bridadan bridadan Jun 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is pulling in the following unneeded options: -m, -t, -c <--clean, and -o <--options>. Perhaps this should just be a new instantiation of argparse?

This should probably be in a separate PR though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a PR to fix this @bridadan ?


parser.add_option("-S", "--supported-toolchains",
parser.add_argument("-S", "--supported-toolchains",
action="store_true",
dest="supported_toolchains",
default=False,
help="Displays supported matrix of targets and toolchains")

parser.add_option('-f', '--filter',
parser.add_argument('-f', '--filter',
dest='general_filter_regex',
default=None,
help='Filter targets')

parser.add_option("-v", "--verbose",
parser.add_argument("-v", "--verbose",
action="store_true",
dest="verbose",
default=False,
help="Verbose diagnostic output")

(options, args) = parser.parse_args()
options = parser.parse_args()

# Only prints matrix of supported toolchains
if options.supported_toolchains:
Expand Down
17 changes: 7 additions & 10 deletions tools/get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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:
Expand All @@ -36,19 +37,15 @@
if __name__ == '__main__':
# Parse Options
parser = get_default_options_parser(add_clean=False, add_options=False)
parser.add_option("--source", dest="source_dir",
default=None, help="The source (input) directory", action="append")
parser.add_option("--prefix", dest="prefix", action="append",
default=None, help="Restrict listing to parameters that have this prefix")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a --source argument isn't specified, then I just get an ERROR:

$ python tools\get_config.py -m K64F -t GCC_ARM
[ERROR] list index out of range

@bogdanm Does it ever make sense to run this script without the --source option specified? If not then we should probably make this a required argument.

default=[], help="The source (input) directory", nargs="*")
parser.add_argument("--prefix", dest="prefix", nargs="*",
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, args) = parser.parse_args()
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")
Expand Down
Loading