blob: 55e0c778e62a22c844477dc95f4bc77369d3bb3e [file] [log] [blame]
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Documentation on can be found at:
import os.path
import sys
TOP_DIR = 'native_client'
MAIN_DEPS = os.path.join(TOP_DIR, 'DEPS')
# List of directories to not apply presubmit project checks, relative
# to the NaCl top directory
# The following contain test data (including automatically generated),
# and do not follow our conventions.
# The following directories contains automatically generated source,
# which may not follow our conventions.
def NaclTopDir():
cwd = os.getcwd()
pos = cwd.rfind(TOP_DIR)
if pos < 0:
print 'ERROR: expected to be called from with %s' % TOP_DIR
return cwd[:pos + len(TOP_DIR)]
def _CommonChecks(input_api, output_api):
"""Checks for both upload and commit."""
results = []
input_api, output_api, project_name='Native Client',
return results
def IsFileInDirectories(f, dirs):
""" Returns true if f is in list of directories"""
for d in dirs:
if d is os.path.commonprefix([f , d]):
return True
return False
def CheckChangeOnUpload(input_api, output_api):
"""Verifies all changes in all files.
input_api: the limited set of input modules allowed in presubmit.
output_api: the limited set of output modules allowed in presubmit.
report = []
report.extend(_CommonChecks(input_api, output_api))
# The commit queue assumes is standalone.
# TODO(bradnelson): Migrate code_hygiene to a common location so that
# it can be used by the commit queue.
old_sys_path = list(sys.path)
sys.path.append(os.path.join(NaclTopDir(), 'tools'))
sys.path.append(os.path.join(NaclTopDir(), 'build'))
import code_hygiene
import validate_chrome_revision
sys.path = old_sys_path
del old_sys_path
affected_files = input_api.AffectedFiles(include_deletes=False)
exclude_dirs = [ NaclTopDir() + '/' + x + '/'
for filename in affected_files:
filename = filename.AbsoluteLocalPath()
if not IsFileInDirectories(filename, exclude_dirs):
errors, warnings = code_hygiene.CheckFile(filename, False)
for e in errors:
report.append(output_api.PresubmitError(e, items=errors[e]))
for w in warnings:
report.append(output_api.PresubmitPromptWarning(w, items=warnings[w]))
if filename.endswith(MAIN_DEPS):
e = validate_chrome_revision.ValidateChromeRevision(filename)
if e is not None:
report.append(output_api.PresubmitError(filename, items=[e]))
except Exception, e:
msg = "Could not validate Chrome revision: %s" % repr(e)
report.append(output_api.PresubmitError(filename, items=[msg]))
return report
def CheckChangeOnCommit(input_api, output_api):
"""Verifies all changes in all files and verifies that the
tree is open and can accept a commit.
input_api: the limited set of input modules allowed in presubmit.
output_api: the limited set of output modules allowed in presubmit.
report = []
report.extend(CheckChangeOnUpload(input_api, output_api))
input_api, output_api,
return report
def GetPreferredTrySlaves(_, change):
# This is a heuristic to (conservatively) detect if the change only
# affects the pnacl toolchain and not the main builders, and run the
# appropriate trybots.
is_pnacl_toolchain_only = True
for f in change.AffectedFiles(include_dirs=True):
if not f.LocalPath().startswith('pnacl'):
is_pnacl_toolchain_only = False
if is_pnacl_toolchain_only:
return [
return [
# Clang bots
# pnacl scons bots
# pnacl spec2k bots