User | Revision | Line number | New contents of line |
switches |
0:0e018d759a2a
|
1
|
#! /usr/bin/env python
|
switches |
0:0e018d759a2a
|
2
|
"""
|
switches |
0:0e018d759a2a
|
3
|
mbed SDK
|
switches |
0:0e018d759a2a
|
4
|
Copyright (c) 2011-2013 ARM Limited
|
switches |
0:0e018d759a2a
|
5
|
|
switches |
0:0e018d759a2a
|
6
|
Licensed under the Apache License, Version 2.0 (the "License");
|
switches |
0:0e018d759a2a
|
7
|
you may not use this file except in compliance with the License.
|
switches |
0:0e018d759a2a
|
8
|
You may obtain a copy of the License at
|
switches |
0:0e018d759a2a
|
9
|
|
switches |
0:0e018d759a2a
|
10
|
http://www.apache.org/licenses/LICENSE-2.0
|
switches |
0:0e018d759a2a
|
11
|
|
switches |
0:0e018d759a2a
|
12
|
Unless required by applicable law or agreed to in writing, software
|
switches |
0:0e018d759a2a
|
13
|
distributed under the License is distributed on an "AS IS" BASIS,
|
switches |
0:0e018d759a2a
|
14
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
switches |
0:0e018d759a2a
|
15
|
See the License for the specific language governing permissions and
|
switches |
0:0e018d759a2a
|
16
|
limitations under the License.
|
switches |
0:0e018d759a2a
|
17
|
"""
|
switches |
0:0e018d759a2a
|
18
|
import sys
|
switches |
0:0e018d759a2a
|
19
|
from time import time
|
switches |
0:0e018d759a2a
|
20
|
from os.path import join, abspath, dirname, normpath
|
switches |
0:0e018d759a2a
|
21
|
from optparse import OptionParser
|
switches |
0:0e018d759a2a
|
22
|
import json
|
switches |
0:0e018d759a2a
|
23
|
|
switches |
0:0e018d759a2a
|
24
|
# Be sure that the tools directory is in the search path
|
switches |
0:0e018d759a2a
|
25
|
ROOT = abspath(join(dirname(__file__), ".."))
|
switches |
0:0e018d759a2a
|
26
|
sys.path.insert(0, ROOT)
|
switches |
0:0e018d759a2a
|
27
|
|
switches |
0:0e018d759a2a
|
28
|
from tools.build_api import build_library
|
switches |
0:0e018d759a2a
|
29
|
from tools.build_api import write_build_report
|
switches |
0:0e018d759a2a
|
30
|
from tools.targets import TARGET_MAP, TARGET_NAMES
|
switches |
0:0e018d759a2a
|
31
|
from tools.toolchains import TOOLCHAINS
|
switches |
0:0e018d759a2a
|
32
|
from tools.test_exporters import ReportExporter, ResultExporterType
|
switches |
0:0e018d759a2a
|
33
|
from tools.test_api import find_tests, build_tests, test_spec_from_test_builds
|
switches |
0:0e018d759a2a
|
34
|
from tools.build_release import OFFICIAL_MBED_LIBRARY_BUILD
|
switches |
0:0e018d759a2a
|
35
|
|
switches |
0:0e018d759a2a
|
36
|
if __name__ == '__main__':
|
switches |
0:0e018d759a2a
|
37
|
try:
|
switches |
0:0e018d759a2a
|
38
|
parser = OptionParser()
|
switches |
0:0e018d759a2a
|
39
|
|
switches |
0:0e018d759a2a
|
40
|
parser.add_option("--source", dest="source_dir",
|
switches |
0:0e018d759a2a
|
41
|
default=None, help="The source (input) directory (for sources other than tests). Defaults to current directory.", action="append")
|
switches |
0:0e018d759a2a
|
42
|
|
switches |
0:0e018d759a2a
|
43
|
parser.add_option("--build", dest="build_dir",
|
switches |
0:0e018d759a2a
|
44
|
default=None, help="The build (output) directory")
|
switches |
0:0e018d759a2a
|
45
|
|
switches |
0:0e018d759a2a
|
46
|
parser.add_option('-c', '--clean',
|
switches |
0:0e018d759a2a
|
47
|
dest='clean',
|
switches |
0:0e018d759a2a
|
48
|
metavar=False,
|
switches |
0:0e018d759a2a
|
49
|
action="store_true",
|
switches |
0:0e018d759a2a
|
50
|
help='Clean the build directory')
|
switches |
0:0e018d759a2a
|
51
|
|
switches |
0:0e018d759a2a
|
52
|
parser.add_option('-a', '--all', dest="all", default=False, action="store_true",
|
switches |
0:0e018d759a2a
|
53
|
help="Build every target (including unofficial targets) and with each of the supported toolchains")
|
switches |
0:0e018d759a2a
|
54
|
|
switches |
0:0e018d759a2a
|
55
|
parser.add_option('-o', '--official', dest="official_only", default=False, action="store_true",
|
switches |
0:0e018d759a2a
|
56
|
help="Build using only the official toolchain for each target")
|
switches |
0:0e018d759a2a
|
57
|
|
switches |
0:0e018d759a2a
|
58
|
parser.add_option("-D", "",
|
switches |
0:0e018d759a2a
|
59
|
action="append",
|
switches |
0:0e018d759a2a
|
60
|
dest="macros",
|
switches |
0:0e018d759a2a
|
61
|
help="Add a macro definition")
|
switches |
0:0e018d759a2a
|
62
|
|
switches |
0:0e018d759a2a
|
63
|
parser.add_option("-j", "--jobs", type="int", dest="jobs",
|
switches |
0:0e018d759a2a
|
64
|
default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
|
switches |
0:0e018d759a2a
|
65
|
|
switches |
0:0e018d759a2a
|
66
|
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
|
switches |
0:0e018d759a2a
|
67
|
default=False, help="Verbose diagnostic output")
|
switches |
0:0e018d759a2a
|
68
|
|
switches |
0:0e018d759a2a
|
69
|
parser.add_option("-t", "--toolchains", dest="toolchains", help="Use toolchains names separated by comma")
|
switches |
0:0e018d759a2a
|
70
|
|
switches |
0:0e018d759a2a
|
71
|
parser.add_option("-p", "--platforms", dest="platforms", default="", help="Build only for the platform namesseparated by comma")
|
switches |
0:0e018d759a2a
|
72
|
|
switches |
0:0e018d759a2a
|
73
|
parser.add_option("", "--config", action="store_true", dest="list_config",
|
switches |
0:0e018d759a2a
|
74
|
default=False, help="List the platforms and toolchains in the release in JSON")
|
switches |
0:0e018d759a2a
|
75
|
|
switches |
0:0e018d759a2a
|
76
|
parser.add_option("", "--test-spec", dest="test_spec",
|
switches |
0:0e018d759a2a
|
77
|
default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool")
|
switches |
0:0e018d759a2a
|
78
|
|
switches |
0:0e018d759a2a
|
79
|
parser.add_option("", "--build-report-junit", dest="build_report_junit", help="Output the build results to an junit xml file")
|
switches |
0:0e018d759a2a
|
80
|
|
switches |
0:0e018d759a2a
|
81
|
parser.add_option("--continue-on-build-fail", action="store_true", dest="continue_on_build_fail",
|
switches |
0:0e018d759a2a
|
82
|
default=False, help="Continue trying to build all tests if a build failure occurs")
|
switches |
0:0e018d759a2a
|
83
|
|
switches |
0:0e018d759a2a
|
84
|
options, args = parser.parse_args()
|
switches |
0:0e018d759a2a
|
85
|
|
switches |
0:0e018d759a2a
|
86
|
# Get set of valid targets
|
switches |
0:0e018d759a2a
|
87
|
all_platforms = set(TARGET_NAMES)
|
switches |
0:0e018d759a2a
|
88
|
bad_platforms = set()
|
switches |
0:0e018d759a2a
|
89
|
platforms = set()
|
switches |
0:0e018d759a2a
|
90
|
if options.platforms != "":
|
switches |
0:0e018d759a2a
|
91
|
platforms = set(options.platforms.split(","))
|
switches |
0:0e018d759a2a
|
92
|
bad_platforms = platforms.difference(all_platforms)
|
switches |
0:0e018d759a2a
|
93
|
platforms = platforms.intersection(all_platforms)
|
switches |
0:0e018d759a2a
|
94
|
elif options.all:
|
switches |
0:0e018d759a2a
|
95
|
platforms = all_platforms
|
switches |
0:0e018d759a2a
|
96
|
else:
|
switches |
0:0e018d759a2a
|
97
|
platforms = set(x[0] for x in OFFICIAL_MBED_LIBRARY_BUILD)
|
switches |
0:0e018d759a2a
|
98
|
bad_platforms = platforms.difference(all_platforms)
|
switches |
0:0e018d759a2a
|
99
|
platforms = platforms.intersection(all_platforms)
|
switches |
0:0e018d759a2a
|
100
|
|
switches |
0:0e018d759a2a
|
101
|
for bad_platform in bad_platforms:
|
switches |
0:0e018d759a2a
|
102
|
print "Platform '%s' is not a valid platform. Skipping." % bad_platform
|
switches |
0:0e018d759a2a
|
103
|
|
switches |
0:0e018d759a2a
|
104
|
if options.platforms:
|
switches |
0:0e018d759a2a
|
105
|
print "Limiting build to the following platforms: %s" % ",".join(platforms)
|
switches |
0:0e018d759a2a
|
106
|
|
switches |
0:0e018d759a2a
|
107
|
# Get set of valid toolchains
|
switches |
0:0e018d759a2a
|
108
|
all_toolchains = set(TOOLCHAINS)
|
switches |
0:0e018d759a2a
|
109
|
bad_toolchains = set()
|
switches |
0:0e018d759a2a
|
110
|
toolchains = set()
|
switches |
0:0e018d759a2a
|
111
|
|
switches |
0:0e018d759a2a
|
112
|
if options.toolchains:
|
switches |
0:0e018d759a2a
|
113
|
toolchains = set(options.toolchains.split(","))
|
switches |
0:0e018d759a2a
|
114
|
bad_toolchains = toolchains.difference(all_toolchains)
|
switches |
0:0e018d759a2a
|
115
|
toolchains = toolchains.intersection(all_toolchains)
|
switches |
0:0e018d759a2a
|
116
|
else:
|
switches |
0:0e018d759a2a
|
117
|
toolchains = all_toolchains
|
switches |
0:0e018d759a2a
|
118
|
|
switches |
0:0e018d759a2a
|
119
|
for bad_toolchain in bad_toolchains:
|
switches |
0:0e018d759a2a
|
120
|
print "Toolchain '%s' is not a valid toolchain. Skipping." % bad_toolchain
|
switches |
0:0e018d759a2a
|
121
|
|
switches |
0:0e018d759a2a
|
122
|
if options.toolchains:
|
switches |
0:0e018d759a2a
|
123
|
print "Limiting build to the following toolchains: %s" % ",".join(toolchains)
|
switches |
0:0e018d759a2a
|
124
|
|
switches |
0:0e018d759a2a
|
125
|
build_config = {}
|
switches |
0:0e018d759a2a
|
126
|
|
switches |
0:0e018d759a2a
|
127
|
for platform in platforms:
|
switches |
0:0e018d759a2a
|
128
|
target = TARGET_MAP[platform]
|
switches |
0:0e018d759a2a
|
129
|
|
switches |
0:0e018d759a2a
|
130
|
if options.official_only:
|
switches |
0:0e018d759a2a
|
131
|
default_toolchain = getattr(target, 'default_toolchain', 'ARM')
|
switches |
0:0e018d759a2a
|
132
|
build_config[platform] = list(toolchains.intersection(set([default_toolchain])))
|
switches |
0:0e018d759a2a
|
133
|
else:
|
switches |
0:0e018d759a2a
|
134
|
build_config[platform] = list(toolchains.intersection(set(target.supported_toolchains)))
|
switches |
0:0e018d759a2a
|
135
|
|
switches |
0:0e018d759a2a
|
136
|
if options.list_config:
|
switches |
0:0e018d759a2a
|
137
|
print json.dumps(build_config, indent=4)
|
switches |
0:0e018d759a2a
|
138
|
sys.exit(0)
|
switches |
0:0e018d759a2a
|
139
|
|
switches |
0:0e018d759a2a
|
140
|
# Ensure build directory is set
|
switches |
0:0e018d759a2a
|
141
|
if not options.build_dir:
|
switches |
0:0e018d759a2a
|
142
|
print "[ERROR] You must specify a build path"
|
switches |
0:0e018d759a2a
|
143
|
sys.exit(1)
|
switches |
0:0e018d759a2a
|
144
|
|
switches |
0:0e018d759a2a
|
145
|
# Default base source path is the current directory
|
switches |
0:0e018d759a2a
|
146
|
base_source_paths = options.source_dir
|
switches |
0:0e018d759a2a
|
147
|
if not base_source_paths:
|
switches |
0:0e018d759a2a
|
148
|
base_source_paths = ['.']
|
switches |
0:0e018d759a2a
|
149
|
|
switches |
0:0e018d759a2a
|
150
|
|
switches |
0:0e018d759a2a
|
151
|
start = time()
|
switches |
0:0e018d759a2a
|
152
|
build_report = {}
|
switches |
0:0e018d759a2a
|
153
|
build_properties = {}
|
switches |
0:0e018d759a2a
|
154
|
test_builds = {}
|
switches |
0:0e018d759a2a
|
155
|
total_build_success = True
|
switches |
0:0e018d759a2a
|
156
|
|
switches |
0:0e018d759a2a
|
157
|
for target_name, target_toolchains in build_config.iteritems():
|
switches |
0:0e018d759a2a
|
158
|
target = TARGET_MAP[target_name]
|
switches |
0:0e018d759a2a
|
159
|
|
switches |
0:0e018d759a2a
|
160
|
for target_toolchain in target_toolchains:
|
switches |
0:0e018d759a2a
|
161
|
library_build_success = True
|
switches |
0:0e018d759a2a
|
162
|
|
switches |
0:0e018d759a2a
|
163
|
try:
|
switches |
0:0e018d759a2a
|
164
|
build_directory = join(options.build_dir, target_name, target_toolchain)
|
switches |
0:0e018d759a2a
|
165
|
# Build sources
|
switches |
0:0e018d759a2a
|
166
|
build_library(base_source_paths, build_directory, target, target_toolchain,
|
switches |
0:0e018d759a2a
|
167
|
jobs=options.jobs,
|
switches |
0:0e018d759a2a
|
168
|
clean=options.clean,
|
switches |
0:0e018d759a2a
|
169
|
report=build_report,
|
switches |
0:0e018d759a2a
|
170
|
properties=build_properties,
|
switches |
0:0e018d759a2a
|
171
|
name="mbed-os",
|
switches |
0:0e018d759a2a
|
172
|
macros=options.macros,
|
switches |
0:0e018d759a2a
|
173
|
verbose=options.verbose,
|
switches |
0:0e018d759a2a
|
174
|
archive=False)
|
switches |
0:0e018d759a2a
|
175
|
except Exception, e:
|
switches |
0:0e018d759a2a
|
176
|
library_build_success = False
|
switches |
0:0e018d759a2a
|
177
|
print "Failed to build library"
|
switches |
0:0e018d759a2a
|
178
|
print e
|
switches |
0:0e018d759a2a
|
179
|
|
switches |
0:0e018d759a2a
|
180
|
if options.continue_on_build_fail or library_build_success:
|
switches |
0:0e018d759a2a
|
181
|
# Build all the tests
|
switches |
0:0e018d759a2a
|
182
|
all_tests = find_tests(base_source_paths[0], target_name, toolchain_name)
|
switches |
0:0e018d759a2a
|
183
|
test_build_success, test_build = build_tests(all_tests, [build_directory], build_directory, target, target_toolchain,
|
switches |
0:0e018d759a2a
|
184
|
clean=options.clean,
|
switches |
0:0e018d759a2a
|
185
|
report=build_report,
|
switches |
0:0e018d759a2a
|
186
|
properties=build_properties,
|
switches |
0:0e018d759a2a
|
187
|
macros=options.macros,
|
switches |
0:0e018d759a2a
|
188
|
verbose=options.verbose,
|
switches |
0:0e018d759a2a
|
189
|
jobs=options.jobs,
|
switches |
0:0e018d759a2a
|
190
|
continue_on_build_fail=options.continue_on_build_fail)
|
switches |
0:0e018d759a2a
|
191
|
|
switches |
0:0e018d759a2a
|
192
|
if not test_build_success:
|
switches |
0:0e018d759a2a
|
193
|
total_build_success = False
|
switches |
0:0e018d759a2a
|
194
|
print "Failed to build some tests, check build log for details"
|
switches |
0:0e018d759a2a
|
195
|
|
switches |
0:0e018d759a2a
|
196
|
test_builds.update(test_build)
|
switches |
0:0e018d759a2a
|
197
|
else:
|
switches |
0:0e018d759a2a
|
198
|
total_build_success = False
|
switches |
0:0e018d759a2a
|
199
|
break
|
switches |
0:0e018d759a2a
|
200
|
|
switches |
0:0e018d759a2a
|
201
|
# If a path to a test spec is provided, write it to a file
|
switches |
0:0e018d759a2a
|
202
|
if options.test_spec:
|
switches |
0:0e018d759a2a
|
203
|
test_spec_data = test_spec_from_test_builds(test_builds)
|
switches |
0:0e018d759a2a
|
204
|
|
switches |
0:0e018d759a2a
|
205
|
# Create the target dir for the test spec if necessary
|
switches |
0:0e018d759a2a
|
206
|
# mkdir will not create the dir if it already exists
|
switches |
0:0e018d759a2a
|
207
|
test_spec_dir = dirname(options.test_spec)
|
switches |
0:0e018d759a2a
|
208
|
if test_spec_dir:
|
switches |
0:0e018d759a2a
|
209
|
mkdir(test_spec_dir)
|
switches |
0:0e018d759a2a
|
210
|
|
switches |
0:0e018d759a2a
|
211
|
try:
|
switches |
0:0e018d759a2a
|
212
|
with open(options.test_spec, 'w') as f:
|
switches |
0:0e018d759a2a
|
213
|
f.write(json.dumps(test_spec_data, indent=2))
|
switches |
0:0e018d759a2a
|
214
|
except IOError, e:
|
switches |
0:0e018d759a2a
|
215
|
print "[ERROR] Error writing test spec to file"
|
switches |
0:0e018d759a2a
|
216
|
print e
|
switches |
0:0e018d759a2a
|
217
|
|
switches |
0:0e018d759a2a
|
218
|
# If a path to a JUnit build report spec is provided, write it to a file
|
switches |
0:0e018d759a2a
|
219
|
if options.build_report_junit:
|
switches |
0:0e018d759a2a
|
220
|
report_exporter = ReportExporter(ResultExporterType.JUNIT)
|
switches |
0:0e018d759a2a
|
221
|
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
|
switches |
0:0e018d759a2a
|
222
|
|
switches |
0:0e018d759a2a
|
223
|
print "\n\nCompleted in: (%.2f)s" % (time() - start)
|
switches |
0:0e018d759a2a
|
224
|
|
switches |
0:0e018d759a2a
|
225
|
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
|
switches |
0:0e018d759a2a
|
226
|
status = print_report_exporter.report(build_report)
|
switches |
0:0e018d759a2a
|
227
|
|
switches |
0:0e018d759a2a
|
228
|
if status:
|
switches |
0:0e018d759a2a
|
229
|
sys.exit(0)
|
switches |
0:0e018d759a2a
|
230
|
else:
|
switches |
0:0e018d759a2a
|
231
|
sys.exit(1)
|
switches |
0:0e018d759a2a
|
232
|
|
switches |
0:0e018d759a2a
|
233
|
except KeyboardInterrupt, e:
|
switches |
0:0e018d759a2a
|
234
|
print "\n[CTRL+c] exit"
|
switches |
0:0e018d759a2a
|
235
|
except Exception,e:
|
switches |
0:0e018d759a2a
|
236
|
import traceback
|
switches |
0:0e018d759a2a
|
237
|
traceback.print_exc(file=sys.stdout)
|
switches |
0:0e018d759a2a
|
238
|
print "[ERROR] %s" % str(e)
|
switches |
0:0e018d759a2a
|
239
|
sys.exit(1)
|