update-project-files.py 987 Bytes
Newer Older
1 2 3 4 5 6 7
#!/usr/bin/python -Es
# vim: et:sw=4:ts=4:sts=4
#
# Script regenerates project file list from the list of files tracked by Git.
#

SOURCES = [
8
    "src/*.c", "src/*.h", "src/*.rl", "src/*.l",
9
    "src/*.y", "tests/*.c", "tests/*.h",
10
    "tests-fuzz/*.c", "tests-fuzz/*.h",
Jan Včelák's avatar
Jan Včelák committed
11
    "libtap/*.c", "libtap/*.h",
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
]

OUTPUT_FILE = "Knot.files"

# ----------------------------------------------------------------------------

from subprocess import Popen, PIPE
import os
import sys

def run(command):
    p = Popen(command, stdout=PIPE, stderr=PIPE)
    (out, errout) = p.communicate()
    if p.returncode != 0:
        raise Exception("Command %s failed.", command)
    return out

print >>sys.stderr, "Updating %s." % OUTPUT_FILE

git_root = run(["git", "rev-parse", "--show-toplevel"]).strip()
os.chdir(git_root)

command = ["git", "ls-files"] + SOURCES
files = run(command).splitlines()

with open(OUTPUT_FILE, "w") as output:
    output.write("\n".join(sorted(files)))
    output.write("\n")