Merge lp:~jpakkane/unity/includecheck into lp:unity/phablet

Proposed by Jussi Pakkanen
Status: Merged
Approved by: Michi Henning
Approved revision: no longer in the source branch.
Merged at revision: 579
Proposed branch: lp:~jpakkane/unity/includecheck
Merge into: lp:unity/phablet
Prerequisite: lp:~michihenning/unity/ResourcePtr-fix
Diff against target: 97 lines (+79/-0)
3 files modified
tests/CMakeLists.txt (+1/-0)
tests/cleanincludes/CMakeLists.txt (+2/-0)
tests/cleanincludes/includechecker.py (+76/-0)
To merge this branch: bzr merge lp:~jpakkane/unity/includecheck
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michi Henning (community) Approve
Review via email: mp+158005@code.launchpad.net

This proposal supersedes a proposal from 2013-04-09.

Commit message

Detect unwanted implementation detail leakage in public headers

Our API design guidelines say that public headers should not leak implementation details such as gobject. This script checks that they don't.

Description of the change

Our API design guidelines say that public headers should not leak implementation details such as gobject. This script checks that they don't.

This will cause a test error because one of the headers in the prerequisite branch exposes boost. Once that is fixed, this can be merged.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

Very cool, I like it! :-)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Michi? Could you mark this toplevel approved so it gets merged?

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/CMakeLists.txt'
2--- tests/CMakeLists.txt 2013-04-10 09:19:27 +0000
3+++ tests/CMakeLists.txt 2013-04-11 09:31:24 +0000
4@@ -72,3 +72,4 @@
5 add_subdirectory(unittests)
6 add_subdirectory(qmluitests)
7 add_subdirectory(whitespace)
8+add_subdirectory(cleanincludes)
9
10=== added directory 'tests/cleanincludes'
11=== added file 'tests/cleanincludes/CMakeLists.txt'
12--- tests/cleanincludes/CMakeLists.txt 1970-01-01 00:00:00 +0000
13+++ tests/cleanincludes/CMakeLists.txt 2013-04-11 09:31:24 +0000
14@@ -0,0 +1,2 @@
15+add_test(cleanincludes ${CMAKE_CURRENT_SOURCE_DIR}/includechecker.py
16+${CMAKE_SOURCE_DIR}/include)
17
18=== added file 'tests/cleanincludes/includechecker.py'
19--- tests/cleanincludes/includechecker.py 1970-01-01 00:00:00 +0000
20+++ tests/cleanincludes/includechecker.py 2013-04-11 09:31:24 +0000
21@@ -0,0 +1,76 @@
22+#!/usr/bin/python3 -tt
23+
24+# Copyright (C) 2013 Canonical Ltd
25+#
26+# This program is free software: you can redistribute it and/or modify
27+# it under the terms of the GNU General Public License version 3 as
28+# published by the Free Software Foundation.
29+#
30+# This program is distributed in the hope that it will be useful,
31+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+# GNU General Public License for more details.
34+#
35+# You should have received a copy of the GNU General Public License
36+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37+#
38+# Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
39+
40+"""A script that traverses all header files in a given
41+directory and scans them for forbidden includes."""
42+
43+import os, sys, stat
44+
45+forbidden = ['boost',
46+ 'gobject',
47+ 'gtk',
48+ 'Qt',
49+ 'dbus.h',
50+ ]
51+
52+def check_file(filename):
53+ errors_found = False
54+ linenum = 0
55+ for line in open(filename):
56+ line = line.strip()
57+ if line.startswith('#include'):
58+ for f in forbidden:
59+ if f in line:
60+ msg = 'Forbidden include: %s:%d - %s'\
61+ % (filename, linenum, line)
62+ print(msg)
63+ errors_found = True;
64+ linenum += 1
65+ return errors_found
66+
67+def check_headers(incdir):
68+ errors_found = False
69+ suffixes = {'h': True,
70+ 'hpp': True,
71+ 'hh': True,
72+ 'hxx': True,
73+ 'H': True,
74+ }
75+ for root, dirs, files in os.walk(incdir):
76+ if 'internal' in dirs:
77+ dirs.remove('internal')
78+ for filename in files:
79+ suffix = filename.split('.')[-1]
80+ if suffix in suffixes:
81+ fullname = os.path.join(root, filename)
82+ if check_file(fullname):
83+ errors_found = True
84+ return errors_found
85+
86+if __name__ == '__main__':
87+ if len(sys.argv) != 2:
88+ print(sys.argv[0], '<include directory>')
89+ sys.exit(1)
90+ incdir = sys.argv[1]
91+ if not stat.S_ISDIR(os.stat(incdir).st_mode):
92+ print("Argument", incdir, "is not a directory.")
93+ sys.exit(1)
94+ if check_headers(incdir):
95+ sys.exit(1)
96+
97+

Subscribers

People subscribed via source and target branches