Skip to content

Commit

Permalink
Add mechanism to prevent wrong build directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jachris committed Nov 12, 2017
1 parent dd4ebd5 commit ae1f48b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Support for MSVC 2017
- Experimental rules for native Android apps
- New `timeout` parameter for `core.call()`
- Mechanism to prevent accidental deletes by using a wrong build directory

### Changed
- Using `cook --targets` will now list paths relative to the build directory
Expand Down
18 changes: 14 additions & 4 deletions cook/core/system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import shutil
import sys

from os.path import normpath, relpath, join, abspath
from os.path import normpath, relpath, join

from . import log

build_dir = None
intermediate_dir = None
Expand All @@ -11,13 +14,20 @@
def initialize(destination):
global build_dir, intermediate_dir, temporary_dir

build_dir = abspath(destination)
build_dir = os.path.abspath(destination)
cook = os.path.join(build_dir, '.cook/')
intermediate_dir = os.path.join(cook, 'intermediate/')
temporary_dir = os.path.join(cook, 'temporary/')

if not os.path.isdir(destination):
os.makedirs(destination)
if not os.path.isdir(build_dir):
os.makedirs(build_dir)
elif os.listdir(build_dir) and not os.path.isdir(cook):
log.error(
'The build directory "{}" is not empty and does not seem to be '
'the location of a previous build.'.format(build_dir)
)
sys.exit(1)

if not os.path.isdir(cook):
os.mkdir(cook)
if not os.path.isdir(intermediate_dir):
Expand Down

0 comments on commit ae1f48b

Please sign in to comment.