#!/usr/bin/env python

# Copyright 2015 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script will update Skia's dependencies as necessary and run
# gyp if needed.

# Depends on: Python, Git, and depot_tools.
#
# Example usage:
#
#   git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
#   export PATH="${PWD}/depot_tools:${PATH}"
#   git clone https://skia.googlesource.com/skia
#   cd skia
#   python bin/sync-and-gyp
#   ninja -C out/Debug && out/Debug/dm
#
# Once changes are made to DEPS or gyp/ or the source, call:
#
#   python bin/sync-and-gyp

# To retreive and use all optional deps:
#
#   python bin/sync-and-gyp --deps=all
#   ninja -C out/Debug && out/Debug/dm

import fnmatch
import hashlib
import os
import subprocess
import sys

skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)

skia_out = os.environ.get("SKIA_OUT")
if skia_out:
  skia_out = os.path.abspath(skia_out)
  hash_path = os.path.join(skia_out, 'gyp_hash')
else:
  hash_path = os.path.join('out', 'gyp_hash')

os.chdir(skia_dir)

if 0 != subprocess.call(['python', 'bin/sync'] + sys.argv[1:]):
  sys.stderr.write('sync failed.')
  exit(1)

hasher = hashlib.sha1()

for var in ['AR', 'AR_host', 'AR_target',
            'CC', 'CC_host', 'CC_target',
            'CFLAGS', 'CFLAGS_host',
            'CPPFLAGS', 'CPPFLAGS_host',
            'CXX', 'CXX_host', 'CXX_target',
            'GYP_DEFINES', 'GYP_GENERATORS',
            'NM', 'NM_host', 'NM_target',
            'READELF', 'READELF_host', 'READELF_target']:
  hasher.update(os.environ.get(var, '') + '\n')

def listfiles(folder, matchfilter):
  for root, folders, files in os.walk(folder):
    for filename in files:
      if fnmatch.fnmatch(filename, matchfilter):
        yield os.path.join(root, filename)

for filename in sorted(listfiles('gyp', '*')):
  with open(filename, 'r') as f:
    hasher.update(f.read())

find_dirs = [
    'bench',
    'fuzz',
    'gm',
    'tests',
    'third_party/externals/icu/source/common',
    'third_party/externals/nanomsg/src',
    'third_party/externals/sfntly/sfntly',
    'third_party/externals/shaderc2',
    'tools/VisualBench',
    'tools/gpu',
    'tools/kilobench',
    'tools/skiaserve',
    'tools/skiaserve/urlhandlers',
    'tools/vulkan',
]

for dir in find_dirs:
  for filename in sorted(listfiles(dir, '*.c*')):
    hasher.update(filename + '\n')

gyp_hash = hasher.hexdigest()

def cat_if_exists(path):
  if os.path.exists(path):
    with open(path, 'r') as f:
      return f.read()
  return ''

if cat_if_exists(hash_path).strip() != gyp_hash:
  env = os.environ.copy()
  if skia_out:
    env['SKIA_OUT'] = skia_out
  subprocess.call(['python', './gyp_skia'], env=env)
  with open(hash_path, 'w') as o:
    o.write(gyp_hash)
