3 # Copyright (C) 2010 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 # THE POSSIBILITY OF SUCH DAMAGE.
27 base_directory = ENV['TARGET_BUILD_DIR'] or throw "Unable to find TARGET_BUILD_DIR in the environment!"
28 is_shallow_bundle = (ENV['SHALLOW_BUNDLE'] || "NO").upcase == "YES"
31 throw "Unable to find TARGET_BUILD_DIR in the environment!"
34 Dir.chdir base_directory
36 $PERMITTED_INCLUDE_TYPES = { :public => [ :public ], :private => [ :public, :private ] }
38 $HEADER_NAMES_TO_TYPE = { }
39 $HEADERS_BY_TYPE = { :public => [], :private => [] }
41 $error_printed = false
45 STDERR.puts "ERROR: #{msg}"
48 def build_header_maps is_shallow_bundle
49 current_version_path = is_shallow_bundle ? "" : "Versions/A/"
50 all_headers = `find WebKit.framework/#{current_version_path}{,Private}Headers -type f -name '*.h'`.split
52 all_headers.each do |header|
53 if /\/Headers\/(.*)/.match(header)
54 $HEADER_NAMES_TO_TYPE[$1] = :public
55 $HEADERS_BY_TYPE[:public] << header
56 elsif /\/PrivateHeaders\/(.*)/.match(header)
57 $HEADER_NAMES_TO_TYPE[$1] = :private
58 $HEADERS_BY_TYPE[:private] << header
60 print_error "Unknown header type: #{header}"
65 def resolve_include(header, included_header, permitted_types)
66 # Ignore includes that aren't in the typical framework style.
67 return unless /<([^\/]+)\/(.*)>/.match(included_header)
69 framework, included_header_name = [$1, $2]
71 # Ignore includes that aren't related to other WebKit headers.
72 return unless framework =~ /^Web/
74 # A header of any type including a WebCore header is a recipe for disaster.
75 if framework == "WebCore"
76 # <rdar://problem/7718826> WebKeyGenerator.h should not include a WebCore header
77 return if header =~ /\/WebKeyGenerator.h$/ and included_header_name == "WebCoreKeyGenerator.h"
79 print_error "#{header} included #{included_header}!"
83 header_type = $HEADER_NAMES_TO_TYPE[included_header_name]
86 print_error "#{header} included #{included_header} but I could not find a header of that name!"
87 elsif not permitted_types.member?(header_type)
88 print_error "#{header} included #{included_header} which is #{header_type}!"
92 def verify_includes(header, permitted_types)
93 File.open(header) do |file|
94 file.each_line do |line|
95 if /#(include|import) (.*)/.match(line)
96 resolve_include(header, $2, permitted_types)
102 build_header_maps is_shallow_bundle
104 $HEADERS_BY_TYPE.each do |header_type, headers|
105 permitted_types = $PERMITTED_INCLUDE_TYPES[header_type]
106 headers.each do |header|
107 verify_includes header, permitted_types
111 exit 1 if $error_printed