summaryrefslogtreecommitdiff
path: root/tools/requirements_style_check.sh
blob: ccbff3bddc9d8cef3c8349032083e2833f520d59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
#
# Enforce the requirement that dependencies are listed in the input
# files in alphabetical order.

# FIXME(dhellmann): This doesn't deal with URL requirements very
# well. We should probably sort those on the egg-name, rather than the
# full line.

function check_file() {
    typeset f=$1

    # We don't care about comment lines.
    grep -v '^#' $f > ${f}.unsorted
    sort -i -f ${f}.unsorted > ${f}.sorted
    diff -c ${f}.unsorted ${f}.sorted
    rc=$?
    rm -f ${f}.sorted ${f}.unsorted
    return $rc
}

exit_code=0
for filename in $@
do
    check_file $filename
    if [ $? -ne 0 ]
    then
        echo "Please list requirements in $filename in alphabetical order" 1>&2
        exit_code=1
    fi
done
exit $exit_code