Skip to content

Commit 1cc251f

Browse files
committed
Merge pull request #683 from PrzemekWirkus/cpputest-export
Tools: Update exporters' capabilities to support CppUTest project exports
2 parents 15d4861 + 1e73f08 commit 1cc251f

File tree

21 files changed

+166
-98
lines changed

21 files changed

+166
-98
lines changed

libraries/tests/utest/basic/basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CppUTest/TestHarness.h"
1+
#include "TestHarness.h"
22

33
TEST_GROUP(FirstTestGroup)
44
{

libraries/tests/utest/general/general.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CppUTest/TestHarness.h"
1+
#include "TestHarness.h"
22
#include <utility>
33
#include "mbed.h"
44

libraries/tests/utest/semihost_fs/semihost_fs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CppUTest/TestHarness.h"
1+
#include "TestHarness.h"
22
#include "mbed.h"
33
#include "semihost_api.h"
44
#include <stdio.h>

libraries/tests/utest/testrunner/testrunner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#include "CppUTest\CommandLineTestRunner.h"
1+
#include "CommandLineTestRunner.h"
22
#include <stdio.h>
33
#include "mbed.h"
44
#include "testrunner.h"
55
#include "test_env.h"
66

77
/**
8-
Object 'console' is used to show prints on console.
8+
Object 'mbed_cpputest_console' is used to show prints on console.
99
It is declared in \cpputest\src\Platforms\armcc\UtestPlatform.cpp
1010
*/
11-
Serial console(STDIO_UART_TX, STDIO_UART_RX);
11+
Serial mbed_cpputest_console(STDIO_UART_TX, STDIO_UART_RX);
1212

1313
int main(int ac, char** av)
1414
{

workspace_tools/build.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
default=False,
8686
help="Compile the u-blox library")
8787

88+
parser.add_option("", "--cpputest",
89+
action="store_true",
90+
dest="cpputest_lib",
91+
default=False,
92+
help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
93+
8894
parser.add_option("-D", "",
8995
action="append",
9096
dest="macros",
@@ -169,6 +175,8 @@
169175
libraries.extend(["fat"])
170176
if options.ublox:
171177
libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
178+
if options.cpputest_lib:
179+
libraries.extend(["cpputest"])
172180

173181
notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
174182

workspace_tools/build_api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def build_project(src_path, build_path, target, toolchain_name,
9292

9393
def build_library(src_paths, build_path, target, toolchain_name,
9494
dependencies_paths=None, options=None, name=None, clean=False,
95-
notify=None, verbose=False, macros=None, inc_dirs=None, jobs=1):
95+
notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None, jobs=1):
9696
""" src_path: the path of the source directory
9797
build_path: the path of the build directory
9898
target: ['LPC1768', 'LPC11U24', 'LPC2368']
@@ -102,6 +102,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
102102
notify: Notify function for logs
103103
verbose: Write the actual tools command lines if True
104104
inc_dirs: additional include directories which should be included in build
105+
inc_dirs_ext: additional include directories which should be copied to library directory
105106
"""
106107
if type(src_paths) != ListType:
107108
src_paths = [src_paths]
@@ -125,6 +126,13 @@ def build_library(src_paths, build_path, target, toolchain_name,
125126
for src_path in src_paths:
126127
resources.append(toolchain.scan_resources(src_path))
127128

129+
# Add extra include directories / files which are required by library
130+
# This files usually are not in the same directory as source files so
131+
# previous scan will not include them
132+
if inc_dirs_ext is not None:
133+
for inc_ext in inc_dirs_ext:
134+
resources.append(toolchain.scan_resources(inc_ext))
135+
128136
# Dependencies Include Paths
129137
dependencies_include_dir = []
130138
if dependencies_paths is not None:
@@ -171,6 +179,7 @@ def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=Fals
171179
macros=MACROS,
172180
notify=notify,
173181
inc_dirs=lib.inc_dirs,
182+
inc_dirs_ext=lib.inc_dirs_ext,
174183
jobs=jobs)
175184
else:
176185
print 'Library "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)

workspace_tools/export/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""
1717
import os, tempfile
1818
from os.path import join, exists, basename
19-
from os import makedirs
2019
from shutil import copytree, rmtree
2120

2221
from workspace_tools.utils import mkdir
@@ -50,7 +49,8 @@ def online_build_url_resolver(url):
5049
return {'path':'', 'name':''}
5150

5251

53-
def export(project_path, project_name, ide, target, destination='/tmp/', tempdir=None, clean=True, build_url_resolver=online_build_url_resolver):
52+
def export(project_path, project_name, ide, target, destination='/tmp/',
53+
tempdir=None, clean=True, extra_symbols=None, build_url_resolver=online_build_url_resolver):
5454
# Convention: we are using capitals for toolchain and target names
5555
if target is not None:
5656
target = target.upper()
@@ -75,7 +75,7 @@ def export(project_path, project_name, ide, target, destination='/tmp/', tempdir
7575
report['errormsg'] = ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN % (target, ide)
7676
else:
7777
try:
78-
exporter = Exporter(target, tempdir, project_name, build_url_resolver)
78+
exporter = Exporter(target, tempdir, project_name, build_url_resolver, extra_symbols=extra_symbols)
7979
exporter.scan_and_copy_resources(project_path, tempdir)
8080
exporter.generate()
8181
report['success'] = True

workspace_tools/export/codered.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def generate(self):
4848
'linker_script': self.resources.linker_script,
4949
'object_files': self.resources.objects,
5050
'libraries': libraries,
51-
'symbols': self.toolchain.get_symbols()
51+
'symbols': self.get_symbols()
5252
}
5353
self.gen_file('codered_%s_project.tmpl' % self.target.lower(), ctx, '.project')
5454
self.gen_file('codered_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')

workspace_tools/export/codesourcery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def generate(self):
5555
'library_paths': self.resources.lib_dirs,
5656
'linker_script': self.resources.linker_script,
5757
'libraries': libraries,
58-
'symbols': self.toolchain.get_symbols()
58+
'symbols': self.get_symbols()
5959
}
6060
self.gen_file('codesourcery_%s.tmpl' % self.target.lower(), ctx, 'Makefile')

workspace_tools/export/coide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def generate(self):
7979
'library_paths': self.resources.lib_dirs,
8080
'object_files': self.resources.objects,
8181
'libraries': libraries,
82-
'symbols': self.toolchain.get_symbols()
82+
'symbols': self.get_symbols()
8383
}
8484
target = self.target.lower()
8585

workspace_tools/export/ds5_5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def generate(self):
5656
'scatter_file': self.resources.linker_script,
5757
'object_files': self.resources.objects + self.resources.libraries,
5858
'source_files': source_files,
59-
'symbols': self.toolchain.get_symbols()
59+
'symbols': self.get_symbols()
6060
}
6161
target = self.target.lower()
6262

