Skip to content

Commit 01266cd

Browse files
authored
Merge pull request #374 from screamerbg/development
mbed CLI 0.9.10 fixes
2 parents 23afb59 + e486633 commit 01266cd

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

mbed/mbed.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
# Application version
38-
ver = '0.9.9'
38+
ver = '0.9.10'
3939

4040
# Default paths to Mercurial and Git
4141
hg_cmd = 'hg'
@@ -603,15 +603,24 @@ def checkout(rev, clean=False):
603603
if not rev:
604604
return
605605
info("Checkout \"%s\" in %s" % (rev, os.path.basename(os.getcwd())))
606-
popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q']))
607-
if Git.isdetached(): # try to find associated refs to avoid detached state
608-
refs = Git.getrefs(rev)
609-
for ref in refs: # re-associate with a local or remote branch (rev is the same)
610-
branch = re.sub(r'^(.*?)\/(.*?)$', r'\2', ref)
606+
branch = None
607+
refs = Git.getrefs(rev)
608+
for ref in refs: # re-associate with a local or remote branch (rev is the same)
609+
m = re.match(r'^(.*?)\/(.*?)$', ref)
610+
if m and m.group(2) != "HEAD": # matches origin/<branch> and isn't HEAD ref
611+
if not os.path.exists(os.path.join('.git', 'refs', 'heads', m.group(2))): # okay only if local branch with that name doesn't exist (git will checkout the origin/<branch> in that case)
612+
branch = m.group(2)
613+
elif ref != "HEAD":
614+
branch = ref # matches local branch and isn't HEAD ref
615+
616+
if branch:
611617
info("Revision \"%s\" matches a branch \"%s\" reference. Re-associating with branch" % (rev, branch))
612618
popen([git_cmd, 'checkout', branch] + ([] if very_verbose else ['-q']))
613619
break
614620

621+
if not branch:
622+
popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q']))
623+
615624
def update(rev=None, clean=False, clean_files=False, is_local=False):
616625
if clean:
617626
Git.discard(clean_files)
@@ -701,9 +710,9 @@ def getrev():
701710
return pquery([git_cmd, 'rev-parse', 'HEAD']).strip()
702711

703712
# Gets current branch or returns empty string if detached
704-
def getbranch():
713+
def getbranch(rev='HEAD'):
705714
try:
706-
branch = pquery([git_cmd, 'rev-parse', '--symbolic-full-name', '--abbrev-ref', 'HEAD']).strip()
715+
branch = pquery([git_cmd, 'rev-parse', '--symbolic-full-name', '--abbrev-ref', rev]).strip()
707716
except ProcessException:
708717
branch = "master"
709718
return branch if branch != "HEAD" else ""
@@ -813,13 +822,16 @@ def fromurl(cls, url, path=None):
813822
def fromlib(cls, lib=None):
814823
with open(lib) as f:
815824
ref = f.read(200)
816-
if ref.startswith('!<arch>'):
817-
warning(
818-
"A static library \"%s\" in \"%s\" uses a non-standard .lib file extension, which is not compatible with the mbed build tools.\n"
819-
"Please change the extension of \"%s\" (for example to \"%s\").\n" % (os.path.basename(lib), os.path.split(lib)[0], os.path.basename(lib), os.path.basename(lib).replace('.lib', '.ar')))
820-
return False
821-
else:
822-
return cls.fromurl(ref, lib[:-4])
825+
826+
m_local = re.match(regex_local_ref, ref.strip().replace('\\', '/'))
827+
m_repo_url = re.match(regex_url_ref, ref.strip().replace('\\', '/'))
828+
m_bld_url = re.match(regex_build_url, ref.strip().replace('\\', '/'))
829+
if not (m_local or m_bld_url or m_repo_url):
830+
warning(
831+
"File \"%s\" in \"%s\" uses a non-standard .lib file extension, which is not compatible with the mbed build tools.\n" % (os.path.basename(lib), os.path.split(lib)[0]))
832+
return False
833+
else:
834+
return cls.fromurl(ref, lib[:-4])
823835

