Skip to content

Commit b248827

Browse files
committed
Add script to export mbed SDK tests to different IDEs
1 parent b7301d7 commit b248827

File tree

9 files changed

+129
-48
lines changed

9 files changed

+129
-48
lines changed

workspace_tools/build.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
# Extra libraries
4141
parser.add_option("-r", "--rtos", action="store_true", dest="rtos",
4242
default=False, help="Compile the rtos")
43-
parser.add_option("-b", "--debug", action="store_true", dest="debug",
44-
default=False, help="Compile the debugging library")
45-
parser.add_option("-f", "--fatfs", action="store_true", dest="fatfs",
46-
default=False, help="Compile the fatfs")
4743
parser.add_option("-e", "--eth", action="store_true", dest="eth",
4844
default=False, help="Compile the ethernet library")
4945
parser.add_option("-V", "--vodafone", action="store_true", dest="vodafone",
@@ -56,7 +52,6 @@
5652
default=False, help="Compile the DSP library")
5753
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
5854
default=False, help="Verbose diagnostic output")
59-
6055
(options, args) = parser.parse_args()
6156

6257
# Get target list
@@ -77,18 +72,14 @@
7772
# Additional Libraries
7873
if options.rtos:
7974
libraries.extend(["rtx", "rtos"])
80-
if options.debug:
81-
libraries.append("debug")
82-
if options.fatfs:
83-
libraries.append("fatfs")
84-
if options.usb_host:
85-
libraries.append("usb_host")
8675
if options.eth:
8776
libraries.append("eth")
8877
if options.vodafone:
8978
libraries.append("vodafone")
9079
if options.usb:
9180
libraries.append("usb")
81+
if options.usb_host:
82+
libraries.append("usb_host")
9283
if options.dsp:
9384
libraries.extend(["cmsis_dsp", "dsp"])
9485

