Skip to content

mbed CLI 0.9.10 fixes #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


# Application version
ver = '0.9.9'
ver = '0.9.10'

# Default paths to Mercurial and Git
hg_cmd = 'hg'
Expand Down Expand Up @@ -600,15 +600,24 @@ def checkout(rev, clean=False):
if not rev:
return
info("Checkout \"%s\" in %s" % (rev, os.path.basename(os.getcwd())))
popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q']))
if Git.isdetached(): # try to find associated refs to avoid detached state
refs = Git.getrefs(rev)
for ref in refs: # re-associate with a local or remote branch (rev is the same)
branch = re.sub(r'^(.*?)\/(.*?)$', r'\2', ref)
branch = None
refs = Git.getrefs(rev)
for ref in refs: # re-associate with a local or remote branch (rev is the same)
m = re.match(r'^(.*?)\/(.*?)$', ref)
if m and m.group(2) != "HEAD": # matches origin/<branch> and isn't HEAD ref
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)
branch = m.group(2)
elif ref != "HEAD":
branch = ref # matches local branch and isn't HEAD ref

if branch:
info("Revision \"%s\" matches a branch \"%s\" reference. Re-associating with branch" % (rev, branch))
popen([git_cmd, 'checkout', branch] + ([] if very_verbose else ['-q']))
break

if not branch:
popen([git_cmd, 'checkout', rev] + (['-f'] if clean else []) + ([] if very_verbose else ['-q']))

def update(rev=None, clean=False, clean_files=False, is_local=False):
if clean:
Git.discard(clean_files)
Expand Down Expand Up @@ -698,9 +707,9 @@ def getrev():
return pquery([git_cmd, 'rev-parse', 'HEAD']).strip()

# Gets current branch or returns empty string if detached
def getbranch():
def getbranch(rev='HEAD'):
try:
branch = pquery([git_cmd, 'rev-parse', '--symbolic-full-name', '--abbrev-ref', 'HEAD']).strip()
branch = pquery([git_cmd, 'rev-parse', '--symbolic-full-name', '--abbrev-ref', rev]).strip()
except ProcessException:
branch = "master"
return branch if branch != "HEAD" else ""
Expand Down Expand Up @@ -810,13 +819,16 @@ def fromurl(cls, url, path=None):
def fromlib(cls, lib=None):
with open(lib) as f:
ref = f.read(200)
if ref.startswith('!<arch>'):
warning(
"A static library \"%s\" in \"%s\" uses a non-standard .lib file extension, which is not compatible with the mbed build tools.\n"
"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')))
return False
else:
return cls.fromurl(ref, lib[:-4])

m_local = re.match(regex_local_ref, ref.strip().replace('\\', '/'))
m_repo_url = re.match(regex_url_ref, ref.strip().replace('\\', '/'))
m_bld_url = re.match(regex_build_url, ref.strip().replace('\\', '/'))
if not (m_local or m_bld_url or m_repo_url):
warning(
"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]))
return False
else:
return cls.fromurl(ref, lib[:-4])

@classmethod
def fromrepo(cls, path=None):
Expand Down Expand Up @@ -1236,7 +1248,6 @@ def check_requirements(self, show_warning=False):
missing = []
except ProcessException:
warning("Unable to auto-install required Python modules.")
pass

except (IOError, ImportError, OSError):
pass
Expand Down Expand Up @@ -1376,7 +1387,7 @@ def set_cfg(self, *args, **kwargs):
def list_cfg(self, *args, **kwargs):
return Cfg(self.path).list(*args, **kwargs)

# Cfg classed used for handling the config backend
# Cfg classed used for handling the config backend
class Cfg(object):
path = None
file = ".mbed"
Expand Down Expand Up @@ -1406,7 +1417,6 @@ def set(self, var, val):
f.write('\n'.join(lines) + '\n')
except (IOError, OSError):
warning("Unable to write config file %s" % fl)
pass

# Gets config value
def get(self, var, default_val=None):
Expand Down Expand Up @@ -1788,7 +1798,7 @@ def publish(all_refs=None, msg=None, top=True):
repo.publish(all_refs)
else:
if top:
action("Nothing to publish to the remote repository (the source tree is unmodified)")
action("Nothing to publish to the remote repository (the source tree is unmodified)")
except ProcessException as e:
if e[0] != 1:
raise e
Expand Down Expand Up @@ -1978,7 +1988,7 @@ def sync(recursive=True, keep_refs=False, top=True):
def list_(detailed=False, prefix='', p_path=None, ignore=False):
repo = Repo.fromrepo()

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')))
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'))

for i, lib in enumerate(sorted(repo.libs, key=lambda l: l.path)):
if prefix:
Expand Down Expand Up @@ -2148,7 +2158,6 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
if not build:
build = os.path.join(program.path, program.build_dir, 'tests', target, tchain)


if test_spec:
# Preserve path to given test spec
test_spec = os.path.relpath(os.path.join(orig_path, test_spec), program.path)
Expand Down Expand Up @@ -2288,7 +2297,7 @@ def detect():
def config_(var=None, value=None, global_cfg=False, unset=False, list_config=False):
name = var
var = str(var).upper()

if list_config:
g = Global()
g_vars = g.list_cfg().items()
Expand All @@ -2297,7 +2306,7 @@ def config_(var=None, value=None, global_cfg=False, unset=False, list_config=Fal
for v in g_vars:
log("%s=%s\n" % (v[0], v[1]))
else:
log("No global configuration is set\n")
log("No global configuration is set\n")
log("\n")

p = Program(os.getcwd())
Expand Down Expand Up @@ -2380,7 +2389,7 @@ def main():

# Help messages adapt based on current dir
cwd_root = os.getcwd()

if sys.version_info[0] != 2 or sys.version_info[1] < 7:
error(
"mbed CLI is compatible with Python version >= 2.7 and < 3.0\n"
Expand Down Expand Up @@ -2425,4 +2434,4 @@ def main():


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name="mbed-cli",
version="0.9.9",
version="0.9.10",
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",
long_description=LONG_DESC,
url='http://github.com/ARMmbed/mbed-cli',
Expand Down