Skip to content

Commit

Permalink
Better argument handling in csibe.py
Browse files Browse the repository at this point in the history
  • Loading branch information
loki04 committed Mar 13, 2016
1 parent b11a654 commit b8c74a5
Showing 1 changed file with 87 additions and 7 deletions.
94 changes: 87 additions & 7 deletions csibe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,30 @@

class CSiBEBuilder(object):

def __init__(self, csibe_path, build_path, toolchain_name):
def __init__(self, csibe_path, build_path, toolchain_name, projects, flags):

self.csibe_dir = csibe_path
self.build_dir = build_path
self.toolchain_name = toolchain_name
self.projects = projects

self.cflags = []
self.cxxflags = []
self.rustcflags = []

if flags['cflags']:
self.cflags.extend(flags['cflags'])

if flags['cxxflags']:
self.cxxflags.extend(flags['cxxflags'])

if flags['rustcflags']:
self.rustcflags.extend(flags['rustcflags'])

if flags['globalflags']:
self.cflags.extend(flags['globalflags'])
self.cxxflags.extend(flags['globalflags'])
self.rustcflags.extend(flags['globalflags'])

self.toolchain_build_dir = os.path.join(
self.build_dir,
Expand All @@ -32,6 +51,18 @@ def __init__(self, csibe_path, build_path, toolchain_name):
if self.toolchain_file_path:
self.cmake_toolchain_options = "-DCMAKE_TOOLCHAIN_FILE={}".format(self.toolchain_file_path)

if self.projects:
os.environ['CSiBE_SUBPROJECTS'] = " ".join(self.projects);

if self.cflags:
os.environ['CSiBE_CFLAGS'] = " ".join(self.cflags);

if self.cxxflags:
os.environ['CSiBE_CXXFLAGS'] = " ".join(self.cxxflags);

if self.rustcflags:
os.environ['CSiBE_RUSTCFLAGS'] = " ".join(self.rustcflags);

def run_cmake(self):
return subprocess.call(
["cmake",
Expand Down Expand Up @@ -84,6 +115,10 @@ def submodule_init_and_update(repository_path):
"gcc-cortex-m0",
"gcc-cortex-m4"]

projects = []
for item in os.listdir('src'):
projects.append(item)

parser = argparse.ArgumentParser()

parser.add_argument(
Expand Down Expand Up @@ -115,19 +150,64 @@ def submodule_init_and_update(repository_path):
default="build",
help="directory name for build files")

args = parser.parse_args()
parser.add_argument(
"--cflags",
action='append',
help="compiler flags for C files")

parser.add_argument(
"--cxxflags",
action='append',
help="compiler flags for CXX files")

parser.add_argument(
"--rustcflags",
action='append',
help="compiler flags for Rust files")

parser.add_argument(
"--globalflags",
action='append',
help="compiler flags for CXX files")

parser.add_argument(
"option",
nargs="*",
help="can be project names, toolchain file, or compiler flags")

args, global_flags = parser.parse_known_args()

if args.globalflags:
global_flags.append(args.globalflags)

csibe_path = os.path.dirname(os.path.realpath(__file__))

submodule_init_and_update(csibe_path)

if args.build_all:
targets_to_build = toolchains
else:
targets_to_build = [args.toolchain]
# Target selection
targets_to_build = []
for opt in args.option:
if opt in toolchains:
targets_to_build.append(opt)

if not targets_to_build:
if args.build_all:
targets_to_build = toolchains
else:
targets_to_build = [args.toolchain]

# Project selection
projects_to_build = []
for opt in args.option:
if opt in projects:
projects_to_build.append(opt)

for target in targets_to_build:
builder = CSiBEBuilder(csibe_path, args.build_dir, target)
builder = CSiBEBuilder(csibe_path, args.build_dir, target, projects_to_build,
{'cflags' : args.cflags,
'cxxflags' : args.cxxflags,
'rustcflags' : args.rustcflags,
'globalflags' : global_flags})

cmake_return_value = builder.run_cmake()
if cmake_return_value:
Expand Down

0 comments on commit b8c74a5

Please sign in to comment.