workspace_tools/export/emblocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def generate(self):
6666
'script_file': self.resources.linker_script,
6767
'library_paths': self.resources.lib_dirs,
6868
'libraries': libraries,
69-
'symbols': self.toolchain.get_symbols(),
69+
'symbols': self.get_symbols(),
7070
'object_files': self.resources.objects,
7171
'sys_libs': self.toolchain.sys_libs,
7272
'cc_org': self.toolchain.cc[1:],

workspace_tools/export/exporters.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ class Exporter():
1818
TEMPLATE_DIR = dirname(__file__)
1919
DOT_IN_RELATIVE_PATH = False
2020

21-
def __init__(self, target, inputDir, program_name, build_url_resolver):
21+
def __init__(self, target, inputDir, program_name, build_url_resolver, extra_symbols=None):
2222
self.inputDir = inputDir
2323
self.target = target
2424
self.program_name = program_name
2525
self.toolchain = TOOLCHAIN_CLASSES[self.get_toolchain()](TARGET_MAP[target])
2626
self.build_url_resolver = build_url_resolver
2727
jinja_loader = FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))
2828
self.jinja_environment = Environment(loader=jinja_loader)
29+
self.extra_symbols = extra_symbols
2930

3031
def get_toolchain(self):
3132
return self.TOOLCHAIN
@@ -97,6 +98,16 @@ def gen_file(self, template_file, data, target_file):
9798
logging.debug("Generating: %s" % target_path)
9899
open(target_path, "w").write(target_text)
99100

