import os
import shutil
import sys
BUILDTYPE = 'Debug'
TARGET_ALL = 'all'
TARGET_CLEAN = 'clean'
TARGET_DEFAULT = 'most'
TARGET_GYP = 'gyp'
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
OUT_SUBDIR = os.environ.get('SKIA_OUT', 'out')
GYP_SUBDIR = 'gyp'
def cd(path):
print '> cd %s' % path
if not os.path.isdir(path):
print 'directory %s does not exist' % path
sys.exit(1)
os.chdir(path)
def rmtree(path):
print '> rmtree %s' % path
shutil.rmtree(path, ignore_errors=True)
def runcommand(command):
print '> %s' % command
if os.system(command):
sys.exit(1)
def MakeClean():
cd(SCRIPT_DIR)
rmtree(OUT_SUBDIR)
def CheckWindowsEnvironment():
try:
env_DevEnvDir = os.environ['DevEnvDir']
return except KeyError:
pass
print ('\nCould not find Visual Studio environment variables.'
'\nPerhaps you have not yet run vcvars32.bat as described at'
'\nhttp://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx ?')
found_path = None
try:
possible_path = os.path.abspath(os.path.join(
os.environ['VS100COMNTOOLS'], os.path.pardir, os.path.pardir,
'VC', 'bin', 'vcvars32.bat'))
if os.path.exists(possible_path):
found_path = possible_path
except KeyError:
pass
if found_path:
print '\nIt looks like you can run that script at:\n%s' % found_path
else:
print '\nUnable to find vcvars32.bat on your system.'
sys.exit(1)
def MakeWindows(targets):
if os.environ.get('CHROME_HEADLESS', '0') != '1':
CheckWindowsEnvironment()
cd(SCRIPT_DIR)
runcommand('python gyp_skia')
while TARGET_GYP in targets:
targets.remove(TARGET_GYP)
if targets:
runcommand('ninja -C %s %s' % (
os.path.join(OUT_SUBDIR, BUILDTYPE), ' '.join(targets)))
def Make(args):
global BUILDTYPE
if not args:
args = [TARGET_DEFAULT]
targets = []
for arg in args:
if arg == TARGET_ALL:
targets.append('everything')
elif arg == TARGET_CLEAN:
MakeClean()
elif arg.startswith('BUILDTYPE='):
BUILDTYPE = arg[10:]
elif arg.startswith('GYP_DEFINES='):
os.environ['GYP_DEFINES'] = arg[12:]
else:
targets.append(arg)
if not targets:
sys.exit(0)
if os.name == 'nt':
MakeWindows(targets)
sys.exit(0)
elif os.name == 'posix':
if sys.platform == 'darwin':
print 'Mac developers should not run this script; see ' \
'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/mac'
sys.exit(1)
elif sys.platform == 'cygwin':
print 'Windows development on Cygwin is not currently supported; see ' \
'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/windows'
sys.exit(1)
else:
print 'Unix developers should not run this script; see ' \
'https://sites.google.com/site/skiadocs/user-documentation/quick-start-guides/linux'
sys.exit(1)
else:
print 'unknown platform (os.name=%s, sys.platform=%s); see %s' % (
os.name, sys.platform, 'https://sites.google.com/site/skiadocs/')
sys.exit(1)
sys.exit(0)
Make(sys.argv[1:])