xref: /titanic_44/usr/src/tools/onbld/Checks/Keywords.py (revision cdf0c1d55d9b3b6beaf994835440dfb01aef5cf0)
1*cdf0c1d5Smjnelson#! /usr/bin/python
2*cdf0c1d5Smjnelson#
3*cdf0c1d5Smjnelson# CDDL HEADER START
4*cdf0c1d5Smjnelson#
5*cdf0c1d5Smjnelson# The contents of this file are subject to the terms of the
6*cdf0c1d5Smjnelson# Common Development and Distribution License (the "License").
7*cdf0c1d5Smjnelson# You may not use this file except in compliance with the License.
8*cdf0c1d5Smjnelson#
9*cdf0c1d5Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*cdf0c1d5Smjnelson# or http://www.opensolaris.org/os/licensing.
11*cdf0c1d5Smjnelson# See the License for the specific language governing permissions
12*cdf0c1d5Smjnelson# and limitations under the License.
13*cdf0c1d5Smjnelson#
14*cdf0c1d5Smjnelson# When distributing Covered Code, include this CDDL HEADER in each
15*cdf0c1d5Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*cdf0c1d5Smjnelson# If applicable, add the following below this CDDL HEADER, with the
17*cdf0c1d5Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying
18*cdf0c1d5Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner]
19*cdf0c1d5Smjnelson#
20*cdf0c1d5Smjnelson# CDDL HEADER END
21*cdf0c1d5Smjnelson#
22*cdf0c1d5Smjnelson
23*cdf0c1d5Smjnelson#
24*cdf0c1d5Smjnelson# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25*cdf0c1d5Smjnelson# Use is subject to license terms.
26*cdf0c1d5Smjnelson#
27*cdf0c1d5Smjnelson# ident	"%Z%%M%	%I%	%E% SMI"
28*cdf0c1d5Smjnelson#
29*cdf0c1d5Smjnelson
30*cdf0c1d5Smjnelson#
31*cdf0c1d5Smjnelson# Mercurial (lack of) keyword checks
32*cdf0c1d5Smjnelson#
33*cdf0c1d5Smjnelson
34*cdf0c1d5Smjnelsonimport re, sys
35*cdf0c1d5Smjnelson
36*cdf0c1d5Smjnelson# A general 'ident'-style decleration, to allow for leniency.
37*cdf0c1d5Smjnelsonident = re.compile(r'((\%Z\%(\%M\%)\s+\%I\%|\%W\%)\s+\%E\% SMI)')
38*cdf0c1d5Smjnelson
39*cdf0c1d5Smjnelson#
40*cdf0c1d5Smjnelson# Absolutely anything that appears to be an SCCS keyword.
41*cdf0c1d5Smjnelson# It's impossible to programatically differentiate between these
42*cdf0c1d5Smjnelson# and other, legitimate, uses of matching strings.
43*cdf0c1d5Smjnelson#
44*cdf0c1d5Smjnelsonanykword = re.compile(r'%[A-ILMP-UWYZ]%')
45*cdf0c1d5Smjnelson
46*cdf0c1d5Smjnelsondef keywords(fh, filename=None, lenient=False, verbose=False,
47*cdf0c1d5Smjnelson             output=sys.stderr):
48*cdf0c1d5Smjnelson    '''Search FH for SCCS keywords, which should not be present when
49*cdf0c1d5Smjnelson    Mercurial is in use.
50*cdf0c1d5Smjnelson
51*cdf0c1d5Smjnelson    If LENIENT, accept #ident-style declarations, for the purposes of
52*cdf0c1d5Smjnelson    migration'''
53*cdf0c1d5Smjnelson
54*cdf0c1d5Smjnelson    if not filename:
55*cdf0c1d5Smjnelson        filename = fh.name
56*cdf0c1d5Smjnelson
57*cdf0c1d5Smjnelson    ret = 0
58*cdf0c1d5Smjnelson    lineno = 0
59*cdf0c1d5Smjnelson
60*cdf0c1d5Smjnelson    for line in fh:
61*cdf0c1d5Smjnelson        line = line.rstrip('\r\n')
62*cdf0c1d5Smjnelson        lineno += 1
63*cdf0c1d5Smjnelson
64*cdf0c1d5Smjnelson        if lenient and ident.search(line):
65*cdf0c1d5Smjnelson            continue
66*cdf0c1d5Smjnelson
67*cdf0c1d5Smjnelson        match = anykword.findall(line)
68*cdf0c1d5Smjnelson        if match:
69*cdf0c1d5Smjnelson            ret = 1
70*cdf0c1d5Smjnelson            output.write('%s: %d: contains SCCS keywords "%s"\n' %
71*cdf0c1d5Smjnelson                         (filename, lineno, ', '.join(match)))
72*cdf0c1d5Smjnelson            if verbose:
73*cdf0c1d5Smjnelson                output.write("   %s\n" % line)
74*cdf0c1d5Smjnelson
75*cdf0c1d5Smjnelson    return ret
76