101+
def get_symbols(self, add_extra_symbols=True):
102+
""" This function returns symbols which must be exported.
103+
Please add / overwrite symbols in each exporter separately
104+
"""
105+
symbols = self.toolchain.get_symbols()
106+
# We have extra symbols from e.g. libraries, we want to have them also added to export
107+
if add_extra_symbols:
108+
if self.extra_symbols is not None:
109+
symbols.extend(self.extra_symbols)
110+
return symbols
100111

101112
def zip_working_directory_and_clean_up(tempdirectory=None, destination=None, program_name=None, clean=True):
102113
uid = str(uuid.uuid4())

workspace_tools/export/gccarm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ def generate(self):
9090
'library_paths': self.resources.lib_dirs,
9191
'linker_script': self.resources.linker_script,
9292
'libraries': libraries,
93-
'symbols': self.toolchain.get_symbols()
93+
'symbols': self.get_symbols()
9494
}
9595
self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile')

workspace_tools/export/iar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def generate(self):
5959
'linker_script': self.resources.linker_script,
6060
'object_files': self.resources.objects,
6161
'libraries': self.resources.libraries,
62-
'symbols': self.toolchain.get_symbols(),
62+
'symbols': self.get_symbols(),
6363
'source_files': sources,
6464
}
6565
self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)

workspace_tools/export/kds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def generate(self):
3939
'linker_script': self.resources.linker_script,
4040
'object_files': self.resources.objects,
4141
'libraries': libraries,
42-
'symbols': self.toolchain.get_symbols()
42+
'symbols': self.get_symbols()
4343
}
4444
self.gen_file('kds_%s_project.tmpl' % self.target.lower(), ctx, '.project')
4545
self.gen_file('kds_%s_cproject.tmpl' % self.target.lower(), ctx, '.cproject')

workspace_tools/export/uvision4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def generate(self):
123123
'scatter_file': self.resources.linker_script,
124124
'object_files': self.resources.objects + self.resources.libraries,
125125
'source_files': source_files.items(),
126-
'symbols': self.toolchain.get_symbols() + ['__ASSERT_MSG'],
126+
'symbols': self.get_symbols() + ['__ASSERT_MSG'],
127127
'hex_files' : self.resources.hex_files,
128128
'flags' : self.get_flags(),
129129
}

workspace_tools/libraries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"build_dir": CPPUTEST_LIBRARY,
9595
"dependencies": [MBED_LIBRARIES],
9696
'inc_dirs': [CPPUTEST_INC, CPPUTEST_PLATFORM_INC, CPPUTEST_TESTRUNNER_INC, TEST_MBED_LIB],
97-
'inc_dirs_ext': [CPPUTEST_INC],
97+
'inc_dirs_ext': [CPPUTEST_INC_EXT],
9898
'macros': ["CPPUTEST_USE_MEM_LEAK_DETECTION=0", "CPPUTEST_USE_STD_CPP_LIB=0", "CPPUTEST=1"],
9999
},
100100
]

workspace_tools/paths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@
9595

9696
# CppUtest library
9797
CPPUTEST_DIR = join(ROOT, "..")
98-
CPPUTEST_SRC = join(CPPUTEST_DIR, "cpputest", "src", "CppUTest") #, "CppUTest"
99-
CPPUTEST_INC = join(CPPUTEST_DIR, "cpputest", "include") #, "CppUTest"
98+
CPPUTEST_SRC = join(CPPUTEST_DIR, "cpputest", "src", "CppUTest")
99+
CPPUTEST_INC = join(CPPUTEST_DIR, "cpputest", "include")
100+
CPPUTEST_INC_EXT = join(CPPUTEST_DIR, "cpputest", "include", "CppUTest")
100101
# Platform dependant code is here (for armcc compiler)
101102
CPPUTEST_PLATFORM_SRC = join(CPPUTEST_DIR, "cpputest", "src", "Platforms", "armcc")
102103
CPPUTEST_PLATFORM_INC = join(CPPUTEST_DIR, "cpputest", "include", "Platforms", "armcc")

0 commit comments

Comments
 (0)