• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright 2020-2022 The Khronos Group Inc.
4#
5# SPDX-License-Identifier: Apache-2.0
6
7# compareImages - compare all asciidoctor images in two branches
8# Usage: compareImages branch1 branch2
9
10# Where to put temporary files
11compare=compare
12
13branch1=$1
14branch2=$2
15
16echo "Preparing test tree under compare/"
17rm -rf $compare
18
19echo "Gathering images under compare/$1 compare/$2"
20if git checkout $branch1 ; then
21    img1=$compare/$branch1
22    files1=$compare/$branch1-files
23    mkdir -p $img1
24    cp images/*.svg $img1
25    (cd $img1 ; ls) > $files1
26else
27    echo "Cannot switch to branch $branch1"
28    rm -rf $compare
29    exit 1
30fi
31
32if git checkout $branch2 ; then
33    img2=$compare/$branch2
34    files2=$compare/$branch2-files
35    mkdir -p $img2
36    cp images/*.svg $img2
37    (cd $img2 ; ls) > $files2
38else
39    echo "Cannot switch to branch $branch2"
40    rm -rf $compare
41    exit 1
42fi
43
44srcfile=compare/compImages.adoc
45
46# Boilerplate header
47echo "= Image Comparison of Vulkan images in $branch1 $branch2
48:data-uri:
49:icons: font
50include::../config/attribs.adoc[]
51" > $srcfile
52
53
54# Files common to both branches
55echo "== Images Common to Both Branches
56" >> $srcfile
57
58# Identical images
59identical=()
60
61# Where to generate comparison images
62compdir=$compare/compare
63mkdir -p $compdir
64
65for file in `comm -12 $files1 $files2` ; do
66    echo "Comparing $file"
67    if diff -q $img1/$file $img2/$file > /dev/null ; then
68        identical+=( $file )
69        # Files are identical
70    else
71        # sum1=`sum $img1/$file | awk '{print $1}'`
72        # sum2=`sum $img2/$file | awk '{print $1}'`
73        #
74        # if test $sum1 -eq $sum2 ; then
75
76        # Generate comparison image
77        compfile="$compdir/$file"
78        compare $img1/$file $img2/$file $compfile
79
80        echo "=== $file
81
82image::$branch1/$file[title=\"$file in $branch1\",align=\"center\",opts=\"inline\"]
83
84image::$branch2/$file[title=\"$file in $branch2\",align=\"center\",opts=\"inline\"]
85
86image::compare/$file[title=\"Comparison of branches\",align=\"center\",opts=\"inline\"]
87
88<<<
89
90" >> $srcfile
91
92    fi
93done
94
95
96# Identical files
97echo "== Identical images
98" >> $srcfile
99
100for file in ${identical[@]} ; do
101    echo "  * $file" >> $srcfile
102done
103echo >> $srcfile
104
105
106# Files only in first branch
107echo "== Images only in $branch1
108" >> $srcfile
109
110for file in `comm -23 $files1 $files2` ; do
111    echo "  * $file" >> $srcfile
112done
113echo >> $srcfile
114
115
116# Files only in second branch
117echo "== Images only in $branch2
118" >> $srcfile
119
120for file in `comm -13 $files1 $files2` ; do
121    echo "  * $file" >> $srcfile
122done
123echo >> $srcfile
124
125outfile=$compare/`basename $srcfile .adoc`.pdf
126echo "Generating $outfile from $srcfile"
127asciidoctor -b pdf -r asciidoctor-pdf -o $outfile $srcfile
128