Skip to content

Commit

Permalink
roomservice.py: Fixups around fallback branches not being used by dep…
Browse files Browse the repository at this point in the history
…endencies when ROOMSERVICE_BRANCHES is defined.

Change-Id: Ifb42a023cae5f62ac8f9cf7832125b91b431169c
  • Loading branch information
koush committed Jan 10, 2013
1 parent b10200a commit 5584637
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tools/roomservice.py
Expand Up @@ -128,7 +128,7 @@ def is_in_manifest(projectname):

return None

def add_to_manifest(repositories):
def add_to_manifest(repositories, fallback_branch = None):
try:
lm = ElementTree.parse(".repo/local_manifest.xml")
lm = lm.getroot()
Expand All @@ -148,6 +148,11 @@ def add_to_manifest(repositories):

if 'branch' in repository:
project.set('revision',repository['branch'])
elif fallback_branch:
print "Using fallback branch %s for %s" % (fallback_branch, repo_name)
project.set('revision', fallback_branch)
else:
print "Using default branch for %s" % repo_name

lm.append(project)

Expand All @@ -159,7 +164,7 @@ def add_to_manifest(repositories):
f.write(raw_xml)
f.close()

def fetch_dependencies(repo_path):
def fetch_dependencies(repo_path, fallback_branch = None):
print 'Looking for dependencies'
dependencies_path = repo_path + '/cm.dependencies'
syncable_repos = []
Expand All @@ -178,7 +183,7 @@ def fetch_dependencies(repo_path):

if len(fetch_list) > 0:
print 'Adding dependencies to manifest'
add_to_manifest(fetch_list)
add_to_manifest(fetch_list, fallback_branch)
else:
print 'Dependencies file not found, bailing out.'

Expand Down Expand Up @@ -216,32 +221,31 @@ def has_branch(branches, revision):
repo_path = "device/%s/%s" % (manufacturer, device)
adding = {'repository':repo_name,'target_path':repo_path}

fallback_branch = None
if not has_branch(result, default_revision):
found = False
if os.getenv('ROOMSERVICE_BRANCHES'):
fallbacks = filter(bool, os.getenv('ROOMSERVICE_BRANCHES').split(' '))
for fallback in fallbacks:
if has_branch(result, fallback):
print "Using fallback branch: %s" % fallback
found = True
adding['branch'] = fallback
fallback_branch = fallback
break
if not found:

if not fallback_branch:
print "Default revision %s not found in %s. Bailing." % (default_revision, repo_name)
print "Branches found:"
for branch in [branch['name'] for branch in result]:
print branch
print "Use the ROOMSERVICE_BRANCHES environment variable to specify a list of fallback branches."
sys.exit()

add_to_manifest([adding])
add_to_manifest([adding], fallback_branch)

print "Syncing repository to retrieve project."
os.system('repo sync %s' % repo_path)
print "Repository synced!"

fetch_dependencies(repo_path)
fetch_dependencies(repo_path, fallback_branch)
print "Done"
sys.exit()

Expand Down

0 comments on commit 5584637

Please sign in to comment.