From 806fd657c2424a7328c21a4246da038a6dafed0e Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 5 Dec 2013 20:33:43 -0500 Subject: use file includes in rgbasm objects to generate dependencies --- pokemontools/scan_includes.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pokemontools/scan_includes.py (limited to 'pokemontools/scan_includes.py') diff --git a/pokemontools/scan_includes.py b/pokemontools/scan_includes.py new file mode 100644 index 0000000..138f011 --- /dev/null +++ b/pokemontools/scan_includes.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +""" +Recursively scan an asm file for rgbasm INCLUDEs and INCBINs. +Used to generate dependencies for each rgbasm object. +""" + +import os +import sys + +import configuration +conf = configuration.Config() + +def recursive_scan(filename, includes = []): + if (filename[-4:] == '.asm' or filename[-3] == '.tx') and os.path.exists(filename): + lines = open(filename).readlines() + for line in lines: + for directive in ('INCLUDE', 'INCBIN'): + if directive in line: + line = line[:line.find(';')] + if directive in line: + include = line.split('"')[1] + if include not in includes: + includes += [include] + includes = recursive_scan(include, includes) + break + return includes + +if __name__ == '__main__': + filenames = sys.argv[1:] + for filename in filenames: + dependencies = recursive_scan(os.path.join(conf.path, filename)) + sys.stdout.write(' '.join(dependencies)) + -- cgit v1.2.3 From f35bb2c5cc390ec0008cede2721104592dbcb29d Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Dec 2013 01:26:09 -0500 Subject: scan_includes: join names properly and actually use conf.path --- pokemontools/scan_includes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pokemontools/scan_includes.py') diff --git a/pokemontools/scan_includes.py b/pokemontools/scan_includes.py index 138f011..7f34e92 100644 --- a/pokemontools/scan_includes.py +++ b/pokemontools/scan_includes.py @@ -22,13 +22,15 @@ def recursive_scan(filename, includes = []): include = line.split('"')[1] if include not in includes: includes += [include] - includes = recursive_scan(include, includes) + includes = recursive_scan(os.path.join(conf.path, include), includes) break return includes if __name__ == '__main__': filenames = sys.argv[1:] + dependencies = [] for filename in filenames: - dependencies = recursive_scan(os.path.join(conf.path, filename)) - sys.stdout.write(' '.join(dependencies)) + dependencies += recursive_scan(os.path.join(conf.path, filename)) + dependencies = list(set(dependencies)) + sys.stdout.write(' '.join(dependencies)) -- cgit v1.2.3