Example #1
0
def _generate_lint_ninjas():
  n = ninja_generator.NinjaGenerator('lint', target_groups=['lint'])
  lint_script = 'src/build/lint_source.py'
  analyze_diffs_script = 'src/build/analyze_diffs.py'
  ignore = 'src/build/lint_ignore.txt'
  implicit_base = [analyze_diffs_script, lint_script, ignore]
  n.rule('lint', command=('%s -i %s -o $out $in' % (lint_script, ignore)),
         description='lint $out')
  n.rule('lint_merge', command='%s --merge -o $out @$out.rsp' % lint_script,
         rspfile='$out.rsp',
         rspfile_content='$in_newline',
         description='lint --merge $out')

  files = lint_source.get_all_files_to_check()
  results = []
  for f in files:
    with ninja_generator.open_dependency(f, 'r',
                                         ignore_dependency=True) as source_file:
      tracking_path = analyze_diffs.compute_tracking_path(None, f, source_file)
      implicit = implicit_base[:]
      if tracking_path:
        implicit.append(tracking_path)
    out = os.path.join(build_common.OUT_DIR, 'lint', f + '.result')
    n.build(out, 'lint', f, implicit=implicit, use_staging=False)
    results.append(out)

  out = os.path.join(build_common.OUT_DIR, 'lint_results.txt')
  n.build(out, 'lint_merge', results, implicit=implicit_base, use_staging=False)
Example #2
0
def _generate_lint_ninjas():
    n = ninja_generator.NinjaGenerator('lint', target_groups=['lint'])
    lint_script = 'src/build/lint_source.py'
    analyze_diffs_script = 'src/build/analyze_diffs.py'
    ignore = 'src/build/lint_ignore.txt'
    implicit_base = [analyze_diffs_script, lint_script, ignore]
    n.rule('lint',
           command=('%s -i %s -o $out $in' % (lint_script, ignore)),
           description='lint $out')
    n.rule('lint_merge',
           command='%s --merge -o $out @$out.rsp' % lint_script,
           rspfile='$out.rsp',
           rspfile_content='$in_newline',
           description='lint --merge $out')

    files = lint_source.get_all_files_to_check()
    results = []
    for f in files:
        with ninja_generator.open_dependency(
                f, 'r', ignore_dependency=True) as source_file:
            tracking_path = analyze_diffs.compute_tracking_path(
                None, f, source_file)
            implicit = implicit_base[:]
            if tracking_path:
                implicit.append(tracking_path)
        out = os.path.join(build_common.OUT_DIR, 'lint', f + '.result')
        n.build(out, 'lint', f, implicit=implicit, use_staging=False)
        results.append(out)

    out = os.path.join(build_common.OUT_DIR, 'lint_results.txt')
    n.build(out,
            'lint_merge',
            results,
            implicit=implicit_base,
            use_staging=False)