workspace_tools/export/__init__.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
limitations under the License.
1616
"""
1717
import os, tempfile
18-
from os.path import join
18+
from os.path import join, exists, basename
19+
from os import makedirs
20+
from shutil import copytree, rmtree
1921

22+
from workspace_tools.utils import mkdir
2023
from workspace_tools.export import uvision4, codesourcery, codered, gccarm, ds5_5, iar
2124
from workspace_tools.export.exporters import zip_working_directory_and_clean_up, OldLibrariesException
2225

@@ -80,3 +83,34 @@ def export(project_path, project_name, ide, target, destination='/tmp/', tempdir
8083
zip_path = zip_working_directory_and_clean_up(tempdir, destination, project_name, clean)
8184

8285
return zip_path, report
86+
87+
88+
###############################################################################
89+
# Generate project folders following the online conventions
90+
###############################################################################
91+
def copy_tree(src, dst, clean=True):
92+
if exists(dst):
93+
if clean:
94+
rmtree(dst)
95+
else:
96+
return
97+
98+
copytree(src, dst)
99+
100+
101+
def setup_user_prj(user_dir, prj_path, lib_paths=None):
102+
"""
103+
Setup a project with the same directory structure of the mbed online IDE
104+
"""
105+
mkdir(user_dir)
106+
107+
# Project Path
108+
copy_tree(prj_path, join(user_dir, "src"))
109+
110+
# Project Libraries
111+
user_lib = join(user_dir, "lib")
112+
mkdir(user_lib)
113+
114+
if lib_paths is not None:
115+
for lib_path in lib_paths:
116+
copy_tree(lib_path, join(user_lib, basename(lib_path)))

workspace_tools/export_test.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,24 @@
1919
ROOT = abspath(join(dirname(__file__), ".."))
2020
sys.path.append(ROOT)
2121

22-
from workspace_tools.paths import *
23-
from workspace_tools.utils import mkdir, cmd, copy_file
24-
from workspace_tools.export import export
22+
from shutil import move
2523

26-
from shutil import copytree
24+
from workspace_tools.paths import *
25+
from workspace_tools.utils import mkdir, cmd
26+
from workspace_tools.export import export, setup_user_prj
2727

28-
EXPORT_DIR = join(BUILD_DIR, "export_test")
29-
USER_WORKSPACE = join(EXPORT_DIR, "user_workspace")
3028

3129
USR_PRJ_NAME = "usr_prj"
32-
USER_PRJ = join(USER_WORKSPACE, USR_PRJ_NAME)
33-
USER_LIB = join(USER_PRJ, "lib")
30+
USER_PRJ = join(EXPORT_WORKSPACE, USR_PRJ_NAME)
3431
USER_SRC = join(USER_PRJ, "src")
3532

36-
TEMP = join(USER_WORKSPACE, ".temp")
37-
3833

3934
def setup_test_user_prj():
4035
if exists(USER_PRJ):
4136
print 'Test user project already generated...'
4237
return
4338

44-
# Build project directory structure
45-
for d in [USER_LIB, USER_SRC]:
46-
mkdir(d)
47-
48-
# Sources
49-
print 'Copying sources...'
50-
copy_file(join(TEST_DIR, "rtos", "mbed", "basic", "main.cpp"), join(USER_SRC, "main.cpp"))
51-
copytree(join(LIB_DIR, "rtos"), join(USER_LIB, "rtos"))
39+
setup_user_prj(USER_PRJ, join(TEST_DIR, "rtos", "mbed", "basic"), [join(LIB_DIR, "rtos")])
5240

5341
# FAKE BUILD URL
5442
open(join(USER_SRC, "mbed.bld"), 'w').write("http://mbed.org/users/mbed_official/code/mbed/builds/976df7c37ad5\n")
@@ -61,17 +49,16 @@ def fake_build_url_resolver(url):
6149

6250
def test_export(toolchain, target, expected_error=None):
6351
if toolchain is None and target is None:
64-
base_dir = join(TEMP, "zip")
52+
base_dir = join(EXPORT_TMP, "zip")
6553
else:
66-
base_dir = join(TEMP, toolchain, target)
54+
base_dir = join(EXPORT_TMP, toolchain, target)
6755
temp_dir = join(base_dir, "temp")
6856
mkdir(temp_dir)
6957

7058
zip_path, report = export(USER_PRJ, USR_PRJ_NAME, toolchain, target, base_dir, temp_dir, False, fake_build_url_resolver)
7159

7260
if report['success']:
73-
export_name = join(EXPORT_DIR, "export_%s_%s.zip" % (toolchain, target))
74-
cmd(["mv", zip_path, export_name])
61+
move(zip_path, join(EXPORT_DIR, "export_%s_%s.zip" % (toolchain, target)))
7562
print "[OK]"
7663
else:
7764
if expected_error is None:

workspace_tools/libraries.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"source_dir": [ETH_SOURCES, LWIP_SOURCES],
7272
"build_dir": ETH_LIBRARY,
7373
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_SOURCES, LWIP_SOURCES],
74-
# "supported": CORTEX_ARM_SUPPORT
7574
},
7675

7776
{

workspace_tools/make.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@
3232
from workspace_tools.tests import TESTS, Test, TEST_MAP
3333
from workspace_tools.paths import BUILD_DIR, RTOS_LIBRARIES
3434
from workspace_tools.targets import TARGET_MAP
35+
from workspace_tools.utils import args_error
3536
try:
3637
import workspace_tools.private_settings as ps
3738
except:
3839
ps = object()
3940

40-
def args_error(parser, message):
41-
print "\n\n%s\n\n" % message
42-
parser.print_help()
43-
sys.exit()
44-
4541

4642
if __name__ == '__main__':
4743
# Parse Options

workspace_tools/paths.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@
7878
# USB Host
7979
USB_HOST = join(LIB_DIR, "USBHost")
8080
USB_HOST_LIBRARIES = join(BUILD_DIR, "usb_host")
81+
82+
# Export
83+
EXPORT_DIR = join(BUILD_DIR, "export")
84+
EXPORT_WORKSPACE = join(EXPORT_DIR, "workspace")
85+
EXPORT_TMP = join(EXPORT_DIR, ".temp")
86+

workspace_tools/project.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import sys
2+
from os.path import join, abspath, dirname, exists
3+
ROOT = abspath(join(dirname(__file__), ".."))
4+
sys.path.append(ROOT)
5+
6+
from shutil import move
7+
from optparse import OptionParser
8+
9+
from workspace_tools.paths import EXPORT_DIR, EXPORT_WORKSPACE, EXPORT_TMP
10+
from workspace_tools.paths import MBED_BASE, MBED_LIBRARIES
11+
from workspace_tools.export import export, setup_user_prj, EXPORTERS
12+
from workspace_tools.utils import args_error
13+
from workspace_tools.tests import TESTS, Test, TEST_MAP
14+
from workspace_tools.targets import TARGET_NAMES
15+
16+
17+
if __name__ == '__main__':
18+
# Parse Options
19+
parser = OptionParser()
20+
21+
parser.add_option("-m", "--mcu", metavar="MCU", default='LPC1768',
22+
help="generate project for the given MCU (%s)" % ', '.join(TARGET_NAMES))
23+
24+
parser.add_option("-p", type="int", dest="program",
25+
help="The index of the desired test program: [0-%d]" % (len(TESTS)-1))
26+
27+
parser.add_option("-i", dest="ide", default='uvision',
28+
help="The target IDE: %s" % str(EXPORTERS.keys()))
29+
30+
parser.add_option("-b", dest="build", action="store_true", default=False,
31+
help="Use the mbed library build, instead of the sources")
32+
33+
(options, args) = parser.parse_args()
34+
35+
# Target
36+
if options.mcu is None :
37+
args_error(parser, "[ERROR] You should specify an MCU")
38+
mcu = options.mcu
39+
40+
# IDE
41+
if options.ide is None:
42+
args_error(parser, "[ERROR] You should specify an IDE")
43+
ide = options.ide
44+
45+
# Project
46+
if options.program is None or (options.program < 0) or (options.program > (len(TESTS)-1)):
47+
message = "[ERROR] You have to specify one of the following tests:\n"
48+
message += '\n'.join(map(str, sorted(TEST_MAP.values())))
49+
args_error(parser, message)
50+
test = Test(options.program)
51+
52+
if not options.build:
53+
# Substitute the library builds with the sources
54+
# TODO: Substitute also the other library build paths
55+
if MBED_LIBRARIES in test.dependencies:
56+
test.dependencies.remove(MBED_LIBRARIES)
57+
test.dependencies.append(MBED_BASE)
58+
59+
# Build the projectwith the same directory structure of the mbed online IDE
60+
project_dir = join(EXPORT_WORKSPACE, test.id)
61+
setup_user_prj(project_dir, test.source_dir, test.dependencies)
62+
63+
# Export to selected toolchain
64+
tmp_path, report = export(project_dir, test.id, ide, mcu, EXPORT_WORKSPACE, EXPORT_TMP)
65+
if report['success']:
66+
zip_path = join(EXPORT_DIR, "%s_%s_%s.zip" % (test.id, ide, mcu))
67+
move(tmp_path, zip_path)
68+
print "[OK]"
69+
else:
70+
print '[ERRROR] %s' % report['errormsg']

workspace_tools/tests.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,49 +503,41 @@
503503
"id": "NET_1", "description": "TCP client hello world",
504504
"source_dir": join(TEST_DIR, "net", "helloworld", "tcpclient"),
505505
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
506-
# "supported": CORTEX_ARM_SUPPORT,
507506
},
508507
{
509508
"id": "NET_2", "description": "UDP client hello world",
510509
"source_dir": join(TEST_DIR, "net", "helloworld", "udpclient"),
511510
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
512-
# "supported": CORTEX_ARM_SUPPORT,
513511
},
514512
{
515513
"id": "NET_3", "description": "TCP echo server",
516514
"source_dir": join(TEST_DIR, "net", "echo", "tcp_server"),
517515
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
518-
# "supported": CORTEX_ARM_SUPPORT,
519516
},
520517
{
521518
"id": "NET_4", "description": "TCP echo client",
522519
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client"),
523520
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
524-
# "supported": CORTEX_ARM_SUPPORT,
525521
},
526522
{
527523
"id": "NET_5", "description": "UDP echo server",
528524
"source_dir": join(TEST_DIR, "net", "echo", "udp_server"),
529525
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
530-
# "supported": CORTEX_ARM_SUPPORT,
531526
},
532527
{
533528
"id": "NET_6", "description": "UDP echo client",
534529
"source_dir": join(TEST_DIR, "net", "echo", "udp_client"),
535530
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
536-
# "supported": CORTEX_ARM_SUPPORT,
537531
},
538532
{
539533
"id": "NET_7", "description": "HTTP client",
540534
"source_dir": join(TEST_DIR, "net", "protocols", "HTTPClient_HelloWorld"),
541535
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
542-
# "supported": CORTEX_ARM_SUPPORT,
543536
},
544537
{
545538
"id": "NET_8", "description": "NTP client",
546539
"source_dir": join(TEST_DIR, "net", "protocols", "NTPClient_HelloWorld"),
547540
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
548-
# "supported": CORTEX_ARM_SUPPORT,
549541
},
550542
{
551543
"id": "NET_9", "description": "Multicast Send",

workspace_tools/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,9 @@ def split_path(path):
8484
base, file = split(path)
8585
name, ext = splitext(file)
8686
return base, name, ext
87+
88+
89+
def args_error(parser, message):
90+
print "\n\n%s\n\n" % message
91+
parser.print_help()
92+
sys.exit()

0 commit comments

Comments
 (0)