tizen beta release
[framework/web/webkit-efl.git] / Tools / Scripts / check-for-inappropriate-objc-class-names
1 #!/usr/bin/perl
2
3 # Copyright (C) 2006, 2007, 2008, 2010, 2011 Apple Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
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.
13
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.
25
26 # "check-for-inappropriate-objc-class-names" script for WebKit Open Source Project
27
28 # Intended to be invoked from an Xcode build step to check if a framework
29 # defines any Objective-C class whose name does not have one of the prefixes
30 # the framework is allowed to use.
31
32 use warnings;
33 use strict;
34
35 use File::Basename;
36
37 sub touch($);
38
39 my @allowedPrefixes = @ARGV;
40
41 die "No allowed prefixes passed on the command line" if !@allowedPrefixes;
42
43 my $arch = $ENV{'CURRENT_ARCH'};
44 my $target = $ENV{'TARGET_NAME'};
45 my $variant = $ENV{'CURRENT_VARIANT'};
46 my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'};
47
48 my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}";
49
50 my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . join('-', @allowedPrefixes) . ".timestamp";
51 my $buildTimestampAge = -M $buildTimestampPath;
52 my $executablePathAge = -M $executablePath;
53 my $scriptAge = -M $0;
54
55 my $pattern = "^(" . join('|', @allowedPrefixes) . ")";
56
57 my $sawError = 0;
58
59 if (!defined $executablePathAge || !defined $buildTimestampAge || $executablePathAge < $buildTimestampAge || $scriptAge < $buildTimestampAge) {
60     if (!open NM, "(nm -Ugjp '$executablePath' | sed 's/^/STDOUT:/') 2>&1 |") {
61         print "ERROR: Could not open $executablePath\n";
62         $sawError = 1;
63         next;
64     }
65     my @badNames;
66     while (<NM>) {
67         if (/^STDOUT:/) {
68             next unless /^STDOUT:_OBJC_CLASS_\$_/;
69             chomp;
70             my $className = substr($_, 21);
71             push(@badNames, $className) unless $className =~ /$pattern/;
72         } else {
73             print STDERR if $_ ne "nm: no name list\n";
74         }
75     }
76     close NM;
77
78     if (@badNames) {
79
80         my $shortName = $executablePath;
81         $shortName =~ s/.*\///;
82
83         print "ERROR: $shortName defines one or more Objective-C classes with inappropriate names. ($executablePath)\n";
84         for my $className (@badNames) {
85             print "ERROR: Inappropriate Objective-C class name: $className.\n";
86         }
87
88         if (@allowedPrefixes > 1) {
89             print "ERROR: Objective-C class names in $target must have one of these prefixes: " . join(", ", map('"' . $_ . '"', @allowedPrefixes)) . ".\n";
90         } else {
91             print "ERROR: Objective-C class names in $target must have the prefix \"" . $allowedPrefixes[0] . "\".\n";
92         }
93
94         $sawError = 1;
95     }
96 }
97
98 if ($sawError and !$coverageBuild) {
99     unlink $executablePath;
100     exit 1;
101 }
102
103 touch($buildTimestampPath);
104 exit 0;
105
106 sub touch($)
107 {
108     my ($path) = @_;
109     open(TOUCH, ">", $path) or die "$!";
110     close(TOUCH);
111 }