Skip to content

Commit 9f62d70

Browse files
committed
Update project generator script to allow working with any source
Update test exporters script Update travis build script Added config system CLI script Fixed building of legacy libraries and layouts
1 parent c2e3001 commit 9f62d70

File tree

7 files changed

+326
-85
lines changed

7 files changed

+326
-85
lines changed

tools/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
if options.usb_host:
193193
libraries.append("usb_host")
194194
if options.dsp:
195-
libraries.extend(["cmsis_dsp", "dsp"])
195+
libraries.extend(["dsp"])
196196
if options.fat:
197197
libraries.extend(["fat"])
198198
if options.ublox:

tools/build_api.py

Lines changed: 134 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -394,33 +394,145 @@ def build_library(src_paths, build_path, target, toolchain_name,
394394
# Let Exception propagate
395395
raise e
396396

397-
def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
398-
""" Wrapper for build_library function.
397+
######################
398+
### Legacy methods ###
399+
######################
400+
401+
def build_lib(lib_id, target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
402+
""" Legacy method for building mbed libraries
399403
Function builds library in proper directory using all dependencies and macros defined by user.
400404
"""
401405
lib = Library(lib_id)
402-
if lib.is_supported(target, toolchain):
403-
# We need to combine macros from parameter list with macros from library definition
404-
MACROS = lib.macros if lib.macros else []
405-
if macros:
406-
MACROS.extend(macros)
407-
408-
return build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options,
409-
verbose=verbose,
410-
silent=silent,
411-
clean=clean,
412-
macros=MACROS,
413-
notify=notify,
414-
inc_dirs=lib.inc_dirs,
415-
inc_dirs_ext=lib.inc_dirs_ext,
416-
jobs=jobs,
417-
report=report,
418-
properties=properties,
419-
extra_verbose=extra_verbose)
420-
else:
406+
if not lib.is_supported(target, toolchain_name):
421407
print 'Library "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
422408
return False
409+
410+
# We need to combine macros from parameter list with macros from library definition
411+
MACROS = lib.macros if lib.macros else []
412+
if macros:
413+
macros.extend(MACROS)
414+
else:
415+
macros = MACROS
416+
417+
src_paths = lib.source_dir
418+
build_path = lib.build_dir
419+
dependencies_paths = lib.dependencies
420+
inc_dirs = lib.inc_dirs
421+
inc_dirs_ext = lib.inc_dirs_ext
422+
423+
""" src_path: the path of the source directory
424+
build_path: the path of the build directory
425+
target: ['LPC1768', 'LPC11U24', 'LPC2368']
426+
toolchain: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CR']
427+
library_paths: List of paths to additional libraries
428+
clean: Rebuild everything if True
429+
notify: Notify function for logs
430+
verbose: Write the actual tools command lines if True
431+
inc_dirs: additional include directories which should be included in build
432+
inc_dirs_ext: additional include directories which should be copied to library directory
433+
"""
434+
if type(src_paths) != ListType:
435+
src_paths = [src_paths]
436+
437+
# The first path will give the name to the library
438+
name = basename(src_paths[0])
439+
440+
if report != None:
441+
start = time()
442+
id_name = name.upper()
443+
description = name
444+
vendor_label = target.extra_labels[0]
445+
cur_result = None
446+
prep_report(report, target.name, toolchain_name, id_name)
447+
cur_result = create_result(target.name, toolchain_name, id_name, description)
423448

449+
if properties != None:
450+
prep_properties(properties, target.name, toolchain_name, vendor_label)
451+
452+
for src_path in src_paths:
453+
if not exists(src_path):
454+
error_msg = "The library source folder does not exist: %s", src_path
455+
456+
if report != None:
457+
cur_result["output"] = error_msg
458+
cur_result["result"] = "FAIL"
459+
add_result_to_report(report, cur_result)
460+
461+
raise Exception(error_msg)
462+
463+
try:
464+
# Toolchain instance
465+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose)
466+
toolchain.VERBOSE = verbose
467+
toolchain.jobs = jobs
468+
toolchain.build_all = clean
469+
470+
toolchain.info("Building library %s (%s, %s)" % (name.upper(), target.name, toolchain_name))
471+
472+
# Scan Resources
473+
resources = []
474+
for src_path in src_paths:
475+
resources.append(toolchain.scan_resources(src_path))
476+
477+
# Add extra include directories / files which are required by library
478+
# This files usually are not in the same directory as source files so
479+
# previous scan will not include them
480+
if inc_dirs_ext is not None:
481+
for inc_ext in inc_dirs_ext:
482+
resources.append(toolchain.scan_resources(inc_ext))
483+
484+
# Dependencies Include Paths
485+
dependencies_include_dir = []
486+
if dependencies_paths is not None:
487+
for path in dependencies_paths:
488+
lib_resources = toolchain.scan_resources(path)
489+
dependencies_include_dir.extend(lib_resources.inc_dirs)
490+
491+
if inc_dirs:
492+
dependencies_include_dir.extend(inc_dirs)
493+
494+
# Create the desired build directory structure
495+
bin_path = join(build_path, toolchain.obj_path)
496+
mkdir(bin_path)
497+
tmp_path = join(build_path, '.temp', toolchain.obj_path)
498+
mkdir(tmp_path)
499+
500+
# Copy Headers
501+
for resource in resources:
502+
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
503+
dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
504+
505+
# Compile Sources
506+
objects = []
507+
for resource in resources:
508+
objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))
509+
510+
needed_update = toolchain.build_library(objects, bin_path, name)
511+
512+
if report != None and needed_update:
513+
end = time()
514+
cur_result["elapsed_time"] = end - start
515+
cur_result["output"] = toolchain.get_output()
516+
cur_result["result"] = "OK"
517+
518+
add_result_to_report(report, cur_result)
519+
520+
except Exception, e:
521+
if report != None:
522+
end = time()
523+
cur_result["result"] = "FAIL"
524+
cur_result["elapsed_time"] = end - start
525+
526+
toolchain_output = toolchain.get_output()
527+
if toolchain_output:
528+
cur_result["output"] += toolchain_output
529+
530+
cur_result["output"] += str(e)
531+
532+
add_result_to_report(report, cur_result)
533+
534+
# Let Exception propagate
535+
raise e
424536

425537
# We do have unique legacy conventions about how we build and package the mbed library
426538
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
@@ -543,6 +655,7 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F
543655
# Let Exception propagate
544656
raise e
545657

658+
546659
def get_unique_supported_toolchains():
547660
""" Get list of all unique toolchains supported by targets """
548661
unique_supported_toolchains = []

tools/get_config.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#! /usr/bin/env python2
2+
"""
3+
mbed SDK
4+
Copyright (c) 2011-2013 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
"""
19+
import sys
20+
from os.path import isdir, abspath, dirname, join
21+
from os import _exit
22+
23+
# Be sure that the tools directory is in the search path
24+
ROOT = abspath(join(dirname(__file__), ".."))
25+
sys.path.insert(0, ROOT)
26+
27+
from tools.utils import args_error
28+
from tools.options import get_default_options_parser
29+
from tools.build_api import get_config
30+
from config import Config
31+
try:
32+
import tools.private_settings as ps
33+
except:
34+
ps = object()
35+
36+
if __name__ == '__main__':
37+
# Parse Options
38+
parser = get_default_options_parser(add_clean=False, add_options=False)
39+
parser.add_option("--source", dest="source_dir",
40+
default=None, help="The source (input) directory", action="append")
41+
parser.add_option("--prefix", dest="prefix", action="append",
42+
default=None, help="Restrict listing to parameters that have this prefix")
43+
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
44+
default=False, help="Verbose diagnostic output")
45+
46+
(options, args) = parser.parse_args()
47+
48+
for path in options.source_dir :
49+
if not isdir(path) :
50+
args_error(parser, "[ERROR] you passed \"{}\" to --source, which does not exist".
51+
format(path))
52+
# Target
53+
if options.mcu is None :
54+
args_error(parser, "[ERROR] You should specify an MCU")
55+
target = options.mcu
56+
57+
# Toolchain
58+
if options.tool is None:
59+
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
60+
toolchain = options.tool
61+
62+
options.prefix = options.prefix or [""]
63+
64+
try:
65+
params, macros = get_config(options.source_dir, target, toolchain)
66+
if not params and not macros:
67+
print "No configuration data available."
68+
_exit(0)
69+
if params:
70+
print "Configuration parameters"
71+
print "------------------------"
72+
for p in params:
73+
for s in options.prefix:
74+
if p.startswith(s):
75+
print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
76+
break
77+
print ""
78+
79+
print "Macros"
80+
print "------"
81+
if macros:
82+
print 'Defined with "macros":', macros
83+
print "Generated from configuration parameters:", Config.parameters_to_macros(params)
84+
85+
except KeyboardInterrupt, e:
86+
print "\n[CTRL+c] exit"
87+
except Exception,e:
88+
if options.verbose:
89+
import traceback
90+
traceback.print_exc(file=sys.stdout)
91+
else:
92+
print "[ERROR] %s" % str(e)
93+
94+
sys.exit(1)

tools/libraries.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,11 @@
5959
},
6060

6161
# DSP libraries
62-
{
63-
"id": "cmsis_dsp",
64-
"source_dir": DSP_CMSIS,
65-
"build_dir": DSP_LIBRARIES,
66-
"dependencies": [MBED_LIBRARIES],
67-
},
6862
{
6963
"id": "dsp",
70-
"source_dir": DSP_ABSTRACTION,
64+
"source_dir": [DSP_ABSTRACTION, DSP_CMSIS],
7165
"build_dir": DSP_LIBRARIES,
72-
"dependencies": [MBED_LIBRARIES, DSP_CMSIS],
66+
"dependencies": [MBED_LIBRARIES]
7367
},
7468

7569
# File system libraries

0 commit comments

Comments
 (0)