skia2/infra/bots/check_deps.py
Hal Canary 389c8e9d2d [minor] mark scripts as executable
if a filename ends with `.py` and  the file begins with '#!.*python.*',
make it executable.

Change-Id: I41de516ff37343d3b0979bde9fd61813aec7365c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254439
Commit-Queue: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-11-21 17:06:27 +00:00

65 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python
#
# Copyright 2019 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Check the DEPS file for correctness."""
import os
import re
import subprocess
import sys
import utils
INFRA_BOTS_DIR = os.path.dirname(os.path.realpath(__file__))
SKIA_DIR = os.path.abspath(os.path.join(INFRA_BOTS_DIR, os.pardir, os.pardir))
def main():
"""Load the DEPS file and verify that all entries are valid."""
# Find gclient.py and run that instead of simply "gclient", which calls into
# update_depot_tools.
gclient = subprocess.check_output([utils.WHICH, utils.GCLIENT])
gclient_py = os.path.join(os.path.dirname(gclient), 'gclient.py')
python = sys.executable or 'python'
# Obtain the DEPS mapping.
output = subprocess.check_output(
[python, gclient_py, 'revinfo'], cwd=SKIA_DIR)
# Check each entry.
errs = []
for e in output.rstrip().splitlines():
split = e.split(': ')
if len(split) != 2:
errs.append(
'Failed to parse `gclient revinfo` output; invalid format: %s' % e)
if split[0] == 'skia':
continue
split = split[1].split('@')
if len(split) != 2:
errs.append(
'Failed to parse `gclient revinfo` output; invalid format: %s' % e)
repo = split[0]
rev = split[1]
if not 'googlesource.com' in repo:
errs.append(
'DEPS must be hosted on googlesource.com; %s is not allowed.' % repo)
if not re.match(r'^[a-z0-9]{40}$', rev):
errs.append('%s: "%s" does not look like a commit hash.' % (repo, rev))
if errs:
print >> sys.stderr, 'Found problems in DEPS:'
for err in errs:
print >> sys.stderr, err
sys.exit(1)
if __name__ == '__main__':
main()