Example #3
0
def main():
  for file_name in sys.argv[1:]:
    basename = os.path.basename(file_name)
    name, ext = os.path.splitext(file_name)

    long_slash_star = False
    if (basename == '__init__.py'):
      # __init__.py files do not need copyrights headers
      return 0
    if (basename == 'config.py' or
        file_name.startswith('canned/') or
        file_name.startswith('mods/android/external/chromium_org/') or
        file_name.startswith('mods/chromium-ppapi/') or
        file_name.startswith('src/')):
      pattern = _CHROMIUM_PATTERN
      canonical = _CHROMIUM_CANONICAL
    elif (file_name.startswith('mods/android/') or
          file_name.startswith('mods/graphics_translation/')):
      pattern = _ANDROID_PATTERN
      canonical = _ANDROID_CANONICAL
      long_slash_star = True
    elif (file_name.startswith('third_party/examples/') or
          file_name.startswith('mods/examples/')):
      # Ignore this directory since we will not be open sourcing it.
      return 0
    elif (file_name.startswith('third_party/android/bionic-aosp/') or
          file_name.startswith('third_party/freebsd/') or
          file_name.startswith('third_party/openbsd/')):
      # They are used for Bionic and only <20 reviewed files exist.
      # TODO(crbug.com/406226): Remove this whitelist once ARC is
      # rebased to L.
      return 0
    else:
      print 'Unknown license pattern for', file_name
      return 1

    with open(file_name, 'r') as f:
      lines = f.readlines()
      if analyze_diffs.compute_tracking_path(None, file_name, lines):
        # We assume copyrights in tracked files are correct.
        return 0
      headers = []
      for line in lines:
        if not headers and 'opyright' not in line:
          continue
        headers.append(line)
        if len(headers) == _MAXIMUM_COPYRIGHT_PATTERN_LINES:
          break
      header = ''.join(headers)
      if not headers:
        print '%s: does not have a copyright notice at all' % file_name
        print '\nSuggested:\n%s' % _expand_canonical(canonical, ext,
                                                     long_slash_star)
        return 1
      m = re.search(pattern, header)
      if not m:
        print '%s: has an incorrect copyright header:\n\n%s' % (
            file_name, header)
        print 'Suggested:\n%s' % _expand_canonical(canonical, ext,
                                                   long_slash_star)
        return 1
      if pattern == _CHROMIUM_PATTERN:
        # For Chromium copyright, make sure (c) is not used after 2014.
        has_pseudo_c_symbol = m.group(1)
        is_2014_or_newer = int(m.group(2)) >= 2014
        is_chromium_os = m.group(3).find('OS') != -1
        if has_pseudo_c_symbol and is_2014_or_newer and not is_chromium_os:
          print ('(c) should not be put in new copyright headers:\n\n%s' %
                 header)
          return 1
  return 0
Example #4
0
def main():
    for file_name in sys.argv[1:]:
        basename = os.path.basename(file_name)
        name, ext = os.path.splitext(file_name)

        long_slash_star = False
        if (basename == '__init__.py'):
            # __init__.py files do not need copyrights headers
            return 0
        if (basename == 'config.py' or file_name.startswith('canned/')
                or file_name.startswith('mods/android/external/chromium_org/')
                or file_name.startswith('mods/chromium-ppapi/')
                or file_name.startswith('src/')):
            pattern = _CHROMIUM_PATTERN
            canonical = _CHROMIUM_CANONICAL
        elif (file_name.startswith('mods/android/')
              or file_name.startswith('mods/graphics_translation/')):
            pattern = _ANDROID_PATTERN
            canonical = _ANDROID_CANONICAL
            long_slash_star = True
        elif (file_name.startswith('third_party/examples/')
              or file_name.startswith('mods/examples/')):
            # Ignore this directory since we will not be open sourcing it.
            return 0
        elif (file_name.startswith('third_party/android/bionic-aosp/')
              or file_name.startswith('third_party/freebsd/')
              or file_name.startswith('third_party/openbsd/')):
            # They are used for Bionic and only <20 reviewed files exist.
            # TODO(crbug.com/406226): Remove this whitelist once ARC is
            # rebased to L.
            return 0
        else:
            print 'Unknown license pattern for', file_name
            return 1

        with open(file_name, 'r') as f:
            lines = f.readlines()
            if analyze_diffs.compute_tracking_path(None, file_name, lines):
                # We assume copyrights in tracked files are correct.
                return 0
            headers = []
            for line in lines:
                if not headers and 'opyright' not in line:
                    continue
                headers.append(line)
                if len(headers) == _MAXIMUM_COPYRIGHT_PATTERN_LINES:
                    break
            header = ''.join(headers)
            if not headers:
                print '%s: does not have a copyright notice at all' % file_name
                print '\nSuggested:\n%s' % _expand_canonical(
                    canonical, ext, long_slash_star)
                return 1
            m = re.search(pattern, header)
            if not m:
                print '%s: has an incorrect copyright header:\n\n%s' % (
                    file_name, header)
                print 'Suggested:\n%s' % _expand_canonical(
                    canonical, ext, long_slash_star)
                return 1
            if pattern == _CHROMIUM_PATTERN:
                # For Chromium copyright, make sure (c) is not used after 2014.
                has_pseudo_c_symbol = m.group(1)
                is_2014_or_newer = int(m.group(2)) >= 2014
                is_chromium_os = m.group(3).find('OS') != -1
                if has_pseudo_c_symbol and is_2014_or_newer and not is_chromium_os:
                    print(
                        '(c) should not be put in new copyright headers:\n\n%s'
                        % header)
                    return 1
    return 0