Incorporate changes from pre-release reviews.
[scons.git] / src / test_copyrights.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Verify that we have proper Copyright notices on all the right files
29 in our distributions.
30
31 Note that this is a packaging test, not a functional test, so the
32 name of this script doesn't end in *Tests.py.
33 """
34
35 import os
36 import os.path
37 import re
38 import string
39
40 import TestSCons
41
42 test = TestSCons.TestSCons()
43
44 try:
45     cwd = os.environ['SCONS_CWD']
46 except KeyError:
47     cwd = os.getcwd()
48
49 class Collect:
50     expression = re.compile('Copyright.*The SCons Foundation')
51     def __init__(self, remove_list):
52         self.copyright = []
53         self.no_copyright = []
54         self.remove_list = remove_list
55
56 def visit(collect, dirname, names):
57     for r in collect.remove_list:
58         try:
59             names.remove(r)
60         except ValueError:
61             pass
62     for name in map(lambda n, d=dirname: os.path.join(d, n), names):
63         if not os.path.isfile(name):
64             continue
65         if collect.expression.search(open(name, 'r').read()):
66             collect.copyright.append(name)
67         else:
68             collect.no_copyright.append(name)
69
70 remove_list = [
71         'build',
72         'debian',
73         'dist',
74         'Optik',
75         'dblite.py',
76         'Conftest.py',
77         'MANIFEST',
78         'os_spawnv_fix.diff',
79         'setup.cfg',
80         'SCons-win32-install-1.jpg',
81         'SCons-win32-install-2.jpg',
82         'SCons-win32-install-3.jpg',
83         'SCons-win32-install-4.jpg',
84 ]
85
86 src_remove_list = [
87         'bin',
88                 'cons.pl',
89                 'design',
90                 'python10',
91                 'reference',
92         'etc',
93         'gentoo',
94         'config',
95         'MANIFEST.in',
96 ]
97
98 # XXX Remove '*-stamp' when we get rid of those.
99 scons = Collect(remove_list + ['build-stamp', 'configure-stamp'])
100 # XXX Remove '.sconsign' when we start using SConsignFile() for SCons builds.
101 local = Collect(remove_list + ['.sconsign'])
102 src = Collect(remove_list + src_remove_list)
103
104 build_scons = os.path.join(cwd, 'build', 'scons')
105 build_local = os.path.join(cwd, 'build', 'scons-local')
106 build_src = os.path.join(cwd, 'build', 'scons-src')
107
108 no_result = []
109
110 if os.path.exists(build_scons):
111     os.path.walk(build_scons, visit, scons)
112 else:
113     no_result.append(build_scons)
114
115 if os.path.exists(build_local):
116     os.path.walk(build_local, visit, local)
117 else:
118     no_result.append(build_local)
119
120 if os.path.exists(build_src):
121     os.path.walk(build_src, visit, src)
122 else:
123     no_result.append(build_src)
124
125 no_copyright = scons.no_copyright + local.no_copyright + src.no_copyright
126
127 if no_copyright:
128     print "Found the following files with no copyrights:"
129     print "\t" + string.join(no_copyright, "\n\t")
130     test.fail_test(1)
131
132 if no_result:
133     print "Cannot check copyrights, the following have apparently not been built:"
134     print "\t" + string.join(no_result, "\n\t")
135     test.no_result(1)
136
137 # All done.
138 test.pass_test()