Skip to content

Commit a701339

Browse files
authored
Merge pull request #2986 from bulislaw/build_profiles
Accept profile name as well as file path for tools/make.py --profile
2 parents 217a8fb + 3af2c5a commit a701339

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

tools/options.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
"""
1717
from json import load
1818
from os.path import join, dirname
19+
from os import listdir
1920
from argparse import ArgumentParser
2021
from tools.toolchains import TOOLCHAINS
2122
from tools.targets import TARGET_NAMES
2223
from tools.utils import argparse_force_uppercase_type, \
2324
argparse_lowercase_hyphen_type, argparse_many, \
24-
argparse_filestring_type, args_error
25+
argparse_filestring_type, args_error, argparse_profile_filestring_type
2526

2627
def get_default_options_parser(add_clean=True, add_options=True,
2728
add_app_config=False):
@@ -73,7 +74,9 @@ def get_default_options_parser(add_clean=True, add_options=True,
7374

7475
if add_options:
7576
parser.add_argument("--profile", dest="profile", action="append",
76-
type=argparse_filestring_type,
77+
type=argparse_profile_filestring_type,
78+
help="Build profile to use. Can be either path to json" \
79+
"file or one of the default one ({})".format(", ".join(list_profiles())),
7780
default=[])
7881
if add_app_config:
7982
parser.add_argument("--app-config", default=None, dest="app_config",
@@ -82,6 +85,12 @@ def get_default_options_parser(add_clean=True, add_options=True,
8285

8386
return parser
8487

88+
def list_profiles():
89+
"""Lists available build profiles
90+
91+
Checks default profile directory (mbed-os/tools/profiles/) for all the json files and return list of names only
92+
"""
93+
return [fn.replace(".json", "") for fn in listdir(join(dirname(__file__), "profiles")) if fn.endswith(".json")]
8594

8695
def extract_profile(parser, options, toolchain):
8796
"""Extract a Toolchain profile from parsed options

tools/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from os import listdir, remove, makedirs
2323
from shutil import copyfile
2424
from os.path import isdir, join, exists, split, relpath, splitext, abspath
25-
from os.path import commonprefix, normpath
25+
from os.path import commonprefix, normpath, dirname
2626
from subprocess import Popen, PIPE, STDOUT, call
2727
import json
2828
from collections import OrderedDict
@@ -435,6 +435,19 @@ def argparse_filestring_type(string):
435435
raise argparse.ArgumentTypeError(
436436
"{0}"" does not exist in the filesystem.".format(string))
437437

438+
def argparse_profile_filestring_type(string):
439+
""" An argument parser that verifies that a string passed in is either
440+
absolute path or a file name (expanded to
441+
mbed-os/tools/profiles/<fname>.json) of a existing file"""
442+
fpath = join(dirname(__file__), "profiles/{}.json".format(string))
443+
if exists(string):
444+
return string
445+
elif exists(fpath):
446+
return fpath
447+
else:
448+
raise argparse.ArgumentTypeError(
449+
"{0} does not exist in the filesystem.".format(string))
450+
438451
def columnate(strings, separator=", ", chars=80):
439452
""" render a list of strings as a in a bunch of columns
440453

0 commit comments

Comments
 (0)