12 # along with this program; if not, write to the Free Software |
12 # along with this program; if not, write to the Free Software |
13 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
13 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
14 # |
14 # |
15 |
15 |
16 # |
16 # |
17 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
17 # Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
18 # Use is subject to license terms. |
18 # Use is subject to license terms. |
19 # |
19 # |
20 |
20 |
21 '''workspace extensions for mercurial |
21 '''workspace extensions for mercurial |
22 |
22 |
52 from mercurial import cmdutil, node, ignore |
52 from mercurial import cmdutil, node, ignore |
53 |
53 |
54 from onbld.Scm.WorkSpace import WorkSpace, ActiveEntry |
54 from onbld.Scm.WorkSpace import WorkSpace, ActiveEntry |
55 from onbld.Scm.Backup import CdmBackup |
55 from onbld.Scm.Backup import CdmBackup |
56 from onbld.Checks import Cddl, Comments, Copyright, CStyle, HdrChk |
56 from onbld.Checks import Cddl, Comments, Copyright, CStyle, HdrChk |
57 from onbld.Checks import JStyle, Keywords, Rti, onSWAN |
57 from onbld.Checks import JStyle, Keywords, Mapfile, Rti, onSWAN |
58 |
58 |
59 |
59 |
60 def yes_no(ui, msg, default): |
60 def yes_no(ui, msg, default): |
61 if default: |
61 if default: |
62 prompt = ' [Y/n]:' |
62 prompt = ' [Y/n]:' |
123 |
123 |
124 def not_check(repo, cmd): |
124 def not_check(repo, cmd): |
125 '''return a function which returns boolean indicating whether a file |
125 '''return a function which returns boolean indicating whether a file |
126 should be skipped for CMD.''' |
126 should be skipped for CMD.''' |
127 |
127 |
128 notfile = repo.join('cdm/%s.NOT' % cmd) |
128 |
129 |
129 # |
130 if os.path.exists(notfile): |
130 # The ignore routines need a canonical path to the file (relative to the |
131 return ignore.ignore(repo.root, [notfile], repo.ui.warn) |
131 # repo root), whereas the check commands get paths relative to the cwd. |
|
132 # |
|
133 # Wrap our argument such that the path is canonified before it is checked. |
|
134 # |
|
135 def canonified_check(ignfunc): |
|
136 def f(path): |
|
137 cpath = util.canonpath(repo.root, repo.getcwd(), path) |
|
138 return ignfunc(cpath) |
|
139 return f |
|
140 |
|
141 ignorefiles = [] |
|
142 |
|
143 for f in [ repo.join('cdm/%s.NOT' % cmd), |
|
144 repo.wjoin('exception_lists/%s' % cmd) ]: |
|
145 if os.path.exists(f): |
|
146 ignorefiles.append(f) |
|
147 |
|
148 if ignorefiles: |
|
149 ign = ignore.ignore(repo.root, ignorefiles, repo.ui.warn) |
|
150 return canonified_check(ign) |
132 else: |
151 else: |
133 return util.never |
152 return util.never |
134 |
153 |
135 |
154 |
136 # |
155 # |
307 ret |= Cddl.cddlchk(fh, lenient=lenient, output=ui) |
326 ret |= Cddl.cddlchk(fh, lenient=lenient, output=ui) |
308 fh.close() |
327 fh.close() |
309 return ret |
328 return ret |
310 |
329 |
311 |
330 |
|
331 def cdm_mapfilechk(ui, repo, *args, **opts): |
|
332 '''check for a valid MAPFILE header block in active files |
|
333 |
|
334 Check that all link-editor mapfiles contain the standard mapfile |
|
335 header comment directing the reader to the document containing |
|
336 Solaris object versioning rules (README.mapfile).''' |
|
337 |
|
338 filelist = opts.get('filelist') or _buildfilelist(repo, args) |
|
339 |
|
340 ui.write('Mapfile comment check:\n') |
|
341 |
|
342 ret = 0 |
|
343 exclude = not_check(repo, 'mapfilechk') |
|
344 |
|
345 for f, e in filelist.iteritems(): |
|
346 if e and e.is_removed(): |
|
347 continue |
|
348 elif f.find('mapfile') == -1: |
|
349 continue |
|
350 elif (e or opts.get('honour_nots')) and exclude(f): |
|
351 ui.status('Skipping %s...\n' % f) |
|
352 continue |
|
353 |
|
354 fh = open(f, 'r') |
|
355 ret |= Mapfile.mapfilechk(fh, output=ui) |
|
356 fh.close() |
|
357 return ret |
|
358 |
|
359 |
312 def cdm_copyright(ui, repo, *args, **opts): |
360 def cdm_copyright(ui, repo, *args, **opts): |
313 '''check active files for valid copyrights |
361 '''check active files for valid copyrights |
314 |
362 |
315 Check that all active files have a valid copyright containing the |
363 Check that all active files have a valid copyright containing the |
316 current year (and *only* the current year). |
364 current year (and *only* the current year). |
642 |
690 |
643 |
691 |
644 def cdm_nits(ui, repo, *args, **opts): |
692 def cdm_nits(ui, repo, *args, **opts): |
645 '''check for stylistic nits in active files |
693 '''check for stylistic nits in active files |
646 |
694 |
647 Run cddlchk, copyright, cstyle, hdrchk, jstyle, permchk, and |
695 Run cddlchk, copyright, cstyle, hdrchk, jstyle, mapfilechk, |
648 keywords checks.''' |
696 permchk, and keywords checks.''' |
649 |
697 |
650 cmds = [cdm_cddlchk, |
698 cmds = [cdm_cddlchk, |
651 cdm_copyright, |
699 cdm_copyright, |
652 cdm_cstyle, |
700 cdm_cstyle, |
653 cdm_hdrchk, |
701 cdm_hdrchk, |
654 cdm_jstyle, |
702 cdm_jstyle, |
|
703 cdm_mapfilechk, |
655 cdm_permchk, |
704 cdm_permchk, |
656 cdm_keywords] |
705 cdm_keywords] |
657 |
706 |
658 return run_checks(wslist[repo], cmds, *args, **opts) |
707 return run_checks(wslist[repo], cmds, *args, **opts) |
659 |
708 |
660 |
709 |
661 def cdm_pbchk(ui, repo, *args, **opts): |
710 def cdm_pbchk(ui, repo, *args, **opts): |
662 '''pre-putback check all active files |
711 '''pre-putback check all active files |
663 |
712 |
664 Run cddlchk, comchk, copyright, cstyle, hdrchk, jstyle, permchk, tagchk, |
713 Run cddlchk, comchk, copyright, cstyle, hdrchk, jstyle, mapfilechk, |
665 branchchk, keywords and rtichk checks. Additionally, warn about |
714 permchk, tagchk, branchchk, keywords and rtichk checks. Additionally, |
666 uncommitted changes.''' |
715 warn about uncommitted changes.''' |
667 |
716 |
668 # |
717 # |
669 # The current ordering of these is that the commands from cdm_nits |
718 # The current ordering of these is that the commands from cdm_nits |
670 # run first in the same order as they would in cdm_nits. Then the |
719 # run first in the same order as they would in cdm_nits. Then the |
671 # pbchk specifics run |
720 # pbchk specifics run |
985 '^list|active': (cdm_list, [('p', 'parent', '', 'parent workspace'), |
1035 '^list|active': (cdm_list, [('p', 'parent', '', 'parent workspace'), |
986 ('r', 'removed', None, 'show removed files'), |
1036 ('r', 'removed', None, 'show removed files'), |
987 ('a', 'added', None, 'show added files'), |
1037 ('a', 'added', None, 'show added files'), |
988 ('m', 'modified', None, 'show modified files')], |
1038 ('m', 'modified', None, 'show modified files')], |
989 'hg list [-amrRu] [-p PARENT]'), |
1039 'hg list [-amrRu] [-p PARENT]'), |
|
1040 'mapfilechk': (cdm_mapfilechk, [('p', 'parent', '', 'parent workspace')], |
|
1041 'hg mapfilechk [-p PARENT]'), |
990 '^nits': (cdm_nits, [('p', 'parent', '', 'parent workspace')], |
1042 '^nits': (cdm_nits, [('p', 'parent', '', 'parent workspace')], |
991 'hg nits [-p PARENT]'), |
1043 'hg nits [-p PARENT]'), |
992 '^pbchk': (cdm_pbchk, [('p', 'parent', '', 'parent workspace'), |
1044 '^pbchk': (cdm_pbchk, [('p', 'parent', '', 'parent workspace'), |
993 ('N', 'nocheck', None, 'skip RTI check')], |
1045 ('N', 'nocheck', None, 'skip RTI check')], |
994 'hg pbchk [-N] [-p PARENT]'), |
1046 'hg pbchk [-N] [-p PARENT]'), |