824836
@classmethod
825837
def fromrepo(cls, path=None):
@@ -1239,7 +1251,6 @@ def check_requirements(self, show_warning=False):
12391251
missing = []
12401252
except ProcessException:
12411253
warning("Unable to auto-install required Python modules.")
1242-
pass
12431254

12441255
except (IOError, ImportError, OSError):
12451256
pass
@@ -1379,7 +1390,7 @@ def set_cfg(self, *args, **kwargs):
13791390
def list_cfg(self, *args, **kwargs):
13801391
return Cfg(self.path).list(*args, **kwargs)
13811392

1382-
# Cfg classed used for handling the config backend
1393+
# Cfg classed used for handling the config backend
13831394
class Cfg(object):
13841395
path = None
13851396
file = ".mbed"
@@ -1409,7 +1420,6 @@ def set(self, var, val):
14091420
f.write('\n'.join(lines) + '\n')
14101421
except (IOError, OSError):
14111422
warning("Unable to write config file %s" % fl)
1412-
pass
14131423

14141424
# Gets config value
14151425
def get(self, var, default_val=None):
@@ -1791,7 +1801,7 @@ def publish(all_refs=None, msg=None, top=True):
17911801
repo.publish(all_refs)
17921802
else:
17931803
if top:
1794-
action("Nothing to publish to the remote repository (the source tree is unmodified)")
1804+
action("Nothing to publish to the remote repository (the source tree is unmodified)")
17951805
except ProcessException as e:
17961806
if e[0] != 1:
17971807
raise e
@@ -1981,7 +1991,7 @@ def sync(recursive=True, keep_refs=False, top=True):
19811991
def list_(detailed=False, prefix='', p_path=None, ignore=False):
19821992
repo = Repo.fromrepo()
19831993

1984-
print("%s (%s)" % (prefix + (relpath(p_path, repo.path) if p_path else repo.name), ((repo.url+('#'+str(repo.rev)[:12] if repo.rev else '') if detailed else str(repo.rev)[:12]) or 'no revision')))
1994+
print "%s (%s)" % (prefix + (relpath(p_path, repo.path) if p_path else repo.name), ((repo.url+('#'+str(repo.rev)[:12] if repo.rev else '') if detailed else str(repo.rev)[:12]) or 'no revision'))
19851995

19861996
for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)):
19871997
if prefix:
@@ -2151,7 +2161,6 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
21512161
if not build:
21522162
build = os.path.join(program.path, program.build_dir, 'tests', target, tchain)
21532163

2154-
21552164
if test_spec:
21562165
# Preserve path to given test spec
21572166
test_spec = os.path.relpath(os.path.join(orig_path, test_spec), program.path)
@@ -2291,7 +2300,7 @@ def detect():
22912300
def config_(var=None, value=None, global_cfg=False, unset=False, list_config=False):
22922301
name = var
22932302
var = str(var).upper()
2294-
2303+
22952304
if list_config:
22962305
g = Global()
22972306
g_vars = g.list_cfg().items()
@@ -2300,7 +2309,7 @@ def config_(var=None, value=None, global_cfg=False, unset=False, list_config=Fal
23002309
for v in g_vars:
23012310
log("%s=%s\n" % (v[0], v[1]))
23022311
else:
2303-
log("No global configuration is set\n")
2312+
log("No global configuration is set\n")
23042313
log("\n")
23052314

23062315
p = Program(os.getcwd())
@@ -2383,7 +2392,7 @@ def main():
23832392

23842393
# Help messages adapt based on current dir
23852394
cwd_root = os.getcwd()
2386-
2395+
23872396
if sys.version_info[0] != 2 or sys.version_info[1] < 7:
23882397
error(
23892398
"mbed CLI is compatible with Python version >= 2.7 and < 3.0\n"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
setup(
2020
name="mbed-cli",
21-
version="0.9.9",
21+
version="0.9.10",
2222
description="ARM mbed command line tool for repositories version control, publishing and updating code from remotely hosted repositories (GitHub, GitLab and mbed.org), and invoking mbed OS own build system and export functions, among other operations",
2323
long_description=LONG_DESC,
2424
url='http://github.com/ARMmbed/mbed-cli',

0 commit comments

Comments
 (0)