Skip to content

Commit

Permalink
Update building to allow individual challenges to be built
Browse files Browse the repository at this point in the history
  • Loading branch information
krx committed Jul 29, 2016
1 parent 3209acd commit 71b3ce9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
13 changes: 2 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@ if [[ $? -ne 0 ]]; then
exit 1
fi

# Check if the patched challenges are already there
REGEN=0
if [[ -d "$DIR/cqe-challenges" && -n "$(ls -A "$DIR/cqe-challenges" 2>/dev/null)" ]]; then
prompt "Patched challenges already exist. Delete and regenerate?"
REGEN=$?
fi

if [[ ${REGEN} == 0 ]]; then
echo "Generating patched challenges..."#
${TOOLS}/cb_patcher.py
fi
echo "Running patcher"
${TOOLS}/cb_patcher.py $@

echo "Generating CMakelists"
${TOOLS}/makefiles.py
Expand Down
32 changes: 26 additions & 6 deletions tools/cb_patcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import glob
import os
import shutil
import sys
Expand Down Expand Up @@ -95,17 +96,36 @@ def listdir(path):
return sorted(os.listdir(path))


def clear_challenges():
"""Delete all patched directories"""
for chal in listdir(CHALLENGE_PATH):
shutil.rmtree(os.path.join(CHALLENGE_PATH, chal))
def clear_challenges(chal_paths):
"""Delete patched challenge directories"""
for chal in chal_paths:
try:
shutil.rmtree(chal)
except OSError:
pass


def main():
clear_challenges()
# Check which challenges to patch
if len(sys.argv) > 1:
# Filter out any invalid challenges
chals = set(sys.argv[1:]).intersection(listdir(ORIGINAL_CHALLS))

# Delete the old challenge folders
clear_challenges([os.path.join(CHALLENGE_PATH, c) for c in chals])
else:
# Get all challenges
chals = listdir(ORIGINAL_CHALLS)

# Prompt before deleting all old challenges
existing_chals = glob.glob(os.path.join(CHALLENGE_PATH, '*', ''))
if len(existing_chals) > 0:
res = raw_input('Patched challenges already exist. Delete and regenerate? (y/n): ') or 'n'
if res[0] in 'yY':
clear_challenges(existing_chals)

# Copy over one challenge at a time and patch it
for chal in listdir(ORIGINAL_CHALLS): # Only a few for now
for chal in chals: # Only a few for now
chal_dir = os.path.join(ORIGINAL_CHALLS, chal)
if os.path.isdir(chal_dir):
shutil.copytree(chal_dir,
Expand Down

0 comments on commit 71b3ce9

Please sign in to comment.