190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#!/usr/bin/env python
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)# Copyright (c) 2013 The Chromium Authors. All rights reserved.
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)# found in the LICENSE file.
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)import optparse
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)import os
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)import re
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)import sys
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)import build_version
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)from build_paths import SDK_SRC_DIR, SCRIPT_DIR, OUT_DIR
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)# Add SDK make tools scripts to the python path.
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)import getos
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)VALID_PLATFORMS = ['linux', 'mac', 'win']
207dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochPLATFORM_PREFIX_RE = re.compile(r'^\[([^\]]*)\](.*)$')
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class ParseException(Exception):
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  def __init__(self, filename, line, message):
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    Exception.__init__(self)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    self.filename = filename
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    self.line = line
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    self.message = message
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  def __str__(self):
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return '%s:%d: %s' % (self.filename, self.line, self.message)
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochdef SplitPattern(pattern):
347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  match = PLATFORM_PREFIX_RE.match(pattern)
357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if not match:
367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return pattern, []
377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  # platform-specific line
397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  platforms = match.group(1).split(',')
407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  # If this platform is included, strip the [...] part.
427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  pattern = match.group(2)
437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  return pattern, platforms
447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class VerifyException(Exception):
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  pass
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Rules(object):
50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  def __init__(self, filename, platform=None, contents=None):
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    self.glob_prefixes = []
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    self.exact_filenames = set()
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    self.filename = filename
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    self.platform = platform or getos.GetPlatform()
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    self.exe_ext = '.exe' if self.platform == 'win' else ''
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if self.platform not in VALID_PLATFORMS:
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      raise ParseException(self.filename, 1,
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                           'Unknown platform %s' % self.platform)
6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if not contents:
6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      with open(filename) as f:
6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        contents = f.read()
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for line_no, rule in enumerate(contents.split('\n')):
6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      rule = rule.strip()
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if rule:
6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        self.ParsePattern(line_no + 1, rule)
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  def ParsePattern(self, line_no, pattern):
717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    pattern, platforms = SplitPattern(pattern)
727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    if platforms:
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      unknown_platforms = set(platforms) - set(VALID_PLATFORMS)
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if unknown_platforms:
7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        msg = 'Unknown platform(s) %s.' % (
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            ', '.join('"%s"' % platform for platform in unknown_platforms))
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        raise ParseException(self.filename, line_no, msg)
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if self.platform not in platforms:
7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        return
8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    pattern = pattern.replace('${PLATFORM}', self.platform)
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    pattern = pattern.replace('${EXE_EXT}', self.exe_ext)
8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if '*' in pattern:
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      # glob pattern
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      # We only support * at the end.
8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if pattern.find('*') != len(pattern) - 1:
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        msg = '* is only allowed at the end of the line.'
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        raise ParseException(self.filename, line_no, msg)
9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      # Remove the *
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      pattern = pattern[:-1]
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      self.glob_prefixes.append(pattern)
943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      # Sort by longest prefix first; otherwise the rules:
953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      #
963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      # foo/*
973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      # foo/bar/*
983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      #
993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      # Won't work properly. A file "foo/bar/baz" will match the first rule,
1003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      # not the second.
1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      self.glob_prefixes.sort(cmp=lambda x, y: cmp(len(y), len(x)))
10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    else:
10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      self.exact_filenames.add(pattern)
10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  def VerifyDirectoryList(self, directory_list):
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    exact_filenames_used = set()
10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    glob_prefixes_used = set()
10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    expected_globs = set()
10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    expected_filenames = set()
11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    unexpected_filenames = set()
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for filename in directory_list:
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if os.path.sep != '/':
11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        filename = filename.replace(os.path.sep, '/')
11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if filename in self.exact_filenames:
11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        exact_filenames_used.add(filename)
11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        continue
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      # glob pattern
12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      found_prefix = False
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      for prefix in self.glob_prefixes:
12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        if filename.startswith(prefix):
12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          glob_prefixes_used.add(prefix)
12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          found_prefix = True
12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          break
12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if not found_prefix:
12890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        unexpected_filenames.add(filename)
12990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if len(exact_filenames_used) != len(self.exact_filenames):
13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      # We looped through the directory list, so if the lengths are unequal, it
13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      # must be that we expected something that isn't there.
13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      expected_filenames = self.exact_filenames - exact_filenames_used
13490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if len(glob_prefixes_used) != self.glob_prefixes:
13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      expected_globs = set(self.glob_prefixes) - glob_prefixes_used
13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if expected_filenames or unexpected_filenames or expected_globs:
13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      msg = ''
14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if unexpected_filenames:
14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        msg += '>>> Unexpected filenames: <<<\n%s\n' % (
14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            '\n'.join(sorted(unexpected_filenames)))
14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if expected_filenames:
14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        msg += '>>> Expected filenames: <<<\n%s\n' % (
14590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            '\n'.join(sorted(expected_filenames)))
14690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      if expected_globs:
14790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        msg += '>>> Expected 1+ files in these directories: <<< \n%s\n' % (
14890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)            '\n'.join(sorted(expected_globs)))
14990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      raise VerifyException(msg)
15090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)def GetDirectoryList(directory_path):
15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  result = []
15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  for root, _, files in os.walk(directory_path):
15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    rel_root = os.path.relpath(root, directory_path)
15690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if rel_root == '.':
15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      rel_root = ''
15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    for base_name in files:
15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      result.append(os.path.join(rel_root, base_name))
16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return result
16190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochdef Verify(rule_path, directory_path, platform=None):
164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  rules = Rules(rule_path, platform=platform)
16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  directory_list = GetDirectoryList(directory_path)
16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  rules.VerifyDirectoryList(directory_list)
16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
16890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochdef SortFile(rule_path):
1707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  with open(rule_path) as infile:
1717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    lines = infile.readlines()
1727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  def compare(line1, line2):
1747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    line1 = SplitPattern(line1)[0].lower()
1757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    line2 = SplitPattern(line2)[0].lower()
1767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return cmp(line1, line2)
1777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  lines.sort(compare)
1797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  with open(rule_path, 'w') as output:
1807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    for line in lines:
1817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      output.write(line)
1827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)def main(args):
18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  parser = optparse.OptionParser(usage='%prog <rule file> <directory>')
18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  parser.add_option('-p', '--platform',
18790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      help='Test with this platform, instead of the system\'s platform')
1887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  parser.add_option('-s', '--sort', action='store_true',
1897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      help='Sort the file list in place, rather than verifying the contents.')
19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  options, args = parser.parse_args(args)
1917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
192f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if not args:
193f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    args = [os.path.join(SCRIPT_DIR, 'sdk_files.list')]
194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  if options.sort:
1967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    if not args:
1977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      parser.error('Expected rule file.')
1987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    SortFile(args[0])
1997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return 0
2007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if len(args) < 2:
202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    version = build_version.ChromeMajorVersion()
203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    args.append(os.path.join(OUT_DIR, 'pepper_%s' % version))
20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
20590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  rule_path, directory_path = args
20690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if options.platform:
20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if options.platform not in VALID_PLATFORMS:
20890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      parser.error('Unknown platform: %s' % options.platform)
20990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    platform = options.platform
21090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  else:
21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    platform = getos.GetPlatform()
21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
21390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  try:
214eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return Verify(rule_path, directory_path, platform)
21590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  except ParseException, e:
21690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    print >> sys.stderr, 'Error parsing rules:\n', e
21790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return 1
21890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  except VerifyException, e:
21990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    print >> sys.stderr, 'Error verifying file list:\n', e
22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return 1
22190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return 0
22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
22390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)if __name__ == '__main__':
22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  sys.exit(main(sys.argv[1:]))
226