Skip to content

Commit

Permalink
Merge pull request #15 from loki04/csibe-args
Browse files Browse the repository at this point in the history
Better argument handling in csibe.py
  • Loading branch information
bgabor666 committed Mar 23, 2016
2 parents b11a654 + 8fae42b commit 04a9ea2
Showing 1 changed file with 99 additions and 13 deletions.
112 changes: 99 additions & 13 deletions csibe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@
import os
import subprocess
import sys
import textwrap

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 +52,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 @@ -78,13 +110,22 @@ def submodule_init_and_update(repository_path):

if __name__ == "__main__":

toolchains = ["native",
"clang-cortex-m0",
"clang-cortex-m4",
"gcc-cortex-m0",
"gcc-cortex-m4"]
toolchains = ['native']
for item in os.listdir('toolchain-files'):
if item.endswith('.cmake'):
toolchains.append(item[:-6])

projects = []
for item in os.listdir('src'):
if os.path.isdir(os.path.join('gen', item)):
projects.append(item)

parser = argparse.ArgumentParser()
helpProjects = "\navailable project names:\n\t" + "\n\t".join(projects)
helpToolchains = "\n\navailable toolchain files:\n\t" + "\n\t".join(toolchains)

parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent(helpProjects + helpToolchains))

parser.add_argument(
"-j",
Expand Down Expand Up @@ -115,19 +156,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 files, 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 04a9ea2

Please sign in to comment.