summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2014-11-26 17:12:32 -0800
committerMatt Turner <mattst88@gmail.com>2014-11-26 17:17:35 -0800
commita38c5fc592e5ef766245c82a3e3774280ef3c598 (patch)
tree0dc224a093f23fda55bc6e43ba9ca40ff3d48a18
parent3a27301028849f27b751e9b16c1090cbd720262a (diff)
Add a script to check shader_test's dependencies.
-rwxr-xr-xcheck_dependencies.pl101
1 files changed, 101 insertions, 0 deletions
diff --git a/check_dependencies.pl b/check_dependencies.pl
new file mode 100755
index 0000000..bd6f562
--- /dev/null
+++ b/check_dependencies.pl
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+#
+# Copyright © 2014 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+# For checking that shader_test's dependencies are correct.
+#
+# Run with
+# ./check_dependencies.pl shaders/
+#
+# And then run a command like these to add dependencies to the [require]
+# section:
+#
+# find shaders/ -name '*.shader_test' -exec grep -l '#version 120' {} + | xargs sed -i -e 's/GLSL >= 1.10/GLSL >= 1.20/'
+# find shaders/ -name '*.shader_test' -exec grep -l '#extension GL_ARB_texture_rectangle : require' {} + | xargs sed -i -e 's/GLSL >= 1.20/GLSL >= 1.20\nGL_ARB_texture_rectangle/'
+
+use strict;
+use File::Find;
+
+die("Not enough arguments: specify a directory\n") if ($#ARGV < 0);
+
+# The array_diff function is copied from the Array::Utils package and contains
+# this copyright:
+#
+# This module is Copyright (c) 2007 Sergei A. Fedorov.
+# All rights reserved.
+#
+# You may distribute under the terms of either the GNU General Public
+# License or the Artistic License, as specified in the Perl README file.
+sub array_diff(\@\@) {
+ my %e = map { $_ => undef } @{$_[1]};
+ return @{[ ( grep { (exists $e{$_}) ? ( delete $e{$_} ) : ( 1 ) } @{ $_[0] } ), keys %e ] };
+}
+
+my @shader_test;
+
+sub wanted {
+ push(@shader_test, $File::Find::name) if (/\.shader_test$/);
+}
+
+finddepth(\&wanted, @ARGV);
+
+foreach my $shader_test (@shader_test) {
+ my $expected;
+ my $actual;
+ my @expected_ext;
+ my @actual_ext;
+
+ open(my $fh, "<", $shader_test)
+ or die("cannot open < $shader_test: $!\n");
+
+ while (<$fh>) {
+ chomp;
+
+ if (/^GLSL >= (\d)\.(\d\d)/) {
+ $expected = $1 * 100 + $2;
+ }
+ if (/^\s*#\s*version\s+(\d{3})/) {
+ $actual = $1 if $actual == undef;
+ $actual = $1 if $actual < $1;
+ }
+
+ if (/^(GL_\S+)/) {
+ next if ($1 eq "GL_ARB_fragment_program" ||
+ $1 eq "GL_ARB_vertex_program");
+ push(@expected_ext, $1);
+ }
+ if (/^\s*#\s*extension\s+(GL_\S+)\s*:\s*require/) {
+ push(@actual_ext, $1);
+ }
+ }
+
+ close($fh);
+
+ if ($actual != undef && $expected != $actual) {
+ print "$shader_test requested $expected, but requires $actual\n"
+ }
+
+ my @extension = array_diff(@expected_ext, @actual_ext);
+ foreach my $extension (@extension) {
+ print "$shader_test extension $extension mismatch\n";
+ }
+}