Skip to content
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

Use old *_build folder in case of a new branch #34

Merged
merged 5 commits into from
Jul 10, 2013
Merged
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
80 changes: 55 additions & 25 deletions build/mixxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,58 +303,88 @@ def virtualize_build_dir(self):
branch_build_dir = os.path.join(cache_dir, branch_name)
virtual_build_dir = os.path.join(branch_build_dir, self.build_dir)
virtual_sconsign_file = os.path.join(branch_build_dir, 'sconsign.dblite')
try:
print "os.makedirs", virtual_build_dir
os.makedirs(virtual_build_dir)
except:
# os.makedirs throws an exception if virtual_build_dir already
# exists.
pass
old_branch_build_dir = ''
old_virtual_build_dir = ''
old_virtual_sconsign_file = ''

# Clean up symlinks from our original method of virtualizing.
if os.path.islink(self.build_dir):
print "os.unlink", self.build_dir
os.unlink(self.build_dir)

sconsign_file = '.sconsign.dblite'
sconsign_branch_file = '.sconsign.branch'
sconsign_branch_file = '.sconsign.branch' #contains the branch name of last build
sconsign_branch = ''
is_branch_different = True
if os.path.isfile(sconsign_branch_file):
with open(sconsign_branch_file, 'r') as f:
sconsign_branch = f.read()
sconsign_branch = f.readline()
sconsign_branch = sconsign_branch.strip()

# check if there was a checkout of a different branch sine the last build
is_branch_different = sconsign_branch != branch_name
if not is_branch_different:
# nothing to do
return

if sconsign_branch:
old_branch_build_dir = os.path.join(cache_dir, sconsign_branch)
old_virtual_build_dir = os.path.join(old_branch_build_dir, self.build_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than rely on Python's function-level scoping for this to exist later on in the function, could you just redefine later on or define them at the top of the function with a default empty string values?

old_virtual_sconsign_file = os.path.join(old_branch_build_dir, 'sconsign.dblite')
if os.path.isdir(self.build_dir):
old_virtual_build_dir = os.path.join(old_branch_build_dir, self.build_dir)
if os.path.isdir(old_virtual_build_dir):
raise Exception('%s already exists. '
'build virtualization cannot continue. Please '
'move or delete it.' % old_virtual_build_dir)
print "shutil.move", self.build_dir, old_virtual_build_dir
#move build dir from last build to chach, named with the old branch name
shutil.move(self.build_dir, old_virtual_build_dir)

if os.path.isfile(sconsign_file):
old_virtual_sconsign_file = os.path.join(old_branch_build_dir, 'sconsign.dblite')
print "shutil.move", sconsign_file, old_virtual_sconsign_file
#move sconsdign-dblite as well
shutil.move(sconsign_file, old_virtual_sconsign_file)

# Now there should be no folder self.build_dir or file sconsign_file.
if os.path.isdir(virtual_build_dir):
if os.path.isdir(self.build_dir):
raise Exception('%s exists without a .sconsign.branch file so '
'build virtualization cannot continue. Please '
'move or delete it.' % self.build_dir)
print "shutil.move", virtual_build_dir, self.build_dir
shutil.move(virtual_build_dir, self.build_dir)
if os.path.isfile(virtual_sconsign_file):
if os.path.isfile(sconsign_file):
raise Exception('%s exists without a .sconsign.branch file so '
'build virtualization cannot continue. Please '
'move or delete it.' % sconsign_file)
print "shutil.move", virtual_sconsign_file, sconsign_file
shutil.move(virtual_sconsign_file, sconsign_file)
if os.path.isdir(branch_build_dir):
if os.path.isdir(virtual_build_dir):
# found a build_dir in cache from a previous build
if os.path.isdir(self.build_dir):
raise Exception('%s exists without a .sconsign.branch file so '
'build virtualization cannot continue. Please '
'move or delete it.' % self.build_dir)
print "shutil.move", virtual_build_dir, self.build_dir
shutil.move(virtual_build_dir, self.build_dir)
if os.path.isfile(virtual_sconsign_file):
if os.path.isfile(sconsign_file):
raise Exception('%s exists without a .sconsign.branch file so '
'build virtualization cannot continue. Please '
'move or delete it.' % sconsign_file)
print "shutil.move", virtual_sconsign_file, sconsign_file
shutil.move(virtual_sconsign_file, sconsign_file)
else:
# no chached build dir found, assume this is a branch from the old branch
# if not, no problem because scons will rebuild all chaned files in any case
# copy the old_virtual_dir back
if sconsign_branch:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if and the two nested ifs (if old_virtual_build_dir and old_virtual_sconsign_file) seem redundant since old_virtual_build_dir will not evaluate to True unless it is a non-empty string and it's only a non-empty string if sconsign_branch is non-empty. Both could probably be removed becuase os.path.isdir('') and isfile('') will return false.

if os.path.isdir(old_virtual_build_dir):
if os.path.isdir(self.build_dir):
raise Exception('%s exists without a .sconsign.branch file so '
'build virtualization cannot continue. Please '
'move or delete it.' % self.build_dir)
print "shutil.copytree", old_virtual_build_dir, self.build_dir
shutil.copytree(old_virtual_build_dir, self.build_dir)
if os.path.isfile(old_virtual_sconsign_file):
if os.path.isfile(sconsign_file):
raise Exception('%s exists without a .sconsign.branch file so '
'build virtualization cannot continue. Please '
'move or delete it.' % sconsign_file)
print "shutil.copy", virtual_sconsign_file, sconsign_file
shutil.copy(old_virtual_sconsign_file, sconsign_file)

# create build dir in cache folder for later move
print "os.makedirs", branch_build_dir
os.makedirs(branch_build_dir)

with open(sconsign_branch_file, 'w+') as f:
print 'touch', sconsign_branch_file
Expand Down