3
3
# Copyright (c) 2016 ARM Limited, All Rights Reserved
4
4
# SPDX-License-Identifier: Apache-2.0
5
5
6
- # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
7
# you may not use this file except in compliance with the License.
8
8
9
9
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
10
10
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13
14
# either express or implied.
14
15
15
16
16
- # pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long, too-many-nested-blocks, too-many-public-methods, too-many-instance-attributes
17
- # pylint: disable=invalid-name, missing-docstring
17
+ # pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long,
18
+ # pylint: disable=too-many-nested-blocks, too-many-public-methods, too-many-instance-attributes, too-many-statements
19
+ # pylint: disable=invalid-name, missing-docstring, bad-continuation
18
20
19
- import argparse
21
+ import traceback
20
22
import sys
21
23
import re
22
24
import subprocess
29
31
from urlparse import urlparse
30
32
import urllib
31
33
import zipfile
34
+ import argparse
32
35
33
36
34
37
# Application version
@@ -227,10 +230,10 @@ def staticclass(cls):
227
230
# Handling for multiple version controls
228
231
scms = {}
229
232
def scm (name ):
230
- def scm (cls ):
233
+ def _scm (cls ):
231
234
scms [name ] = cls ()
232
235
return cls
233
- return scm
236
+ return _scm
234
237
235
238
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
236
239
@scm ('bld' )
@@ -245,19 +248,19 @@ def isurl(url):
245
248
else :
246
249
return False
247
250
248
- def init (path , url ):
251
+ def init (path ):
249
252
if not os .path .exists (path ):
250
253
os .mkdir (path )
251
- with cd (path ):
252
- Bld .seturl (url )
253
254
254
255
def clone (url , path = None , depth = None , protocol = None ):
255
256
m = Bld .isurl (url )
256
257
if not m :
257
258
raise ProcessException (1 , "Not an mbed library build URL" )
258
259
259
260
try :
260
- Bld .init (path , url + '/tip' )
261
+ Bld .init (path )
262
+ with cd (path ):
263
+ Bld .seturl (url + '/tip' )
261
264
except Exception as e :
262
265
error (e [1 ], e [0 ])
263
266
@@ -924,11 +927,11 @@ def __wrap_scm(self, method):
924
927
def __scm_call (* args , ** kwargs ):
925
928
if self .scm and hasattr (self .scm , method ) and callable (getattr (self .scm , method )):
926
929
with cd (self .path ):
927
- return getattr (self .scm , method )(* args , ** kwargs )
930
+ return getattr (self .scm , method )(* args , ** kwargs )
928
931
return __scm_call
929
932
930
- def __getattr__ (self , attr ):
931
- if attr in ['geturl' , 'getrev' , 'add' , 'remove' , 'ignores' , 'ignore' , 'unignore' ,
933
+ def __getattr__ (self , attr ):
934
+ if attr in ['geturl' , 'getrev' , 'add' , 'remove' , 'ignores' , 'ignore' , 'unignore' ,
932
935
'status' , 'dirty' , 'commit' , 'outgoing' , 'publish' , 'checkout' , 'update' ,
933
936
'isdetached' ]:
934
937
wrapper = self .__wrap_scm (attr )
@@ -984,8 +987,8 @@ def clone(self, url, path, depth=None, protocol=None, **kwargs):
984
987
self .ignores ()
985
988
self .set_cache (url )
986
989
return True
987
- else :
988
- return False
990
+
991
+ return False
989
992
990
993
def getlibs (self ):
991
994
for root , dirs , files in os .walk (self .path ):
@@ -1114,10 +1117,10 @@ def __init__(self, path=None, print_warning=False):
1114
1117
warning (
1115
1118
"Could not find mbed program in current path \" %s\" .\n "
1116
1119
"You can fix this by calling \" mbed new .\" or \" mbed default root .\" in the root of your program." % self .path )
1117
-
1120
+
1118
1121
def get_cfg (self , * args , ** kwargs ):
1119
1122
return Cfg (self .path ).get (* args , ** kwargs ) or Global ().get_cfg (* args , ** kwargs )
1120
-
1123
+
1121
1124
def set_cfg (self , * args , ** kwargs ):
1122
1125
return Cfg (self .path ).set (* args , ** kwargs )
1123
1126
@@ -1212,7 +1215,7 @@ def add_tools(self, path):
1212
1215
action ("Couldn't find build tools in your program. Downloading the mbed SDK tools..." )
1213
1216
repo = Repo .fromurl (mbed_sdk_tools_url )
1214
1217
repo .clone (mbed_sdk_tools_url , tools_dir )
1215
- except :
1218
+ except Exception :
1216
1219
if os .path .exists (tools_dir ):
1217
1220
rmtree_readonly (tools_dir )
1218
1221
error ("An error occurred while cloning the mbed SDK tools from \" %s\" " % mbed_sdk_tools_url )
@@ -1252,7 +1255,7 @@ def __init__(self):
1252
1255
1253
1256
def get_cfg (self , * args , ** kwargs ):
1254
1257
return Cfg (self .path ).get (* args , ** kwargs )
1255
-
1258
+
1256
1259
def set_cfg (self , * args , ** kwargs ):
1257
1260
return Cfg (self .path ).set (* args , ** kwargs )
1258
1261
@@ -1342,7 +1345,7 @@ def formaturl(url, format="default"):
1342
1345
1343
1346
# Process handling
1344
1347
def subcommand (name , * args , ** kwargs ):
1345
- def subcommand (command ):
1348
+ def __subcommand (command ):
1346
1349
if not kwargs .get ('description' ) and kwargs .get ('help' ):
1347
1350
kwargs ['description' ] = kwargs ['help' ]
1348
1351
if not kwargs .get ('formatter_class' ):
@@ -1374,7 +1377,7 @@ def thunk(parsed_args):
1374
1377
1375
1378
subparser .set_defaults (command = thunk )
1376
1379
return command
1377
- return subcommand
1380
+ return __subcommand
1378
1381
1379
1382
1380
1383
# New command
@@ -1888,7 +1891,7 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
1888
1891
+ ['-t' , tchain , '-m' , target ]
1889
1892
+ list (chain .from_iterable (izip (repeat ('--source' ), source )))
1890
1893
+ (['-v' ] if verbose else [])
1891
- + (list (chain .from_iterable (izip (repeat ('--prefix' ), prefix ))) if prefix else []),
1894
+ + (list (chain .from_iterable (izip (repeat ('--prefix' ), config_prefix ))) if config_prefix else []),
1892
1895
env = env )
1893
1896
1894
1897
if compile_library :
@@ -1942,7 +1945,7 @@ def test_(toolchain=None, mcu=None, list_compile=False, list_run=False, compile_
1942
1945
program = Program (os .getcwd (), True )
1943
1946
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
1944
1947
orig_path = os .getcwd ()
1945
-
1948
+
1946
1949
# Change directories to the program root to use mbed OS tools
1947
1950
with cd (program .path ):
1948
1951
target = program .get_mcu (mcu )
@@ -1952,21 +1955,21 @@ def test_(toolchain=None, mcu=None, list_compile=False, list_run=False, compile_
1952
1955
1953
1956
env = os .environ .copy ()
1954
1957
env ['PYTHONPATH' ] = os .path .abspath (program .path )
1955
-
1958
+
1956
1959
# Setup the source path if not specified
1957
1960
if not source or len (source ) == 0 :
1958
1961
source = [os .path .relpath (program .path , orig_path )]
1959
-
1962
+
1960
1963
# Setup the build path if not specified
1961
1964
if not build :
1962
1965
build = os .path .join (os .path .relpath (program .path , orig_path ), '.build/tests' , target , tchain )
1963
-
1966
+
1964
1967
# Create the path to the test spec file
1965
1968
test_spec = os .path .join (build , 'test_spec.json' )
1966
-
1969
+
1967
1970
# Determine if building and running tests
1968
1971
build_and_run_tests = not list_compile and not list_run and not compile_only and not run_only
1969
-
1972
+
1970
1973
if compile_only or build_and_run_tests :
1971
1974
cmd = ['python' , '-u' , os .path .join (tools_dir , 'test.py' )]
1972
1975
cmd += list (chain .from_iterable (izip (repeat ('-D' ), macros )))
@@ -1977,37 +1980,37 @@ def test_(toolchain=None, mcu=None, list_compile=False, list_run=False, compile_
1977
1980
cmd += ['--test-spec' , test_spec ]
1978
1981
cmd += (['-n' , tests_by_name ] if tests_by_name else [])
1979
1982
cmd += (['-v' ] if verbose else [])
1980
-
1983
+
1981
1984
try :
1982
1985
popen (cmd + args , env = env )
1983
1986
except ProcessException :
1984
1987
error ('Failed to run the test compiling script' )
1985
-
1988
+
1986
1989
if run_only or build_and_run_tests :
1987
1990
cmd = ['mbedgt' , '--test-spec' , test_spec ]
1988
1991
cmd += (['-n' , tests_by_name ] if tests_by_name else [])
1989
1992
cmd += (['-V' ] if verbose else [])
1990
-
1993
+
1991
1994
try :
1992
1995
popen (cmd + args , env = env )
1993
1996
except ProcessException :
1994
1997
error ('Failed to run test runner' )
1995
-
1998
+
1996
1999
if list_compile :
1997
2000
cmd = ['python' , '-u' , os .path .join (tools_dir , 'test.py' ), '--list' ]
1998
2001
cmd += (['-n' , tests_by_name ] if tests_by_name else [])
1999
2002
cmd += (['-v' ] if verbose else [])
2000
-
2003
+
2001
2004
try :
2002
2005
popen (cmd + args , env = env )
2003
2006
except ProcessException :
2004
2007
error ('Failed to run buildable tests listing script' )
2005
-
2008
+
2006
2009
if list_run :
2007
2010
cmd = ['mbedgt' , '--test-spec' , test_spec , '--list' ]
2008
2011
cmd += (['-n' , tests_by_name ] if tests_by_name else [])
2009
2012
cmd += (['-V' ] if verbose else [])
2010
-
2013
+
2011
2014
try :
2012
2015
popen (cmd + args , env = env )
2013
2016
except ProcessException :
@@ -2033,7 +2036,8 @@ def export(ide=None, mcu=None):
2033
2036
macros = program .get_macros ()
2034
2037
2035
2038
env = os .environ .copy ()
2036
- env ['PYTHONPATH' ] = '.'
2039
+ env ['PYTHONPATH' ] = os .path .abspath (program .path )
2040
+
2037
2041
popen (['python' , '-u' , os .path .join (tools_dir , 'project.py' )]
2038
2042
+ list (chain .from_iterable (izip (repeat ('-D' ), macros )))
2039
2043
+ ['-i' , ide , '-m' , target , '--source=%s' % program .path ]
@@ -2058,7 +2062,8 @@ def detect():
2058
2062
2059
2063
# Prepare environment variables
2060
2064
env = os .environ .copy ()
2061
- env ['PYTHONPATH' ] = '.'
2065
+ env ['PYTHONPATH' ] = os .path .abspath (program .path )
2066
+
2062
2067
popen (['python' , '-u' , os .path .join (tools_dir , 'detect_targets.py' )]
2063
2068
+ args ,
2064
2069
env = env )
@@ -2153,8 +2158,7 @@ def toolchain_(name=None, global_cfg=False):
2153
2158
except KeyboardInterrupt as e :
2154
2159
error ('User aborted!' , 255 )
2155
2160
except Exception as e :
2156
- if verbose :
2157
- import traceback
2161
+ if very_verbose :
2158
2162
traceback .print_exc (file = sys .stdout )
2159
2163
error ("Unknown Error: %s" % e , 255 )
2160
2164
sys .exit (status or 0 )
0 commit comments